chore(orbit): auto-switch to the link's server on paste / join

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Psychotoxical
2026-04-24 18:43:18 +02:00
parent f2e4c5b684
commit 6370b5fa3c
4 changed files with 48 additions and 16 deletions
+17 -4
View File
@@ -9,6 +9,7 @@ import {
readOrbitState,
joinOrbitSession,
} from '../utils/orbit';
import { switchActiveServer } from '../utils/switchActiveServer';
import { showToast } from '../utils/toast';
interface Props {
@@ -44,13 +45,25 @@ export default function OrbitJoinModal({ onClose }: Props) {
const active = useAuthStore.getState().getActiveServer();
const activeUrl = (active?.url ?? '').replace(/\/+$/, '');
const wantUrl = parsed.serverBase.replace(/\/+$/, '');
if (activeUrl !== wantUrl) {
setError(t('orbit.toastSwitchServer', { url: wantUrl }));
return;
}
setBusy(true);
try {
// Auto-switch to the link's server if the user has an account for it.
// switch itself tears down any lingering orbit session.
if (activeUrl !== wantUrl) {
const targetServer = useAuthStore.getState().servers
.find(s => s.url.replace(/\/+$/, '') === wantUrl);
if (!targetServer) {
setError(t('orbit.toastNoAccountForServer', { url: wantUrl }));
return;
}
const switched = await switchActiveServer(targetServer);
if (!switched) {
setError(t('orbit.toastSwitchFailed', { url: wantUrl }));
return;
}
}
const playlistId = await findSessionPlaylistId(parsed.sid);
if (!playlistId) { setError(t('orbit.joinErrNotFound')); return; }
const state = await readOrbitState(playlistId);