Apply the auto-fixable lint rules and the formatter, and drop the Vite build artifacts.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Avatar, Box, MenuItem, Text, config } from 'folds';
|
||||
import { Icon, Icons } from '../icons';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { Icon, Icons } from '../icons';
|
||||
import { sessionsAtom, Session } from '../../state/sessions';
|
||||
import { setLocalStorageItem } from '../../state/utils/atomWithLocalStorage';
|
||||
import { getMxIdServer, mxcUrlToHttp } from '../../utils/matrix';
|
||||
@@ -26,7 +26,7 @@ function OtherSessionAvatar({ session }: { session: Session }) {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`${session.baseUrl}/_matrix/client/v3/profile/${encodeURIComponent(session.userId)}`,
|
||||
{ headers: { Authorization: `Bearer ${session.accessToken}` } }
|
||||
{ headers: { Authorization: `Bearer ${session.accessToken}` } },
|
||||
);
|
||||
if (!res.ok) return;
|
||||
const data = await res.json();
|
||||
@@ -34,7 +34,7 @@ function OtherSessionAvatar({ session }: { session: Session }) {
|
||||
const match = (data.avatar_url as string).match(/^mxc:\/\/([^/]+)\/(.+)$/);
|
||||
if (match) {
|
||||
setSrc(
|
||||
`${session.baseUrl}/_matrix/media/v3/thumbnail/${match[1]}/${match[2]}?width=32&height=32&method=crop`
|
||||
`${session.baseUrl}/_matrix/media/v3/thumbnail/${match[1]}/${match[2]}?width=32&height=32&method=crop`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -59,25 +59,25 @@ function OtherSessionAvatar({ session }: { session: Session }) {
|
||||
|
||||
const deleteAllMatrixDatabases = async (): Promise<void> => {
|
||||
console.log('[AccountSwitcher] Deleting all Matrix IndexedDB databases...');
|
||||
|
||||
|
||||
// List of known Matrix database names/patterns to delete
|
||||
const dbsToDelete = [
|
||||
'matrix-js-sdk::matrix-sdk-crypto', // Shared crypto store (causes conflicts)
|
||||
'matrix-js-sdk::matrix-sdk-crypto', // Shared crypto store (causes conflicts)
|
||||
];
|
||||
|
||||
|
||||
// Try to get all databases if the API is available
|
||||
try {
|
||||
if ('databases' in indexedDB) {
|
||||
const allDbs = await (indexedDB as any).databases();
|
||||
const matrixDbs = allDbs
|
||||
.map((db: any) => db.name)
|
||||
.filter((name: string) =>
|
||||
name && (
|
||||
name.startsWith('matrix-js-sdk') ||
|
||||
name.includes('@@') ||
|
||||
name.startsWith('sync@@') ||
|
||||
name.startsWith('crypto@@')
|
||||
)
|
||||
.filter(
|
||||
(name: string) =>
|
||||
name &&
|
||||
(name.startsWith('matrix-js-sdk') ||
|
||||
name.includes('@@') ||
|
||||
name.startsWith('sync@@') ||
|
||||
name.startsWith('crypto@@')),
|
||||
);
|
||||
dbsToDelete.push(...matrixDbs);
|
||||
console.log('[AccountSwitcher] Found Matrix databases:', matrixDbs);
|
||||
@@ -85,7 +85,7 @@ const deleteAllMatrixDatabases = async (): Promise<void> => {
|
||||
} catch (e) {
|
||||
console.warn('[AccountSwitcher] Could not enumerate databases:', e);
|
||||
}
|
||||
|
||||
|
||||
// Delete each database with timeout
|
||||
const deletePromises = dbsToDelete.map(async (dbName) => {
|
||||
try {
|
||||
@@ -104,7 +104,7 @@ const deleteAllMatrixDatabases = async (): Promise<void> => {
|
||||
resolve(); // Don't reject, reload will handle it
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
// Add 1-second timeout per database
|
||||
const timeoutPromise = new Promise<void>((resolve) => {
|
||||
setTimeout(() => {
|
||||
@@ -112,13 +112,13 @@ const deleteAllMatrixDatabases = async (): Promise<void> => {
|
||||
resolve();
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
|
||||
await Promise.race([deletePromise, timeoutPromise]);
|
||||
} catch (error) {
|
||||
console.warn(`[AccountSwitcher] Error deleting ${dbName}:`, error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
await Promise.all(deletePromises);
|
||||
console.log('[AccountSwitcher] ✅ Database cleanup complete');
|
||||
};
|
||||
@@ -129,14 +129,14 @@ export function AccountSwitcher({ currentUserId }: AccountSwitcherProps) {
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const currentProfile = useUserProfile(currentUserId ?? '');
|
||||
const currentAvatarUrl = currentProfile.avatarUrl
|
||||
? mxcUrlToHttp(mx, currentProfile.avatarUrl, useAuthentication, 32, 32, 'crop') ?? undefined
|
||||
? (mxcUrlToHttp(mx, currentProfile.avatarUrl, useAuthentication, 32, 32, 'crop') ?? undefined)
|
||||
: undefined;
|
||||
|
||||
|
||||
const handleSwitchAccount = async (session: Session) => {
|
||||
if (session.userId === currentUserId) return;
|
||||
|
||||
|
||||
console.log('[AccountSwitcher] Switching account from', currentUserId, 'to', session.userId);
|
||||
|
||||
|
||||
// Stop the current client before switching
|
||||
if (mx) {
|
||||
console.log('[AccountSwitcher] Stopping current Matrix client...');
|
||||
@@ -147,16 +147,16 @@ export function AccountSwitcher({ currentUserId }: AccountSwitcherProps) {
|
||||
console.error('[AccountSwitcher] Error stopping client:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set the new current session
|
||||
setLocalStorageItem('currentSessionUserId', session.userId);
|
||||
|
||||
|
||||
// Delete all Matrix databases to prevent conflicts
|
||||
await deleteAllMatrixDatabases();
|
||||
|
||||
|
||||
// Small delay to ensure cleanup is complete
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
// Reload the page to initialize the new session
|
||||
console.log('[AccountSwitcher] Reloading page...');
|
||||
window.location.reload();
|
||||
@@ -168,15 +168,18 @@ export function AccountSwitcher({ currentUserId }: AccountSwitcherProps) {
|
||||
}
|
||||
|
||||
// Filter out other sessions (not current)
|
||||
const otherSessions = sessions.filter(s => s.userId !== currentUserId);
|
||||
const otherSessions = sessions.filter((s) => s.userId !== currentUserId);
|
||||
const hasMultipleAccounts = sessions.length > 1;
|
||||
|
||||
return (
|
||||
<Box direction="Column" gap="200">
|
||||
<Text size="L400" style={{ paddingInline: config.space.S200, paddingBlock: config.space.S100 }}>
|
||||
<Text
|
||||
size="L400"
|
||||
style={{ paddingInline: config.space.S200, paddingBlock: config.space.S100 }}
|
||||
>
|
||||
{hasMultipleAccounts ? 'Switch Account' : 'Accounts'}
|
||||
</Text>
|
||||
|
||||
|
||||
{/* Show current account */}
|
||||
{currentUserId && (
|
||||
<MenuItem
|
||||
@@ -210,11 +213,11 @@ export function AccountSwitcher({ currentUserId }: AccountSwitcherProps) {
|
||||
</Box>
|
||||
</MenuItem>
|
||||
)}
|
||||
|
||||
|
||||
{/* Show other accounts if any */}
|
||||
{otherSessions.map((session) => {
|
||||
const server = getMxIdServer(session.userId);
|
||||
|
||||
|
||||
return (
|
||||
<MenuItem
|
||||
key={session.userId}
|
||||
|
||||
Reference in New Issue
Block a user