chore: test deploy snapshot
This commit is contained in:
@@ -337,7 +337,7 @@ function readStoredShareLastRoomByToken() {
|
||||
}
|
||||
|
||||
try {
|
||||
const raw = window.localStorage.getItem(SHARE_LAST_ROOM_STORAGE_KEY);
|
||||
const raw = window.sessionStorage.getItem(SHARE_LAST_ROOM_STORAGE_KEY);
|
||||
|
||||
if (!raw) {
|
||||
return {} as Record<string, string>;
|
||||
@@ -390,7 +390,48 @@ function writeStoredShareLastRoomSessionId(token: string, sessionId: string | nu
|
||||
delete nextMap[normalizedToken];
|
||||
}
|
||||
|
||||
window.localStorage.setItem(SHARE_LAST_ROOM_STORAGE_KEY, JSON.stringify(nextMap));
|
||||
window.sessionStorage.setItem(SHARE_LAST_ROOM_STORAGE_KEY, JSON.stringify(nextMap));
|
||||
}
|
||||
|
||||
function readShareRoomSessionIdFromLocation() {
|
||||
if (typeof window === 'undefined') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return new URLSearchParams(window.location.search).get('roomSessionId')?.trim() || '';
|
||||
}
|
||||
|
||||
function writeShareRoomSessionIdToLocation(roomSessionId: string | null, mode: 'push' | 'replace' = 'replace') {
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedSessionId = String(roomSessionId ?? '').trim();
|
||||
const nextUrl = new URL(window.location.href);
|
||||
const currentSessionId = nextUrl.searchParams.get('roomSessionId')?.trim() || '';
|
||||
|
||||
if (normalizedSessionId) {
|
||||
if (currentSessionId === normalizedSessionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
nextUrl.searchParams.set('roomSessionId', normalizedSessionId);
|
||||
} else {
|
||||
if (!currentSessionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
nextUrl.searchParams.delete('roomSessionId');
|
||||
}
|
||||
|
||||
const nextPath = `${nextUrl.pathname}${nextUrl.search}${nextUrl.hash}`;
|
||||
|
||||
if (mode === 'push') {
|
||||
window.history.pushState(window.history.state, '', nextPath);
|
||||
return;
|
||||
}
|
||||
|
||||
window.history.replaceState(window.history.state, '', nextPath);
|
||||
}
|
||||
|
||||
function getClientNotificationPermission(): ClientNotificationPermissionState {
|
||||
@@ -3557,7 +3598,7 @@ export function ChatSharePage() {
|
||||
return '';
|
||||
}
|
||||
|
||||
const urlRoomSessionId = new URLSearchParams(window.location.search).get('roomSessionId')?.trim() || '';
|
||||
const urlRoomSessionId = readShareRoomSessionIdFromLocation();
|
||||
|
||||
if (urlRoomSessionId) {
|
||||
return urlRoomSessionId;
|
||||
@@ -5278,13 +5319,31 @@ export function ChatSharePage() {
|
||||
return;
|
||||
}
|
||||
|
||||
const urlRoomSessionId = new URLSearchParams(window.location.search).get('roomSessionId')?.trim() || '';
|
||||
const urlRoomSessionId = readShareRoomSessionIdFromLocation();
|
||||
const restoredRoomSessionId = urlRoomSessionId || readStoredShareLastRoomSessionId(normalizedToken);
|
||||
|
||||
requestedRoomSessionIdRef.current = restoredRoomSessionId;
|
||||
setRequestedRoomSessionId(restoredRoomSessionId);
|
||||
}, [normalizedToken]);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === 'undefined') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const handlePopState = () => {
|
||||
const nextRoomSessionId = readShareRoomSessionIdFromLocation() || readStoredShareLastRoomSessionId(normalizedToken);
|
||||
requestedRoomSessionIdRef.current = nextRoomSessionId;
|
||||
setRequestedRoomSessionId(nextRoomSessionId);
|
||||
setIsShareRoomListVisible(false);
|
||||
};
|
||||
|
||||
window.addEventListener('popstate', handlePopState);
|
||||
return () => {
|
||||
window.removeEventListener('popstate', handlePopState);
|
||||
};
|
||||
}, [normalizedToken]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!normalizedToken || !hasSnapshotRef.current) {
|
||||
return;
|
||||
@@ -5329,22 +5388,10 @@ export function ChatSharePage() {
|
||||
writeStoredShareLastRoomSessionId(normalizedToken, persistedRoomSessionId);
|
||||
}, [normalizedToken, selectedShareRoomSessionId, shareRooms]);
|
||||
useEffect(() => {
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
const nextUrl = new URL(window.location.href);
|
||||
const roomSessionId = shareRooms.some((room) => room.sessionId === requestedRoomSessionId)
|
||||
? requestedRoomSessionId
|
||||
: activeShareRoomSessionId;
|
||||
|
||||
if (roomSessionId) {
|
||||
nextUrl.searchParams.set('roomSessionId', roomSessionId);
|
||||
} else {
|
||||
nextUrl.searchParams.delete('roomSessionId');
|
||||
}
|
||||
|
||||
window.history.replaceState(null, '', `${nextUrl.pathname}${nextUrl.search}${nextUrl.hash}`);
|
||||
writeShareRoomSessionIdToLocation(roomSessionId || null, 'replace');
|
||||
}, [activeShareRoomSessionId, requestedRoomSessionId, shareRooms]);
|
||||
|
||||
const handleUnlockShare = useCallback(async (inputPin?: string) => {
|
||||
@@ -5826,9 +5873,12 @@ export function ChatSharePage() {
|
||||
|
||||
roomSwitchSequenceRef.current += 1;
|
||||
setIsRoomSwitching(true);
|
||||
requestedRoomSessionIdRef.current = normalizedSessionId;
|
||||
writeStoredShareLastRoomSessionId(normalizedToken, normalizedSessionId);
|
||||
writeShareRoomSessionIdToLocation(normalizedSessionId, 'push');
|
||||
setRequestedRoomSessionId(normalizedSessionId);
|
||||
setIsShareRoomListVisible(false);
|
||||
}, [selectedShareRoomSessionId]);
|
||||
}, [normalizedToken, selectedShareRoomSessionId]);
|
||||
|
||||
const handleCreateShareRoom = useCallback(async () => {
|
||||
if (!normalizedToken || isCreatingRoom) {
|
||||
@@ -5871,6 +5921,9 @@ export function ChatSharePage() {
|
||||
? current
|
||||
: [...current, createdRoom]
|
||||
));
|
||||
requestedRoomSessionIdRef.current = createdRoom.sessionId;
|
||||
writeStoredShareLastRoomSessionId(normalizedToken, createdRoom.sessionId);
|
||||
writeShareRoomSessionIdToLocation(createdRoom.sessionId, 'push');
|
||||
setRequestedRoomSessionId(createdRoom.sessionId);
|
||||
setDraftText('');
|
||||
setComposerAttachments([]);
|
||||
|
||||
Reference in New Issue
Block a user