Skip to content

Commit

Permalink
🐛 fix: profile won't cached
Browse files Browse the repository at this point in the history
Signed-off-by: SimonShiki <[email protected]>
  • Loading branch information
SimonShiki committed Aug 11, 2024
1 parent 410dcb4 commit 143f64e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,23 @@ function App () {

useEffect(() => {
const disableContextMenu = (event: MouseEvent) => event.preventDefault();
const disableRefresh = (event: KeyboardEvent) => {
if (
event.key === 'F5' ||
(event.ctrlKey && event.key === 'r') ||
(event.metaKey && event.key === 'r')
) {
event.preventDefault();
}
};
if (import.meta.env.PROD) {
document.addEventListener('keydown', disableRefresh);
}
document.addEventListener('contextmenu', disableContextMenu);
return () => document.removeEventListener('contextmenu', disableContextMenu);
return () => {
document.removeEventListener('contextmenu', disableContextMenu);
document.removeEventListener('keydown', disableRefresh);
};
}, []);
return (
<div className='flex flex-row'>
Expand Down
4 changes: 3 additions & 1 deletion src/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function Settings () {
}
async function qrLogin () {
const keyRes = await fetch(`${ncmConfig.api}login/qr/key`);
const { data: keyData } = await keyRes.json();
const {data: keyData} = await keyRes.json();
const imgRes = await fetch(`${ncmConfig.api}login/qr/create?key=${keyData.unikey}&qrimg=1&t=${Date.now()}`);
const {data: imageData} = await imgRes.json();
setQrUrl(imageData.qrimg);
Expand All @@ -76,6 +76,8 @@ export default function Settings () {
switch (checkData.code) {
// expired
case 800: {
const keyRes = await fetch(`${ncmConfig.api}login/qr/key`);
const { data: keyData } = await keyRes.json();
const imgRes = await fetch(`${ncmConfig.api}login/qr/create?key=${keyData.unikey}&t=${Date.now()}`);
const { data: imageData } = await imgRes.json();
setQrUrl(imageData.qrimg);
Expand Down
3 changes: 2 additions & 1 deletion src/storages/ncm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,10 @@ export class NCM implements AbstractStorage {
private initListener () {
const loggedInJotai = focusAtom(this.ncmStorageConfigJotai, (optic) => optic.prop('loggedIn'));
sharedStore.sub(loggedInJotai, async () => {
const ncmConfig = sharedStore.get(this.ncmStorageConfigJotai) as NCMConfig;
const loggedIn = sharedStore.get(loggedInJotai);
if (loggedIn) {
const { userId } = await this.getProfile();
const ncmConfig = sharedStore.get(this.ncmStorageConfigJotai) as NCMConfig;
sharedStore.set(this.ncmStorageConfigJotai, {...ncmConfig, ...{uid: userId}});
}
});
Expand Down Expand Up @@ -335,6 +335,7 @@ export class NCM implements AbstractStorage {
}

private get config () {
console.log(sharedStore.get(this.ncmStorageConfigJotai));
return (sharedStore.get(this.ncmStorageConfigJotai) ?? defaultConfig) as NCMConfig;
}

Expand Down

0 comments on commit 143f64e

Please sign in to comment.