-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): adjust the display settings to be independent for each wo…
- Loading branch information
Showing
8 changed files
with
112 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/frontend/core/src/components/page-list/use-all-doc-display-properties.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useService, Workspace } from '@toeverything/infra'; | ||
import { useAtom } from 'jotai'; | ||
import { atomWithStorage } from 'jotai/utils'; | ||
import { useCallback } from 'react'; | ||
|
||
import type { | ||
DisplayProperties, | ||
PageDisplayProperties, | ||
PageGroupByType, | ||
} from './types'; | ||
|
||
export const displayPropertiesAtom = atomWithStorage<{ | ||
[workspaceId: string]: DisplayProperties; | ||
}>('allDocDisplayProperties', {}); | ||
|
||
const defaultProps: DisplayProperties = { | ||
groupBy: 'updatedDate', | ||
displayProperties: { | ||
bodyNotes: true, | ||
tags: true, | ||
createDate: true, | ||
updatedDate: true, | ||
}, | ||
}; | ||
|
||
export const useAllDocDisplayProperties = (): [ | ||
DisplayProperties, | ||
( | ||
key: keyof DisplayProperties, | ||
value: PageGroupByType | PageDisplayProperties | ||
) => void, | ||
] => { | ||
const workspace = useService(Workspace); | ||
const [properties, setProperties] = useAtom(displayPropertiesAtom); | ||
|
||
const workspaceProperties = properties[workspace.id] || defaultProps; | ||
|
||
const onChange = useCallback( | ||
( | ||
key: keyof DisplayProperties, | ||
value: PageGroupByType | PageDisplayProperties | ||
) => { | ||
setProperties(prev => ({ | ||
...prev, | ||
[workspace.id]: { | ||
...(prev[workspace.id] || defaultProps), | ||
[key]: value, | ||
}, | ||
})); | ||
}, | ||
[setProperties, workspace.id] | ||
); | ||
|
||
return [workspaceProperties, onChange]; | ||
}; |
29 changes: 0 additions & 29 deletions
29
packages/frontend/core/src/components/page-list/use-page-display-properties.ts
This file was deleted.
Oops, something went wrong.