Skip to content

Commit

Permalink
fix: 🐛 cookie sync bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lcandy2 committed May 10, 2024
1 parent d9efb5c commit 100a468
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ export function SyncLocalStorageWithCookie({
withRedirect = false,
}: SyncLocalStorageWithCookieProps) {
const [selectedSchool] = useAtom(selectedSchoolAtom);

const { host } = selectedSchool || {};
useEffect(() => {
if (selectedSchool) {
Cookies.set('selectedSchool', selectedSchool.host);
if (host) {
Cookies.set('selectedSchool', host);
if (withRedirect) {
redirect('/');
}
} else {
Cookies.remove('selectedSchool');
}
}, [selectedSchool, withRedirect]);
}, [host, withRedirect]);

return <></>;
}
2 changes: 2 additions & 0 deletions src/app/settings/_libs/ui/settings-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import SchoolCustomization from '@/app/settings/_libs/components/school-customiz
import SchoolAction from '@/app/settings/_libs/components/school-action';
import { SettingsConfig } from '@/app/_libs/types';
import JumpToFullscreen from '@/app/settings/_libs/components/jump-to-fullscreen';
import { SyncLocalStorageWithCookie } from '@/app/settings/_libs/components/sync-localstorage-with-cookie';

export default async function SettingsUI({
mode = 'settings',
type = 'page',
}: SettingsConfig) {
return (
<div className="flex flex-col gap-6 w-full">
<SyncLocalStorageWithCookie withRedirect={mode === 'init'} />
{type === 'modal' && <JumpToFullscreen />}
<SchoolSelector />
<SchoolCustomization mode={mode} type={type} />
Expand Down
2 changes: 0 additions & 2 deletions src/app/settings/setup/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Metadata } from 'next';
import Title from '@/app/_libs/components/title';
import SettingsUI from '../_libs/ui/settings-ui';
import { SyncLocalStorageWithCookie } from '@/app/settings/_libs/components/sync-localstorage-with-cookie';

export const metadata: Metadata = {
title: '选择学校',
Expand All @@ -10,7 +9,6 @@ export const metadata: Metadata = {
export default async function Page() {
return (
<div className="flex flex-col">
<SyncLocalStorageWithCookie withRedirect />
<Title
title={'选择学校'}
subtitle={'欢迎使用,你需要配置学校信息以继续。'}
Expand Down

0 comments on commit 100a468

Please sign in to comment.