mirror of
https://github.com/p-stream/p-stream.git
synced 2026-01-11 20:10:32 +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,
|
||||
}: BackendSelectorProps) {
|
||||
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[]>([]);
|
||||
|
||||
// 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
|
||||
useEffect(() => {
|
||||
const fetchMetas = async () => {
|
||||
|
|
@ -142,9 +159,7 @@ export function BackendSelector({
|
|||
};
|
||||
|
||||
const isCustomUrlSelected =
|
||||
customUrl &&
|
||||
selectedUrl === customUrl &&
|
||||
!availableUrls.includes(selectedUrl);
|
||||
selectedUrl !== null && !availableUrls.includes(selectedUrl);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
|
|
|
|||
|
|
@ -18,10 +18,6 @@ import { useAuthStore } from "@/stores/auth";
|
|||
export function LoginPage() {
|
||||
const navigate = useNavigate();
|
||||
const { t } = useTranslation();
|
||||
const [showBackendSelection, setShowBackendSelection] = useState(true);
|
||||
const [selectedBackendUrl, setSelectedBackendUrl] = useState<string | null>(
|
||||
null,
|
||||
);
|
||||
const setBackendUrl = useAuthStore((s) => s.setBackendUrl);
|
||||
const config = conf();
|
||||
const availableBackends =
|
||||
|
|
@ -37,6 +33,11 @@ export function LoginPage() {
|
|||
currentBackendUrl ??
|
||||
(availableBackends.length === 1 ? availableBackends[0] : null);
|
||||
|
||||
const [showBackendSelection, setShowBackendSelection] = useState(true);
|
||||
const [selectedBackendUrl, setSelectedBackendUrl] = useState<string | null>(
|
||||
currentBackendUrl ?? null,
|
||||
);
|
||||
|
||||
const handleBackendSelect = (url: string | null) => {
|
||||
setSelectedBackendUrl(url);
|
||||
if (url) {
|
||||
|
|
|
|||
|
|
@ -38,14 +38,8 @@ function CaptchaProvider(props: {
|
|||
export function RegisterPage() {
|
||||
const navigate = useNavigate();
|
||||
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 currentBackendUrl = useAuthStore((s) => s.backendUrl);
|
||||
const config = conf();
|
||||
const availableBackends =
|
||||
config.BACKEND_URLS.length > 0
|
||||
|
|
@ -54,6 +48,14 @@ export function RegisterPage() {
|
|||
? [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) => {
|
||||
setSelectedBackendUrl(url);
|
||||
if (url) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue