Remove unused javascript (#2470)
Some checks are pending
Deploy to Netlify (dev) / Deploy to Netlify (push) Waiting to run

This commit is contained in:
Ajay Bura 2025-08-29 15:04:52 +05:30 committed by GitHub
parent 399b1a373e
commit 90ca8ca2c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
214 changed files with 341 additions and 8768 deletions

View file

@ -1,9 +1,9 @@
import { atom } from 'jotai';
import {
atomWithLocalStorage,
getLocalStorageItem,
setLocalStorageItem,
} from './utils/atomWithLocalStorage';
// import { atom } from 'jotai';
// import {
// atomWithLocalStorage,
// getLocalStorageItem,
// setLocalStorageItem,
// } from './utils/atomWithLocalStorage';
export type Session = {
baseUrl: string;
@ -24,18 +24,29 @@ export type SessionStoreName = {
/**
* Migration code for old session
*/
const FALLBACK_STORE_NAME: SessionStoreName = {
sync: 'web-sync-store',
crypto: 'crypto-store',
} as const;
// const FALLBACK_STORE_NAME: SessionStoreName = {
// sync: 'web-sync-store',
// crypto: 'crypto-store',
// } as const;
const removeFallbackSession = () => {
export function setFallbackSession(
accessToken: string,
deviceId: string,
userId: string,
baseUrl: string
) {
localStorage.setItem('cinny_access_token', accessToken);
localStorage.setItem('cinny_device_id', deviceId);
localStorage.setItem('cinny_user_id', userId);
localStorage.setItem('cinny_hs_base_url', baseUrl);
}
export const removeFallbackSession = () => {
localStorage.removeItem('cinny_hs_base_url');
localStorage.removeItem('cinny_user_id');
localStorage.removeItem('cinny_device_id');
localStorage.removeItem('cinny_access_token');
};
const getFallbackSession = (): Session | undefined => {
export const getFallbackSession = (): Session | undefined => {
const baseUrl = localStorage.getItem('cinny_hs_base_url');
const userId = localStorage.getItem('cinny_user_id');
const deviceId = localStorage.getItem('cinny_device_id');
@ -59,71 +70,71 @@ const getFallbackSession = (): Session | undefined => {
* End of migration code for old session
*/
export const getSessionStoreName = (session: Session): SessionStoreName => {
if (session.fallbackSdkStores) {
return FALLBACK_STORE_NAME;
}
// export const getSessionStoreName = (session: Session): SessionStoreName => {
// if (session.fallbackSdkStores) {
// return FALLBACK_STORE_NAME;
// }
return {
sync: `sync${session.userId}`,
crypto: `crypto${session.userId}`,
};
};
// return {
// sync: `sync${session.userId}`,
// crypto: `crypto${session.userId}`,
// };
// };
export const MATRIX_SESSIONS_KEY = 'matrixSessions';
const baseSessionsAtom = atomWithLocalStorage<Sessions>(
MATRIX_SESSIONS_KEY,
(key) => {
const defaultSessions: Sessions = [];
const sessions = getLocalStorageItem(key, defaultSessions);
// export const MATRIX_SESSIONS_KEY = 'matrixSessions';
// const baseSessionsAtom = atomWithLocalStorage<Sessions>(
// MATRIX_SESSIONS_KEY,
// (key) => {
// const defaultSessions: Sessions = [];
// const sessions = getLocalStorageItem(key, defaultSessions);
// Before multi account support session was stored
// as multiple item in local storage.
// So we need these migration code.
const fallbackSession = getFallbackSession();
if (fallbackSession) {
removeFallbackSession();
sessions.push(fallbackSession);
setLocalStorageItem(key, sessions);
}
return sessions;
},
(key, value) => {
setLocalStorageItem(key, value);
}
);
// // Before multi account support session was stored
// // as multiple item in local storage.
// // So we need these migration code.
// const fallbackSession = getFallbackSession();
// if (fallbackSession) {
// removeFallbackSession();
// sessions.push(fallbackSession);
// setLocalStorageItem(key, sessions);
// }
// return sessions;
// },
// (key, value) => {
// setLocalStorageItem(key, value);
// }
// );
export type SessionsAction =
| {
type: 'PUT';
session: Session;
}
| {
type: 'DELETE';
session: Session;
};
// export type SessionsAction =
// | {
// type: 'PUT';
// session: Session;
// }
// | {
// type: 'DELETE';
// session: Session;
// };
export const sessionsAtom = atom<Sessions, [SessionsAction], undefined>(
(get) => get(baseSessionsAtom),
(get, set, action) => {
if (action.type === 'PUT') {
const sessions = [...get(baseSessionsAtom)];
const sessionIndex = sessions.findIndex(
(session) => session.userId === action.session.userId
);
if (sessionIndex === -1) {
sessions.push(action.session);
} else {
sessions.splice(sessionIndex, 1, action.session);
}
set(baseSessionsAtom, sessions);
return;
}
if (action.type === 'DELETE') {
const sessions = get(baseSessionsAtom).filter(
(session) => session.userId !== action.session.userId
);
set(baseSessionsAtom, sessions);
}
}
);
// export const sessionsAtom = atom<Sessions, [SessionsAction], undefined>(
// (get) => get(baseSessionsAtom),
// (get, set, action) => {
// if (action.type === 'PUT') {
// const sessions = [...get(baseSessionsAtom)];
// const sessionIndex = sessions.findIndex(
// (session) => session.userId === action.session.userId
// );
// if (sessionIndex === -1) {
// sessions.push(action.session);
// } else {
// sessions.splice(sessionIndex, 1, action.session);
// }
// set(baseSessionsAtom, sessions);
// return;
// }
// if (action.type === 'DELETE') {
// const sessions = get(baseSessionsAtom).filter(
// (session) => session.userId !== action.session.userId
// );
// set(baseSessionsAtom, sessions);
// }
// }
// );