mirror of
https://github.com/p-stream/p-stream.git
synced 2026-05-11 06:20:53 +00:00
persist entered custom backend url when navigating the site
This commit is contained in:
parent
0d4c6471ab
commit
681172fe8e
3 changed files with 33 additions and 15 deletions
|
|
@ -100,9 +100,26 @@ export function BackendSelector({
|
||||||
showCustom = true,
|
showCustom = true,
|
||||||
}: BackendSelectorProps) {
|
}: BackendSelectorProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [customUrl, setCustomUrl] = useState("");
|
// Helper to strip protocol from URL for display
|
||||||
|
const stripProtocol = (url: string | null): string => {
|
||||||
|
if (!url) return "";
|
||||||
|
return url.replace(/^https?:\/\//, "");
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initialize customUrl from selectedUrl if it's a custom URL (not in availableUrls)
|
||||||
|
const isCustomUrl = selectedUrl && !availableUrls.includes(selectedUrl);
|
||||||
|
const [customUrl, setCustomUrl] = useState(
|
||||||
|
isCustomUrl ? stripProtocol(selectedUrl) : "",
|
||||||
|
);
|
||||||
const [backendOptions, setBackendOptions] = useState<BackendOption[]>([]);
|
const [backendOptions, setBackendOptions] = useState<BackendOption[]>([]);
|
||||||
|
|
||||||
|
// Update customUrl when selectedUrl changes and it's a custom URL
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedUrl && !availableUrls.includes(selectedUrl)) {
|
||||||
|
setCustomUrl(stripProtocol(selectedUrl));
|
||||||
|
}
|
||||||
|
}, [selectedUrl, availableUrls]);
|
||||||
|
|
||||||
// Initialize and fetch meta for backend options
|
// Initialize and fetch meta for backend options
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchMetas = async () => {
|
const fetchMetas = async () => {
|
||||||
|
|
@ -142,9 +159,7 @@ export function BackendSelector({
|
||||||
};
|
};
|
||||||
|
|
||||||
const isCustomUrlSelected =
|
const isCustomUrlSelected =
|
||||||
customUrl &&
|
selectedUrl !== null && !availableUrls.includes(selectedUrl);
|
||||||
selectedUrl === customUrl &&
|
|
||||||
!availableUrls.includes(selectedUrl);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,6 @@ import { useAuthStore } from "@/stores/auth";
|
||||||
export function LoginPage() {
|
export function LoginPage() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [showBackendSelection, setShowBackendSelection] = useState(true);
|
|
||||||
const [selectedBackendUrl, setSelectedBackendUrl] = useState<string | null>(
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
const setBackendUrl = useAuthStore((s) => s.setBackendUrl);
|
const setBackendUrl = useAuthStore((s) => s.setBackendUrl);
|
||||||
const config = conf();
|
const config = conf();
|
||||||
const availableBackends =
|
const availableBackends =
|
||||||
|
|
@ -37,6 +33,11 @@ export function LoginPage() {
|
||||||
currentBackendUrl ??
|
currentBackendUrl ??
|
||||||
(availableBackends.length === 1 ? availableBackends[0] : null);
|
(availableBackends.length === 1 ? availableBackends[0] : null);
|
||||||
|
|
||||||
|
const [showBackendSelection, setShowBackendSelection] = useState(true);
|
||||||
|
const [selectedBackendUrl, setSelectedBackendUrl] = useState<string | null>(
|
||||||
|
currentBackendUrl ?? null,
|
||||||
|
);
|
||||||
|
|
||||||
const handleBackendSelect = (url: string | null) => {
|
const handleBackendSelect = (url: string | null) => {
|
||||||
setSelectedBackendUrl(url);
|
setSelectedBackendUrl(url);
|
||||||
if (url) {
|
if (url) {
|
||||||
|
|
|
||||||
|
|
@ -38,14 +38,8 @@ function CaptchaProvider(props: {
|
||||||
export function RegisterPage() {
|
export function RegisterPage() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [step, setStep] = useState(-1);
|
|
||||||
const [mnemonic, setMnemonic] = useState<null | string>(null);
|
|
||||||
const [account, setAccount] = useState<null | AccountProfile>(null);
|
|
||||||
const [siteKey, setSiteKey] = useState<string | null>(null);
|
|
||||||
const [selectedBackendUrl, setSelectedBackendUrl] = useState<string | null>(
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
const setBackendUrl = useAuthStore((s) => s.setBackendUrl);
|
const setBackendUrl = useAuthStore((s) => s.setBackendUrl);
|
||||||
|
const currentBackendUrl = useAuthStore((s) => s.backendUrl);
|
||||||
const config = conf();
|
const config = conf();
|
||||||
const availableBackends =
|
const availableBackends =
|
||||||
config.BACKEND_URLS.length > 0
|
config.BACKEND_URLS.length > 0
|
||||||
|
|
@ -54,6 +48,14 @@ export function RegisterPage() {
|
||||||
? [config.BACKEND_URL]
|
? [config.BACKEND_URL]
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
const [step, setStep] = useState(-1);
|
||||||
|
const [mnemonic, setMnemonic] = useState<null | string>(null);
|
||||||
|
const [account, setAccount] = useState<null | AccountProfile>(null);
|
||||||
|
const [siteKey, setSiteKey] = useState<string | null>(null);
|
||||||
|
const [selectedBackendUrl, setSelectedBackendUrl] = useState<string | null>(
|
||||||
|
currentBackendUrl ?? null,
|
||||||
|
);
|
||||||
|
|
||||||
const handleBackendSelect = (url: string | null) => {
|
const handleBackendSelect = (url: string | null) => {
|
||||||
setSelectedBackendUrl(url);
|
setSelectedBackendUrl(url);
|
||||||
if (url) {
|
if (url) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue