mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-10 13:38:49 +08:00
feat: new CMD-K (#4408)
This commit is contained in:
@@ -9,7 +9,7 @@ import { describe, expect, test } from 'vitest';
|
||||
import {
|
||||
pageSettingFamily,
|
||||
pageSettingsAtom,
|
||||
recentPageSettingsAtom,
|
||||
recentPageIdsBaseAtom,
|
||||
} from '../index';
|
||||
|
||||
describe('page mode atom', () => {
|
||||
@@ -26,20 +26,12 @@ describe('page mode atom', () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(store.get(recentPageSettingsAtom)).toEqual([
|
||||
{
|
||||
id: 'page0',
|
||||
mode: 'page',
|
||||
},
|
||||
]);
|
||||
expect(store.get(recentPageIdsBaseAtom)).toEqual(['page0']);
|
||||
|
||||
const page1SettingAtom = pageSettingFamily('page1');
|
||||
store.set(page1SettingAtom, {
|
||||
mode: 'edgeless',
|
||||
});
|
||||
expect(store.get(recentPageSettingsAtom)).toEqual([
|
||||
{ id: 'page1', mode: 'edgeless' },
|
||||
{ id: 'page0', mode: 'page' },
|
||||
]);
|
||||
expect(store.get(recentPageIdsBaseAtom)).toEqual(['page1', 'page0']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -43,10 +43,6 @@ type PageLocalSetting = {
|
||||
mode: PageMode;
|
||||
};
|
||||
|
||||
type PartialPageLocalSettingWithPageId = Partial<PageLocalSetting> & {
|
||||
id: string;
|
||||
};
|
||||
|
||||
const pageSettingsBaseAtom = atomWithStorage(
|
||||
'pageSettings',
|
||||
{} as Record<string, PageLocalSetting>
|
||||
@@ -55,22 +51,11 @@ const pageSettingsBaseAtom = atomWithStorage(
|
||||
// readonly atom by design
|
||||
export const pageSettingsAtom = atom(get => get(pageSettingsBaseAtom));
|
||||
|
||||
const recentPageSettingsBaseAtom = atomWithStorage<string[]>(
|
||||
export const recentPageIdsBaseAtom = atomWithStorage<string[]>(
|
||||
'recentPageSettings',
|
||||
[]
|
||||
);
|
||||
|
||||
export const recentPageSettingsAtom = atom<PartialPageLocalSettingWithPageId[]>(
|
||||
get => {
|
||||
const recentPageIDs = get(recentPageSettingsBaseAtom);
|
||||
const pageSettings = get(pageSettingsAtom);
|
||||
return recentPageIDs.map(id => ({
|
||||
...pageSettings[id],
|
||||
id,
|
||||
}));
|
||||
}
|
||||
);
|
||||
|
||||
const defaultPageSetting = {
|
||||
mode: 'page',
|
||||
} satisfies PageLocalSetting;
|
||||
@@ -85,7 +70,9 @@ export const pageSettingFamily: AtomFamily<
|
||||
...defaultPageSetting,
|
||||
},
|
||||
(get, set, patch) => {
|
||||
set(recentPageSettingsBaseAtom, ids => {
|
||||
// fixme: this does not work when page reload,
|
||||
// since atomWithStorage is async
|
||||
set(recentPageIdsBaseAtom, ids => {
|
||||
// pick 3 recent page ids
|
||||
return [...new Set([pageId, ...ids]).values()].slice(0, 3);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user