mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
style: enable rxjs/finnish (#6276)
chore(infra): use finnish notation for observables do rename
This commit is contained in:
@@ -14,7 +14,7 @@ export const DumpInfo = (_props: DumpInfoProps) => {
|
||||
const location = useLocation();
|
||||
const workspaceList = useService(WorkspaceListService);
|
||||
const currentWorkspace = useLiveData(
|
||||
useService(CurrentWorkspaceService).currentWorkspace
|
||||
useService(CurrentWorkspaceService).currentWorkspace$
|
||||
);
|
||||
const path = location.pathname;
|
||||
const query = useParams();
|
||||
|
||||
@@ -9,7 +9,7 @@ import { CurrentWorkspaceService } from '../../../modules/workspace/current-work
|
||||
const SyncAwarenessInnerLoggedIn = () => {
|
||||
const { user } = useSession();
|
||||
const currentWorkspace = useLiveData(
|
||||
useService(CurrentWorkspaceService).currentWorkspace
|
||||
useService(CurrentWorkspaceService).currentWorkspace$
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -479,7 +479,7 @@ const PageHistoryManager = ({
|
||||
);
|
||||
|
||||
const page = useService(Doc);
|
||||
const [mode, setMode] = useState<PageMode>(page.mode.value);
|
||||
const [mode, setMode] = useState<PageMode>(page.mode$.value);
|
||||
|
||||
const title = useDocCollectionPageTitle(docCollection, pageId);
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ const InlineTagsList = ({
|
||||
children,
|
||||
}: PropsWithChildren<InlineTagsListProps>) => {
|
||||
const tagService = useService(TagService);
|
||||
const tags = useLiveData(tagService.tags);
|
||||
const tagIds = useLiveData(tagService.tagIdsByPageId(pageId));
|
||||
const tags = useLiveData(tagService.tags$);
|
||||
const tagIds = useLiveData(tagService.tagIdsByPageId$(pageId));
|
||||
|
||||
return (
|
||||
<div className={styles.inlineTagsContainer} data-testid="inline-tags-list">
|
||||
@@ -83,9 +83,9 @@ export const EditTagMenu = ({
|
||||
const t = useAFFiNEI18N();
|
||||
const legacyProperties = useService(WorkspaceLegacyProperties);
|
||||
const tagService = useService(TagService);
|
||||
const tag = useLiveData(tagService.tagByTagId(tagId));
|
||||
const tagColor = useLiveData(tag?.color);
|
||||
const tagValue = useLiveData(tag?.value);
|
||||
const tag = useLiveData(tagService.tagByTagId$(tagId));
|
||||
const tagColor = useLiveData(tag?.color$);
|
||||
const tagValue = useLiveData(tag?.value$);
|
||||
const navigate = useNavigateHelper();
|
||||
|
||||
const menuProps = useMemo(() => {
|
||||
@@ -135,11 +135,11 @@ export const EditTagMenu = ({
|
||||
options.push('-');
|
||||
|
||||
options.push(
|
||||
tagColors.map(([name, color]) => {
|
||||
tagColors.map(([name, color], i) => {
|
||||
return {
|
||||
text: name,
|
||||
icon: (
|
||||
<div className={styles.tagColorIconWrapper}>
|
||||
<div key={i} className={styles.tagColorIconWrapper}>
|
||||
<div
|
||||
className={styles.tagColorIcon}
|
||||
style={{
|
||||
@@ -181,8 +181,8 @@ export const EditTagMenu = ({
|
||||
export const TagsEditor = ({ pageId, readonly }: TagsEditorProps) => {
|
||||
const t = useAFFiNEI18N();
|
||||
const tagService = useService(TagService);
|
||||
const tags = useLiveData(tagService.tags);
|
||||
const tagIds = useLiveData(tagService.tagIdsByPageId(pageId));
|
||||
const tags = useLiveData(tagService.tags$);
|
||||
const tagIds = useLiveData(tagService.tagIdsByPageId$(pageId));
|
||||
const [inputValue, setInputValue] = useState('');
|
||||
const [open, setOpen] = useState(false);
|
||||
const [selectedTagIds, setSelectedTagIds] = useState<string[]>([]);
|
||||
@@ -203,15 +203,11 @@ export const TagsEditor = ({ pageId, readonly }: TagsEditorProps) => {
|
||||
[setOpen, setSelectedTagIds]
|
||||
);
|
||||
|
||||
const exactMatch = useLiveData(tagService.tagByTagValue(inputValue));
|
||||
const exactMatch = useLiveData(tagService.tagByTagValue$(inputValue));
|
||||
|
||||
const filteredLiveData = useMemo(() => {
|
||||
if (inputValue) {
|
||||
return tagService.filterTagsByName(inputValue);
|
||||
}
|
||||
return tagService.tags;
|
||||
}, [inputValue, tagService]);
|
||||
const filteredTags = useLiveData(filteredLiveData);
|
||||
const filteredTags = useLiveData(
|
||||
inputValue ? tagService.filterTagsByName$(inputValue) : tagService.tags$
|
||||
);
|
||||
|
||||
const onInputChange = useCallback(
|
||||
(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
@@ -295,7 +291,7 @@ export const TagsEditor = ({ pageId, readonly }: TagsEditorProps) => {
|
||||
className={styles.tagSelectorItem}
|
||||
data-testid="tag-selector-item"
|
||||
data-tag-id={tag.id}
|
||||
data-tag-value={tag.value}
|
||||
data-tag-value={tag.value$}
|
||||
onClick={() => {
|
||||
onAddTag(tag.id);
|
||||
}}
|
||||
@@ -351,7 +347,7 @@ export const TagsInlineEditor = ({
|
||||
className,
|
||||
}: TagsInlineEditorProps) => {
|
||||
const tagService = useService(TagService);
|
||||
const tagIds = useLiveData(tagService.tagIdsByPageId(pageId));
|
||||
const tagIds = useLiveData(tagService.tagIdsByPageId$(pageId));
|
||||
const empty = !tagIds || tagIds.length === 0;
|
||||
return (
|
||||
<Menu
|
||||
|
||||
@@ -195,7 +195,7 @@ export const WorkspaceList = ({
|
||||
activeSubTab: WorkspaceSubTab;
|
||||
}) => {
|
||||
const workspaces = useLiveData(
|
||||
useService(WorkspaceManager).list.workspaceList
|
||||
useService(WorkspaceManager).list.workspaceList$
|
||||
);
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -34,7 +34,7 @@ export const DeleteLeaveWorkspace = ({
|
||||
const setSettingModal = useSetAtom(openSettingModalAtom);
|
||||
|
||||
const workspaceManager = useService(WorkspaceManager);
|
||||
const workspaceList = useLiveData(workspaceManager.list.workspaceList);
|
||||
const workspaceList = useLiveData(workspaceManager.list.workspaceList$);
|
||||
const currentWorkspace = useService(Workspace);
|
||||
const pushNotification = useSetAtom(pushNotificationAtom);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ export const ProfilePanel = ({ isOwner, workspace }: ProfilePanelProps) => {
|
||||
const t = useAFFiNEI18N();
|
||||
const pushNotification = useSetAtom(pushNotificationAtom);
|
||||
|
||||
const workspaceIsReady = useLiveData(workspace?.engine.rootDocState)?.ready;
|
||||
const workspaceIsReady = useLiveData(workspace?.engine.rootDocState$)?.ready;
|
||||
|
||||
const [avatarBlob, setAvatarBlob] = useState<string | null>(null);
|
||||
const [name, setName] = useState('');
|
||||
|
||||
@@ -26,7 +26,7 @@ export const ShareExport = ({
|
||||
urlType: 'workspace',
|
||||
});
|
||||
const exportHandler = useExportPage(currentPage);
|
||||
const currentMode = useLiveData(page.mode);
|
||||
const currentMode = useLiveData(page.mode$);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -66,7 +66,7 @@ export const AffineSharePage = (props: ShareMenuProps) => {
|
||||
disableShare,
|
||||
} = useIsSharedPage(workspaceId, currentPage.id);
|
||||
|
||||
const currentPageMode = useLiveData(page.mode);
|
||||
const currentPageMode = useLiveData(page.mode$);
|
||||
|
||||
const defaultMode = useMemo(() => {
|
||||
if (isSharedPage) {
|
||||
|
||||
@@ -55,7 +55,7 @@ export const PageHeaderMenuButton = ({
|
||||
meta => meta.id === pageId
|
||||
);
|
||||
const page = useService(Doc);
|
||||
const currentMode = useLiveData(page.mode);
|
||||
const currentMode = useLiveData(page.mode$);
|
||||
|
||||
const { favorite, toggleFavorite } = useFavorite(pageId);
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ export const EditorModeSwitch = ({
|
||||
const trash = pageMeta?.trash ?? false;
|
||||
const page = useService(Doc);
|
||||
|
||||
const currentMode = useLiveData(page.mode);
|
||||
const currentMode = useLiveData(page.mode$);
|
||||
|
||||
useEffect(() => {
|
||||
if (trash || isPublic) {
|
||||
|
||||
@@ -19,7 +19,7 @@ export const usePageHelper = (docCollection: DocCollection) => {
|
||||
|
||||
const isPreferredEdgeless = useCallback(
|
||||
(pageId: string) =>
|
||||
pageRecordList.record(pageId).value?.mode.value === 'edgeless',
|
||||
pageRecordList.record$(pageId).value?.mode$.value === 'edgeless',
|
||||
[pageRecordList]
|
||||
);
|
||||
|
||||
@@ -27,7 +27,7 @@ export const usePageHelper = (docCollection: DocCollection) => {
|
||||
(mode?: 'page' | 'edgeless') => {
|
||||
const page = createDoc();
|
||||
initEmptyPage(page);
|
||||
pageRecordList.record(page.id).value?.setMode(mode || 'page');
|
||||
pageRecordList.record$(page.id).value?.setMode(mode || 'page');
|
||||
openPage(docCollection.id, page.id);
|
||||
return page;
|
||||
},
|
||||
|
||||
@@ -49,7 +49,7 @@ const PageDetailEditorMain = memo(function PageDetailEditorMain({
|
||||
isPublic,
|
||||
publishMode,
|
||||
}: PageDetailEditorProps & { page: BlockSuiteDoc }) {
|
||||
const currentMode = useLiveData(useService(Doc).mode);
|
||||
const currentMode = useLiveData(useService(Doc).mode$);
|
||||
const mode = useMemo(() => {
|
||||
const shareMode = publishMode || currentMode;
|
||||
|
||||
|
||||
@@ -94,8 +94,8 @@ export const TagPageListHeader = ({
|
||||
tag: Tag;
|
||||
workspaceId: string;
|
||||
}) => {
|
||||
const tagColor = useLiveData(tag.color);
|
||||
const tagTitle = useLiveData(tag.value);
|
||||
const tagColor = useLiveData(tag.color$);
|
||||
const tagTitle = useLiveData(tag.value$);
|
||||
|
||||
const t = useAFFiNEI18N();
|
||||
const { jumpToTags, jumpToCollection } = useNavigateHelper();
|
||||
@@ -183,13 +183,9 @@ export const SwitchTag = ({ onClick }: SwitchTagProps) => {
|
||||
const t = useAFFiNEI18N();
|
||||
const [inputValue, setInputValue] = useState('');
|
||||
const tagService = useService(TagService);
|
||||
const filteredLiveData = useMemo(() => {
|
||||
if (inputValue) {
|
||||
return tagService.filterTagsByName(inputValue);
|
||||
}
|
||||
return tagService.tags;
|
||||
}, [inputValue, tagService]);
|
||||
const filteredTags = useLiveData(filteredLiveData);
|
||||
const filteredTags = useLiveData(
|
||||
inputValue ? tagService.filterTagsByName$(inputValue) : tagService.tags$
|
||||
);
|
||||
|
||||
const onInputChange = useCallback(
|
||||
(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
@@ -238,8 +234,8 @@ export const SwitchTag = ({ onClick }: SwitchTagProps) => {
|
||||
};
|
||||
|
||||
const TagLink = ({ tag, onClick }: { tag: Tag; onClick: () => void }) => {
|
||||
const tagColor = useLiveData(tag.color);
|
||||
const tagTitle = useLiveData(tag.value);
|
||||
const tagColor = useLiveData(tag.color$);
|
||||
const tagTitle = useLiveData(tag.value$);
|
||||
return (
|
||||
<Link
|
||||
key={tag.id}
|
||||
|
||||
@@ -69,8 +69,7 @@ const PageSelectionCell = ({
|
||||
|
||||
export const PageTagsCell = ({ pageId }: Pick<PageListItemProps, 'pageId'>) => {
|
||||
const tagsService = useService(TagService);
|
||||
const tagsLiveData = tagsService.tagsByPageId(pageId);
|
||||
const tags = useLiveData(tagsLiveData);
|
||||
const tags = useLiveData(tagsService.tagsByPageId$(pageId));
|
||||
|
||||
return (
|
||||
<div data-testid="page-list-item-tags" className={styles.tagsCell}>
|
||||
|
||||
@@ -57,8 +57,8 @@ export const TagItem = ({
|
||||
style,
|
||||
maxWidth,
|
||||
}: TagItemProps) => {
|
||||
const value = useLiveData(tag?.value);
|
||||
const color = useLiveData(tag?.color);
|
||||
const value = useLiveData(tag?.value$);
|
||||
const color = useLiveData(tag?.color$);
|
||||
const handleRemove: MouseEventHandler = useCallback(
|
||||
e => {
|
||||
e.stopPropagation();
|
||||
@@ -112,13 +112,13 @@ const TagItemNormal = ({
|
||||
return maxItems ? tags.slice(0, maxItems) : tags;
|
||||
}, [maxItems, tags]);
|
||||
|
||||
const tagsOrderedLiveData = useMemo(() => {
|
||||
return LiveData.computed(get =>
|
||||
[...nTags].sort((a, b) => get(a.value).length - get(b.value).length)
|
||||
);
|
||||
}, [nTags]);
|
||||
|
||||
const tagsOrdered = useLiveData(tagsOrderedLiveData);
|
||||
const tagsOrdered = useLiveData(
|
||||
useMemo(() => {
|
||||
return LiveData.computed(get =>
|
||||
[...nTags].sort((a, b) => get(a.value$).length - get(b.value$).length)
|
||||
);
|
||||
}, [nTags])
|
||||
);
|
||||
|
||||
return useMemo(
|
||||
() =>
|
||||
|
||||
@@ -275,11 +275,11 @@ function tagIdToTagOption(
|
||||
|
||||
const PageTitle = ({ id }: { id: string }) => {
|
||||
const page = useLiveData(
|
||||
useService(PageRecordList).records.map(record => {
|
||||
useService(PageRecordList).records$.map(record => {
|
||||
return record.find(p => p.id === id);
|
||||
})
|
||||
);
|
||||
const title = useLiveData(page?.title);
|
||||
const title = useLiveData(page?.title$);
|
||||
const t = useAFFiNEI18N();
|
||||
return title || t['Untitled']();
|
||||
};
|
||||
|
||||
@@ -33,8 +33,8 @@ export const CreateOrEditTag = ({
|
||||
tagMeta?: TagMeta;
|
||||
}) => {
|
||||
const tagService = useService(TagService);
|
||||
const tagOptions = useLiveData(tagService.tagMetas);
|
||||
const tag = useLiveData(tagService.tagByTagId(tagMeta?.id));
|
||||
const tagOptions = useLiveData(tagService.tagMetas$);
|
||||
const tag = useLiveData(tagService.tagByTagId$(tagMeta?.id));
|
||||
const t = useAFFiNEI18N();
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
|
||||
|
||||
@@ -107,8 +107,8 @@ export const pageToCommand = (
|
||||
subTitle?: string,
|
||||
blockId?: string
|
||||
): CMDKCommand => {
|
||||
const pageMode = workspace.services.get(PageRecordList).record(page.id).value
|
||||
?.mode.value;
|
||||
const pageMode = workspace.services.get(PageRecordList).record$(page.id).value
|
||||
?.mode$.value;
|
||||
|
||||
const title = getPageTitle(page.id) || t['Untitled']();
|
||||
const commandLabel = {
|
||||
@@ -320,7 +320,7 @@ export const collectionToCommand = (
|
||||
export const useCollectionsCommands = () => {
|
||||
// todo: considering collections for searching pages
|
||||
const collectionService = useService(CollectionService);
|
||||
const collections = useLiveData(collectionService.collections);
|
||||
const collections = useLiveData(collectionService.collections$);
|
||||
const query = useAtomValue(cmdkQueryAtom);
|
||||
const navigationHelper = useNavigateHelper();
|
||||
const t = useAFFiNEI18N();
|
||||
@@ -356,7 +356,7 @@ export const useCMDKCommandGroups = () => {
|
||||
const collectionCommands = useCollectionsCommands();
|
||||
|
||||
const currentPage = useServiceOptional(Doc);
|
||||
const currentPageMode = useLiveData(currentPage?.mode);
|
||||
const currentPageMode = useLiveData(currentPage?.mode$);
|
||||
const affineCommands = useMemo(() => {
|
||||
return getAllCommand({
|
||||
pageMode: currentPageMode,
|
||||
|
||||
@@ -30,7 +30,7 @@ const showList = environment.isDesktop ? DESKTOP_SHOW_LIST : DEFAULT_SHOW_LIST;
|
||||
export const HelpIsland = () => {
|
||||
const page = useServiceOptional(Doc);
|
||||
const pageId = page?.id;
|
||||
const mode = useLiveData(page?.mode);
|
||||
const mode = useLiveData(page?.mode$);
|
||||
const setOpenSettingModalAtom = useSetAtom(openSettingModalAtom);
|
||||
const [spread, setShowSpread] = useState(false);
|
||||
const t = useAFFiNEI18N();
|
||||
|
||||
@@ -19,7 +19,7 @@ import * as styles from './styles.css';
|
||||
|
||||
export const TrashPageFooter = ({ pageId }: { pageId: string }) => {
|
||||
const workspace = useLiveData(
|
||||
useService(CurrentWorkspaceService).currentWorkspace
|
||||
useService(CurrentWorkspaceService).currentWorkspace$
|
||||
);
|
||||
assertExists(workspace);
|
||||
const docCollection = workspace.docCollection;
|
||||
|
||||
@@ -89,7 +89,7 @@ const CollectionRenderer = ({
|
||||
};
|
||||
return filterPage(collection, pageData);
|
||||
});
|
||||
const location = useLiveData(useService(Workbench).location);
|
||||
const location = useLiveData(useService(Workbench).location$);
|
||||
const currentPath = location.pathname;
|
||||
const path = `/collection/${collection.id}`;
|
||||
|
||||
@@ -174,7 +174,7 @@ export const CollectionsList = ({
|
||||
onCreate,
|
||||
}: CollectionsListProps) => {
|
||||
const metas = useBlockSuiteDocMeta(workspace);
|
||||
const collections = useLiveData(useService(CollectionService).collections);
|
||||
const collections = useLiveData(useService(CollectionService).collections$);
|
||||
const t = useAFFiNEI18N();
|
||||
if (collections.length === 0) {
|
||||
return (
|
||||
|
||||
@@ -36,8 +36,8 @@ export const Page = ({
|
||||
|
||||
const pageId = page.id;
|
||||
const active = params.pageId === pageId;
|
||||
const pageRecord = useLiveData(useService(PageRecordList).record(pageId));
|
||||
const pageMode = useLiveData(pageRecord?.mode);
|
||||
const pageRecord = useLiveData(useService(PageRecordList).record$(pageId));
|
||||
const pageMode = useLiveData(pageRecord?.mode$);
|
||||
const dragItemId = getDragItemId('collectionPage', pageId);
|
||||
|
||||
const icon = useMemo(() => {
|
||||
|
||||
@@ -27,8 +27,8 @@ export const ReferencePage = ({
|
||||
const params = useParams();
|
||||
const active = params.pageId === pageId;
|
||||
|
||||
const pageRecord = useLiveData(useService(PageRecordList).record(pageId));
|
||||
const pageMode = useLiveData(pageRecord?.mode);
|
||||
const pageRecord = useLiveData(useService(PageRecordList).record$(pageId));
|
||||
const pageMode = useLiveData(pageRecord?.mode$);
|
||||
const icon = useMemo(() => {
|
||||
return pageMode === 'edgeless' ? <EdgelessIcon /> : <PageIcon />;
|
||||
}, [pageMode]);
|
||||
|
||||
@@ -29,8 +29,8 @@ export const FavouritePage = ({
|
||||
const params = useParams();
|
||||
const active = params.pageId === pageId;
|
||||
const dragItemId = getDragItemId('favouritePage', pageId);
|
||||
const pageRecord = useLiveData(useService(PageRecordList).record(pageId));
|
||||
const pageMode = useLiveData(pageRecord?.mode);
|
||||
const pageRecord = useLiveData(useService(PageRecordList).record$(pageId));
|
||||
const pageMode = useLiveData(pageRecord?.mode$);
|
||||
|
||||
const icon = useMemo(() => {
|
||||
return pageMode === 'edgeless' ? <EdgelessIcon /> : <PageIcon />;
|
||||
|
||||
@@ -121,7 +121,7 @@ const UserWithWorkspaceListInner = ({
|
||||
}, [onEventEnd, setOpenCreateWorkspaceModal]);
|
||||
|
||||
const workspaceManager = useService(WorkspaceManager);
|
||||
const workspaces = useLiveData(workspaceManager.list.workspaceList);
|
||||
const workspaces = useLiveData(workspaceManager.list.workspaceList$);
|
||||
|
||||
// revalidate workspace list when mounted
|
||||
useEffect(() => {
|
||||
|
||||
@@ -105,7 +105,7 @@ export const AFFiNEWorkspaceList = ({
|
||||
onEventEnd?: () => void;
|
||||
}) => {
|
||||
const workspaces = useLiveData(
|
||||
useService(WorkspaceManager).list.workspaceList
|
||||
useService(WorkspaceManager).list.workspaceList$
|
||||
);
|
||||
|
||||
const setOpenCreateWorkspaceModal = useSetAtom(openCreateWorkspaceModalAtom);
|
||||
@@ -113,7 +113,7 @@ export const AFFiNEWorkspaceList = ({
|
||||
const { jumpToSubPath } = useNavigateHelper();
|
||||
|
||||
const currentWorkspace = useLiveData(
|
||||
useService(CurrentWorkspaceService).currentWorkspace
|
||||
useService(CurrentWorkspaceService).currentWorkspace$
|
||||
);
|
||||
|
||||
const setOpenSettingModalAtom = useSetAtom(openSettingModalAtom);
|
||||
|
||||
@@ -99,7 +99,7 @@ export const RootAppSidebar = ({
|
||||
const { appSettings } = useAppSettingHelper();
|
||||
const docCollection = currentWorkspace.docCollection;
|
||||
const t = useAFFiNEI18N();
|
||||
const currentPath = useLiveData(useService(Workbench).location).pathname;
|
||||
const currentPath = useLiveData(useService(Workbench).location$).pathname;
|
||||
|
||||
const onClickNewPage = useAsyncCallback(async () => {
|
||||
const page = createPage();
|
||||
|
||||
@@ -111,7 +111,7 @@ export function useBlockSuiteMetaHelper(docCollection: DocCollection) {
|
||||
|
||||
const duplicate = useAsyncCallback(
|
||||
async (pageId: string, openPageAfterDuplication: boolean = true) => {
|
||||
const currentPageMode = pageRecordList.record(pageId).value?.mode.value;
|
||||
const currentPageMode = pageRecordList.record$(pageId).value?.mode$.value;
|
||||
const currentPageMeta = getDocMeta(pageId);
|
||||
const newPage = createDoc();
|
||||
const currentPage = docCollection.getDoc(pageId);
|
||||
@@ -137,7 +137,7 @@ export function useBlockSuiteMetaHelper(docCollection: DocCollection) {
|
||||
currentPageMeta.title.replace(lastDigitRegex, '') + `(${newNumber})`;
|
||||
|
||||
pageRecordList
|
||||
.record(newPage.id)
|
||||
.record$(newPage.id)
|
||||
.value?.setMode(currentPageMode || 'page');
|
||||
setDocTitle(newPage.id, newPageTitle);
|
||||
openPageAfterDuplication && openPage(docCollection.id, newPage.id);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useMemo } from 'react';
|
||||
export function useDocEngineStatus() {
|
||||
const workspace = useService(Workspace);
|
||||
|
||||
const engineState = useLiveData(workspace.engine.docEngineState);
|
||||
const engineState = useLiveData(workspace.engine.docEngineState$);
|
||||
|
||||
const progress =
|
||||
(engineState.total - engineState.syncing) / engineState.total;
|
||||
|
||||
@@ -21,7 +21,7 @@ import { useTrashModalHelper } from './use-trash-modal-helper';
|
||||
export function useRegisterBlocksuiteEditorCommands() {
|
||||
const page = useService(Doc);
|
||||
const pageId = page.id;
|
||||
const mode = useLiveData(page.mode);
|
||||
const mode = useLiveData(page.mode$);
|
||||
const t = useAFFiNEI18N();
|
||||
const workspace = useService(Workspace);
|
||||
const docCollection = workspace.docCollection;
|
||||
|
||||
@@ -56,14 +56,14 @@ export const QuickSearch = () => {
|
||||
);
|
||||
|
||||
const workbench = useService(Workbench);
|
||||
const currentPath = useLiveData(workbench.location.map(l => l.pathname));
|
||||
const currentPath = useLiveData(workbench.location$.map(l => l.pathname));
|
||||
const pageRecordList = useService(PageRecordList);
|
||||
const currentPathId = matchPath('/:pageId', currentPath)?.params.pageId;
|
||||
// TODO: getting pageid from route is fragile, get current page from context
|
||||
const currentPage = useLiveData(
|
||||
currentPathId ? pageRecordList.record(currentPathId) : null
|
||||
currentPathId ? pageRecordList.record$(currentPathId) : null
|
||||
);
|
||||
const pageMeta = useLiveData(currentPage?.meta);
|
||||
const pageMeta = useLiveData(currentPage?.meta$);
|
||||
|
||||
return (
|
||||
<CMDKQuickSearchModal
|
||||
|
||||
@@ -32,7 +32,7 @@ export class CollectionService {
|
||||
return this.setting.get(COLLECTIONS_TRASH_KEY) as YArray<DeletedCollection>;
|
||||
}
|
||||
|
||||
readonly collections = LiveData.from(
|
||||
readonly collections$ = LiveData.from(
|
||||
new Observable<Collection[]>(subscriber => {
|
||||
subscriber.next(this.collectionsYArray?.toArray() ?? []);
|
||||
const fn = () => {
|
||||
@@ -46,7 +46,7 @@ export class CollectionService {
|
||||
[]
|
||||
);
|
||||
|
||||
readonly collectionsTrash = LiveData.from(
|
||||
readonly collectionsTrash$ = LiveData.from(
|
||||
new Observable<DeletedCollection[]>(subscriber => {
|
||||
subscriber.next(this.collectionsTrashYArray?.toArray() ?? []);
|
||||
const fn = () => {
|
||||
@@ -148,7 +148,7 @@ export class CollectionService {
|
||||
deletePagesFromCollections(ids: string[]) {
|
||||
const idSet = new Set(ids);
|
||||
this.doc.transact(() => {
|
||||
this.collections.value.forEach(collection => {
|
||||
this.collections$.value.forEach(collection => {
|
||||
this.deletePagesFromCollection(collection, idSet);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ export const GlobalScopeProvider: React.FC<
|
||||
});
|
||||
|
||||
const workspaceProvider = useLiveData(
|
||||
currentWorkspaceService.currentWorkspace
|
||||
currentWorkspaceService.currentWorkspace$
|
||||
)?.services;
|
||||
|
||||
return (
|
||||
|
||||
@@ -57,8 +57,8 @@ const PageItem = ({
|
||||
className,
|
||||
...attrs
|
||||
}: PageItemProps) => {
|
||||
const title = useLiveData(pageRecord.title);
|
||||
const mode = useLiveData(pageRecord.mode);
|
||||
const title = useLiveData(pageRecord.title$);
|
||||
const mode = useLiveData(pageRecord.mode$);
|
||||
const workspace = useService(Workspace);
|
||||
const { isJournal } = useJournalInfoHelper(
|
||||
workspace.docCollection,
|
||||
@@ -171,7 +171,7 @@ const sortPagesByDate = (
|
||||
return [...pages].sort((a, b) => {
|
||||
return (
|
||||
(order === 'asc' ? 1 : -1) *
|
||||
dayjs(b.meta.value[field]).diff(dayjs(a.meta.value[field]))
|
||||
dayjs(b.meta$.value[field]).diff(dayjs(a.meta$.value[field]))
|
||||
);
|
||||
});
|
||||
};
|
||||
@@ -193,7 +193,7 @@ const JournalDailyCountBlock = ({ date }: JournalBlockProps) => {
|
||||
const t = useAFFiNEI18N();
|
||||
const [activeItem, setActiveItem] = useState<NavItemName>('createdToday');
|
||||
const pageRecordList = useService(PageRecordList);
|
||||
const pageRecords = useLiveData(pageRecordList.records);
|
||||
const pageRecords = useLiveData(pageRecordList.records$);
|
||||
|
||||
const navigateHelper = useNavigateHelper();
|
||||
|
||||
@@ -201,10 +201,10 @@ const JournalDailyCountBlock = ({ date }: JournalBlockProps) => {
|
||||
(field: 'createDate' | 'updatedDate') => {
|
||||
return sortPagesByDate(
|
||||
pageRecords.filter(pageRecord => {
|
||||
if (pageRecord.meta.value.trash) return false;
|
||||
if (pageRecord.meta$.value.trash) return false;
|
||||
return (
|
||||
pageRecord.meta.value[field] &&
|
||||
dayjs(pageRecord.meta.value[field]).isSame(date, 'day')
|
||||
pageRecord.meta$.value[field] &&
|
||||
dayjs(pageRecord.meta$.value[field]).isSame(date, 'day')
|
||||
);
|
||||
}),
|
||||
field
|
||||
@@ -321,7 +321,7 @@ const ConflictList = ({
|
||||
setTrashModal({
|
||||
open: true,
|
||||
pageIds: [pageRecord.id],
|
||||
pageTitles: [pageRecord.meta.value.title],
|
||||
pageTitles: [pageRecord.meta$.value.title],
|
||||
});
|
||||
},
|
||||
[setTrashModal]
|
||||
@@ -363,7 +363,7 @@ const JournalConflictBlock = ({ date }: JournalBlockProps) => {
|
||||
const pageRecordList = useService(PageRecordList);
|
||||
const journalHelper = useJournalHelper(workspace.docCollection);
|
||||
const docs = journalHelper.getJournalsByDate(date.format('YYYY-MM-DD'));
|
||||
const pageRecords = useLiveData(pageRecordList.records).filter(v => {
|
||||
const pageRecords = useLiveData(pageRecordList.records$).filter(v => {
|
||||
return docs.some(doc => doc.id === v.id);
|
||||
});
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@ import type { Workbench } from '../../workbench';
|
||||
export class Navigator {
|
||||
constructor(private readonly workbench: Workbench) {}
|
||||
|
||||
private readonly history = this.workbench.activeView.map(
|
||||
private readonly history$ = this.workbench.activeView$.map(
|
||||
view => view.history
|
||||
);
|
||||
|
||||
private readonly location = LiveData.from(
|
||||
this.history.pipe(
|
||||
private readonly location$ = LiveData.from(
|
||||
this.history$.pipe(
|
||||
switchMap(
|
||||
history =>
|
||||
new Observable<{ index: number; entries: Location[] }>(subscriber => {
|
||||
@@ -29,11 +29,11 @@ export class Navigator {
|
||||
{ index: 0, entries: [] }
|
||||
);
|
||||
|
||||
readonly backable = this.location.map(
|
||||
readonly backable$ = this.location$.map(
|
||||
({ index, entries }) => index > 0 && entries.length > 1
|
||||
);
|
||||
|
||||
readonly forwardable = this.location.map(
|
||||
readonly forwardable$ = this.location$.map(
|
||||
({ index, entries }) => index < entries.length - 1
|
||||
);
|
||||
|
||||
@@ -41,7 +41,7 @@ export class Navigator {
|
||||
if (!environment.isDesktop) {
|
||||
window.history.back();
|
||||
} else {
|
||||
this.history.value.back();
|
||||
this.history$.value.back();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ export class Navigator {
|
||||
if (!environment.isDesktop) {
|
||||
window.history.forward();
|
||||
} else {
|
||||
this.history.value.forward();
|
||||
this.history$.value.forward();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ export const NavigationButtons = () => {
|
||||
|
||||
const navigator = useService(Navigator);
|
||||
|
||||
const backable = useLiveData(navigator.backable);
|
||||
const forwardable = useLiveData(navigator.forwardable);
|
||||
const backable = useLiveData(navigator.backable$);
|
||||
const forwardable = useLiveData(navigator.forwardable$);
|
||||
|
||||
const handleBack = useCallback(() => {
|
||||
navigator.back();
|
||||
|
||||
@@ -7,22 +7,22 @@ const RIGHT_SIDEBAR_KEY = 'app:settings:rightsidebar';
|
||||
|
||||
export class RightSidebar {
|
||||
constructor(private readonly globalState: GlobalState) {}
|
||||
readonly isOpen = LiveData.from(
|
||||
readonly isOpen$ = LiveData.from(
|
||||
this.globalState.watch<boolean>(RIGHT_SIDEBAR_KEY),
|
||||
false
|
||||
).map(Boolean);
|
||||
readonly views = new LiveData<RightSidebarView[]>([]);
|
||||
readonly front = this.views.map(
|
||||
readonly views$ = new LiveData<RightSidebarView[]>([]);
|
||||
readonly front$ = this.views$.map(
|
||||
stack => stack[0] as RightSidebarView | undefined
|
||||
);
|
||||
readonly hasViews = this.views.map(stack => stack.length > 0);
|
||||
readonly hasViews$ = this.views$.map(stack => stack.length > 0);
|
||||
|
||||
open() {
|
||||
this._set(true);
|
||||
}
|
||||
|
||||
toggle() {
|
||||
this._set(!this.isOpen.value);
|
||||
this._set(!this.isOpen$.value);
|
||||
}
|
||||
|
||||
close() {
|
||||
@@ -37,15 +37,15 @@ export class RightSidebar {
|
||||
* @private use `RightSidebarViewIsland` instead
|
||||
*/
|
||||
_append(view: RightSidebarView) {
|
||||
this.views.next([...this.views.value, view]);
|
||||
this.views$.next([...this.views$.value, view]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private use `RightSidebarViewIsland` instead
|
||||
*/
|
||||
_moveToFront(view: RightSidebarView) {
|
||||
if (this.views.value.includes(view)) {
|
||||
this.views.next([view, ...this.views.value.filter(v => v !== view)]);
|
||||
if (this.views$.value.includes(view)) {
|
||||
this.views$.next([view, ...this.views$.value.filter(v => v !== view)]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,6 @@ export class RightSidebar {
|
||||
* @private use `RightSidebarViewIsland` instead
|
||||
*/
|
||||
_remove(view: RightSidebarView) {
|
||||
this.views.next(this.views.value.filter(v => v !== view));
|
||||
this.views$.next(this.views$.value.filter(v => v !== view));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ export const RightSidebarContainer = () => {
|
||||
const [resizing, setResizing] = useState(false);
|
||||
const rightSidebar = useService(RightSidebar);
|
||||
|
||||
const frontView = useLiveData(rightSidebar.front);
|
||||
const open = useLiveData(rightSidebar.isOpen) && frontView !== undefined;
|
||||
const frontView = useLiveData(rightSidebar.front$);
|
||||
const open = useLiveData(rightSidebar.isOpen$) && frontView !== undefined;
|
||||
const [floating, setFloating] = useState(false);
|
||||
const appSidebarOpened = useAtomValue(appSidebarOpenAtom);
|
||||
|
||||
|
||||
@@ -10,24 +10,24 @@ export class Tag {
|
||||
private readonly pageRecordList: PageRecordList
|
||||
) {}
|
||||
|
||||
private readonly tagOption = this.properties.tagOptions$.map(
|
||||
private readonly tagOption$ = this.properties.tagOptions$.map(
|
||||
tags => tags.find(tag => tag.id === this.id) as TagSchema
|
||||
);
|
||||
|
||||
value = this.tagOption.map(tag => tag?.value || '');
|
||||
value$ = this.tagOption$.map(tag => tag?.value || '');
|
||||
|
||||
color = this.tagOption.map(tag => tag?.color || '');
|
||||
color$ = this.tagOption$.map(tag => tag?.color || '');
|
||||
|
||||
createDate = this.tagOption.map(tag => tag?.createDate || Date.now());
|
||||
createDate$ = this.tagOption$.map(tag => tag?.createDate || Date.now());
|
||||
|
||||
updateDate = this.tagOption.map(tag => tag?.updateDate || Date.now());
|
||||
updateDate$ = this.tagOption$.map(tag => tag?.updateDate || Date.now());
|
||||
|
||||
rename(value: string) {
|
||||
this.properties.updateTagOption(this.id, {
|
||||
id: this.id,
|
||||
value,
|
||||
color: this.color.value,
|
||||
createDate: this.createDate.value,
|
||||
color: this.color$.value,
|
||||
createDate: this.createDate$.value,
|
||||
updateDate: Date.now(),
|
||||
});
|
||||
}
|
||||
@@ -35,37 +35,37 @@ export class Tag {
|
||||
changeColor(color: string) {
|
||||
this.properties.updateTagOption(this.id, {
|
||||
id: this.id,
|
||||
value: this.value.value,
|
||||
value: this.value$.value,
|
||||
color,
|
||||
createDate: this.createDate.value,
|
||||
createDate: this.createDate$.value,
|
||||
updateDate: Date.now(),
|
||||
});
|
||||
}
|
||||
|
||||
tag(pageId: string) {
|
||||
const pageRecord = this.pageRecordList.record(pageId).value;
|
||||
const pageRecord = this.pageRecordList.record$(pageId).value;
|
||||
if (!pageRecord) {
|
||||
return;
|
||||
}
|
||||
pageRecord?.setMeta({
|
||||
tags: [...pageRecord.meta.value.tags, this.id],
|
||||
tags: [...pageRecord.meta$.value.tags, this.id],
|
||||
});
|
||||
}
|
||||
|
||||
untag(pageId: string) {
|
||||
const pageRecord = this.pageRecordList.record(pageId).value;
|
||||
const pageRecord = this.pageRecordList.record$(pageId).value;
|
||||
if (!pageRecord) {
|
||||
return;
|
||||
}
|
||||
pageRecord?.setMeta({
|
||||
tags: pageRecord.meta.value.tags.filter(tagId => tagId !== this.id),
|
||||
tags: pageRecord.meta$.value.tags.filter(tagId => tagId !== this.id),
|
||||
});
|
||||
}
|
||||
|
||||
readonly pageIds = LiveData.computed(get => {
|
||||
const pages = get(this.pageRecordList.records);
|
||||
readonly pageIds$ = LiveData.computed(get => {
|
||||
const pages = get(this.pageRecordList.records$);
|
||||
return pages
|
||||
.filter(page => get(page.meta).tags.includes(this.id))
|
||||
.filter(page => get(page.meta$).tags.includes(this.id))
|
||||
.map(page => page.id);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export class TagService {
|
||||
private readonly pageRecordList: PageRecordList
|
||||
) {}
|
||||
|
||||
readonly tags = this.properties.tagOptions$.map(tags =>
|
||||
readonly tags$ = this.properties.tagOptions$.map(tags =>
|
||||
tags.map(tag => new Tag(tag.id, this.properties, this.pageRecordList))
|
||||
);
|
||||
|
||||
@@ -34,33 +34,33 @@ export class TagService {
|
||||
this.properties.removeTagOption(tagId);
|
||||
}
|
||||
|
||||
tagsByPageId(pageId: string) {
|
||||
tagsByPageId$(pageId: string) {
|
||||
return LiveData.computed(get => {
|
||||
const pageRecord = get(this.pageRecordList.record(pageId));
|
||||
const pageRecord = get(this.pageRecordList.record$(pageId));
|
||||
if (!pageRecord) return [];
|
||||
const tagIds = get(pageRecord.meta).tags;
|
||||
const tagIds = get(pageRecord.meta$).tags;
|
||||
|
||||
return get(this.tags).filter(tag => tagIds.includes(tag.id));
|
||||
return get(this.tags$).filter(tag => tagIds.includes(tag.id));
|
||||
});
|
||||
}
|
||||
|
||||
tagIdsByPageId(pageId: string) {
|
||||
return this.tagsByPageId(pageId).map(tags => tags.map(tag => tag.id));
|
||||
tagIdsByPageId$(pageId: string) {
|
||||
return this.tagsByPageId$(pageId).map(tags => tags.map(tag => tag.id));
|
||||
}
|
||||
|
||||
tagByTagId(tagId?: string) {
|
||||
return this.tags.map(tags => tags.find(tag => tag.id === tagId));
|
||||
tagByTagId$(tagId?: string) {
|
||||
return this.tags$.map(tags => tags.find(tag => tag.id === tagId));
|
||||
}
|
||||
|
||||
tagMetas = LiveData.computed(get => {
|
||||
return get(this.tags).map(tag => {
|
||||
tagMetas$ = LiveData.computed(get => {
|
||||
return get(this.tags$).map(tag => {
|
||||
return {
|
||||
id: tag.id,
|
||||
title: get(tag.value),
|
||||
color: get(tag.color),
|
||||
pageCount: get(tag.pageIds).length,
|
||||
createDate: get(tag.createDate),
|
||||
updatedDate: get(tag.updateDate),
|
||||
title: get(tag.value$),
|
||||
color: get(tag.color$),
|
||||
pageCount: get(tag.pageIds$).length,
|
||||
createDate: get(tag.createDate$),
|
||||
updatedDate: get(tag.updateDate$),
|
||||
};
|
||||
});
|
||||
});
|
||||
@@ -71,15 +71,17 @@ export class TagService {
|
||||
return trimmedValue.includes(trimmedQuery);
|
||||
}
|
||||
|
||||
filterTagsByName(name: string) {
|
||||
filterTagsByName$(name: string) {
|
||||
return LiveData.computed(get => {
|
||||
return get(this.tags).filter(tag => this.filterFn(get(tag.value), name));
|
||||
return get(this.tags$).filter(tag =>
|
||||
this.filterFn(get(tag.value$), name)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
tagByTagValue(value: string) {
|
||||
tagByTagValue$(value: string) {
|
||||
return LiveData.computed(get => {
|
||||
return get(this.tags).find(tag => this.filterFn(get(tag.value), value));
|
||||
return get(this.tags$).find(tag => this.filterFn(get(tag.value$), value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ export const DeleteTagConfirmModal = ({
|
||||
}) => {
|
||||
const t = useAFFiNEI18N();
|
||||
const tagService = useService(TagService);
|
||||
const tags = useLiveData(tagService.tags);
|
||||
const tags = useLiveData(tagService.tags$);
|
||||
const selectedTags = useMemo(() => {
|
||||
return tags.filter(tag => selectedTagIds.includes(tag.id));
|
||||
}, [selectedTagIds, tags]);
|
||||
const tagName = useLiveData(selectedTags[0]?.value || '');
|
||||
const tagName = useLiveData(selectedTags[0]?.value$ || '');
|
||||
|
||||
const handleDelete = useCallback(() => {
|
||||
selectedTagIds.forEach(tagId => {
|
||||
|
||||
@@ -21,7 +21,7 @@ export class View {
|
||||
initialIndex: 0,
|
||||
});
|
||||
|
||||
location = LiveData.from<Location>(
|
||||
location$ = LiveData.from<Location>(
|
||||
new Observable(subscriber => {
|
||||
subscriber.next(this.history.location);
|
||||
return this.history.listen(update => {
|
||||
@@ -31,7 +31,7 @@ export class View {
|
||||
this.history.location
|
||||
);
|
||||
|
||||
entries = LiveData.from<Location[]>(
|
||||
entries$ = LiveData.from<Location[]>(
|
||||
new Observable(subscriber => {
|
||||
subscriber.next(this.history.entries);
|
||||
return this.history.listen(() => {
|
||||
@@ -41,7 +41,7 @@ export class View {
|
||||
this.history.entries
|
||||
);
|
||||
|
||||
size = new LiveData(100);
|
||||
size$ = new LiveData(100);
|
||||
|
||||
header = createIsland();
|
||||
body = createIsland();
|
||||
@@ -59,6 +59,6 @@ export class View {
|
||||
}
|
||||
|
||||
setSize(size?: number) {
|
||||
this.size.next(size ?? 100);
|
||||
this.size$.next(size ?? 100);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,32 +13,32 @@ interface WorkbenchOpenOptions {
|
||||
}
|
||||
|
||||
export class Workbench {
|
||||
readonly views = new LiveData([new View()]);
|
||||
readonly views$ = new LiveData([new View()]);
|
||||
|
||||
activeViewIndex = new LiveData(0);
|
||||
activeView = LiveData.from(
|
||||
combineLatest([this.views, this.activeViewIndex]).pipe(
|
||||
activeViewIndex$ = new LiveData(0);
|
||||
activeView$ = LiveData.from(
|
||||
combineLatest([this.views$, this.activeViewIndex$]).pipe(
|
||||
map(([views, index]) => views[index])
|
||||
),
|
||||
this.views.value[this.activeViewIndex.value]
|
||||
this.views$.value[this.activeViewIndex$.value]
|
||||
);
|
||||
|
||||
basename = new LiveData('/');
|
||||
basename$ = new LiveData('/');
|
||||
|
||||
location = LiveData.from(
|
||||
this.activeView.pipe(switchMap(view => view.location)),
|
||||
this.views.value[this.activeViewIndex.value].history.location
|
||||
location$ = LiveData.from(
|
||||
this.activeView$.pipe(switchMap(view => view.location$)),
|
||||
this.views$.value[this.activeViewIndex$.value].history.location
|
||||
);
|
||||
|
||||
active(index: number) {
|
||||
this.activeViewIndex.next(index);
|
||||
this.activeViewIndex$.next(index);
|
||||
}
|
||||
|
||||
createView(at: WorkbenchPosition = 'beside', defaultLocation: To) {
|
||||
const view = new View(defaultLocation);
|
||||
const newViews = [...this.views.value];
|
||||
const newViews = [...this.views$.value];
|
||||
newViews.splice(this.indexAt(at), 0, view);
|
||||
this.views.next(newViews);
|
||||
this.views$.next(newViews);
|
||||
return newViews.indexOf(view);
|
||||
}
|
||||
|
||||
@@ -91,33 +91,33 @@ export class Workbench {
|
||||
}
|
||||
|
||||
viewAt(positionIndex: WorkbenchPosition): View | undefined {
|
||||
return this.views.value[this.indexAt(positionIndex)];
|
||||
return this.views$.value[this.indexAt(positionIndex)];
|
||||
}
|
||||
|
||||
close(view: View) {
|
||||
if (this.views.value.length === 1) return;
|
||||
const index = this.views.value.indexOf(view);
|
||||
if (this.views$.value.length === 1) return;
|
||||
const index = this.views$.value.indexOf(view);
|
||||
if (index === -1) return;
|
||||
const newViews = [...this.views.value];
|
||||
const newViews = [...this.views$.value];
|
||||
newViews.splice(index, 1);
|
||||
const activeViewIndex = this.activeViewIndex.value;
|
||||
const activeViewIndex = this.activeViewIndex$.value;
|
||||
if (activeViewIndex !== 0 && activeViewIndex >= index) {
|
||||
this.active(activeViewIndex - 1);
|
||||
}
|
||||
this.views.next(newViews);
|
||||
this.views$.next(newViews);
|
||||
}
|
||||
|
||||
closeOthers(view: View) {
|
||||
view.size.next(100);
|
||||
this.views.next([view]);
|
||||
view.size$.next(100);
|
||||
this.views$.next([view]);
|
||||
this.active(0);
|
||||
}
|
||||
|
||||
moveView(from: number, to: number) {
|
||||
const views = [...this.views.value];
|
||||
const views = [...this.views$.value];
|
||||
const [removed] = views.splice(from, 1);
|
||||
views.splice(to, 0, removed);
|
||||
this.views.next(views);
|
||||
this.views$.next(views);
|
||||
this.active(to);
|
||||
}
|
||||
|
||||
@@ -128,18 +128,18 @@ export class Workbench {
|
||||
* @returns
|
||||
*/
|
||||
resize(index: number, percent: number) {
|
||||
const view = this.views.value[index];
|
||||
const nextView = this.views.value[index + 1];
|
||||
const view = this.views$.value[index];
|
||||
const nextView = this.views$.value[index + 1];
|
||||
if (!nextView) return;
|
||||
|
||||
const totalViewSize = this.views.value.reduce(
|
||||
(sum, v) => sum + v.size.value,
|
||||
const totalViewSize = this.views$.value.reduce(
|
||||
(sum, v) => sum + v.size$.value,
|
||||
0
|
||||
);
|
||||
const percentOfTotal = totalViewSize * percent;
|
||||
const newSize = Number((view.size.value + percentOfTotal).toFixed(4));
|
||||
const newSize = Number((view.size$.value + percentOfTotal).toFixed(4));
|
||||
const newNextSize = Number(
|
||||
(nextView.size.value - percentOfTotal).toFixed(4)
|
||||
(nextView.size$.value - percentOfTotal).toFixed(4)
|
||||
);
|
||||
// TODO: better strategy to limit size
|
||||
if (newSize / totalViewSize < 0.2 || newNextSize / totalViewSize < 0.2)
|
||||
@@ -150,16 +150,16 @@ export class Workbench {
|
||||
|
||||
private indexAt(positionIndex: WorkbenchPosition): number {
|
||||
if (positionIndex === 'active') {
|
||||
return this.activeViewIndex.value;
|
||||
return this.activeViewIndex$.value;
|
||||
}
|
||||
if (positionIndex === 'beside') {
|
||||
return this.activeViewIndex.value + 1;
|
||||
return this.activeViewIndex$.value + 1;
|
||||
}
|
||||
if (positionIndex === 'head') {
|
||||
return 0;
|
||||
}
|
||||
if (positionIndex === 'tail') {
|
||||
return this.views.value.length;
|
||||
return this.views$.value.length;
|
||||
}
|
||||
return positionIndex;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export function useBindWorkbenchToBrowserRouter(
|
||||
const navigate = useNavigate();
|
||||
const browserLocation = useLocation();
|
||||
|
||||
const view = useLiveData(workbench.activeView);
|
||||
const view = useLiveData(workbench.activeView$);
|
||||
|
||||
useEffect(() => {
|
||||
return view.history.listen(update => {
|
||||
|
||||
@@ -31,9 +31,9 @@ export function useBindWorkbenchToDesktopRouter(
|
||||
return;
|
||||
}
|
||||
if (
|
||||
workbench.location.value.pathname === newLocation.pathname &&
|
||||
workbench.location.value.search === newLocation.search &&
|
||||
workbench.location.value.hash === newLocation.hash
|
||||
workbench.location$.value.pathname === newLocation.pathname &&
|
||||
workbench.location$.value.search === newLocation.search &&
|
||||
workbench.location$.value.hash === newLocation.hash
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ export const RouteContainer = ({ route }: Props) => {
|
||||
const viewPosition = useViewPosition();
|
||||
const leftSidebarOpen = useAtomValue(appSidebarOpenAtom);
|
||||
const rightSidebar = useService(RightSidebar);
|
||||
const rightSidebarOpen = useLiveData(rightSidebar.isOpen);
|
||||
const rightSidebarHasViews = useLiveData(rightSidebar.hasViews);
|
||||
const rightSidebarOpen = useLiveData(rightSidebar.isOpen$);
|
||||
const rightSidebarHasViews = useLiveData(rightSidebar.hasViews$);
|
||||
const handleToggleRightSidebar = useCallback(() => {
|
||||
rightSidebar.toggle();
|
||||
}, [rightSidebar]);
|
||||
|
||||
@@ -45,10 +45,10 @@ export const SplitViewPanel = memo(function SplitViewPanel({
|
||||
}: SplitViewPanelProps) {
|
||||
const [indicatorPressed, setIndicatorPressed] = useState(false);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const size = useLiveData(view.size);
|
||||
const size = useLiveData(view.size$);
|
||||
const workbench = useService(Workbench);
|
||||
const activeView = useLiveData(workbench.activeView);
|
||||
const views = useLiveData(workbench.views);
|
||||
const activeView = useLiveData(workbench.activeView$);
|
||||
const views = useLiveData(workbench.views$);
|
||||
const isLast = views[views.length - 1] === view;
|
||||
|
||||
const {
|
||||
@@ -116,7 +116,7 @@ export const SplitViewPanel = memo(function SplitViewPanel({
|
||||
const SplitViewMenu = ({ view }: { view: View }) => {
|
||||
const t = useAFFiNEI18N();
|
||||
const workbench = useService(Workbench);
|
||||
const views = useLiveData(workbench.views);
|
||||
const views = useLiveData(workbench.views$);
|
||||
|
||||
const viewIndex = views.findIndex(v => v === view);
|
||||
|
||||
|
||||
@@ -7,6 +7,6 @@ import { useView } from './use-view';
|
||||
export function useIsActiveView() {
|
||||
const workbench = useService(Workbench);
|
||||
const currentView = useView();
|
||||
const activeView = useLiveData(workbench.activeView);
|
||||
const activeView = useLiveData(workbench.activeView$);
|
||||
return currentView === activeView;
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ export const useViewPosition = () => {
|
||||
const view = useView();
|
||||
|
||||
const [position, setPosition] = useState(() =>
|
||||
calcPosition(view, workbench.views.value)
|
||||
calcPosition(view, workbench.views$.value)
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const subscription = workbench.views.subscribe(views => {
|
||||
const subscription = workbench.views$.subscribe(views => {
|
||||
setPosition(calcPosition(view, views));
|
||||
});
|
||||
return () => {
|
||||
|
||||
@@ -33,7 +33,7 @@ const warpedRoutes = viewRoutes.map(({ path, lazy }) => {
|
||||
export const ViewRoot = ({ view }: { view: View }) => {
|
||||
const viewRouter = useMemo(() => createMemoryRouter(warpedRoutes), []);
|
||||
|
||||
const location = useLiveData(view.location);
|
||||
const location = useLiveData(view.location$);
|
||||
|
||||
useEffect(() => {
|
||||
viewRouter.navigate(location).catch(err => {
|
||||
|
||||
@@ -16,7 +16,7 @@ export const WorkbenchLink = ({
|
||||
>) => {
|
||||
const workbench = useService(Workbench);
|
||||
const { appSettings } = useAppSettingHelper();
|
||||
const basename = useLiveData(workbench.basename);
|
||||
const basename = useLiveData(workbench.basename$);
|
||||
const handleClick = useCallback(
|
||||
(event: React.MouseEvent<HTMLAnchorElement>) => {
|
||||
event.preventDefault();
|
||||
|
||||
@@ -21,7 +21,7 @@ export const WorkbenchRoot = () => {
|
||||
// for debugging
|
||||
(window as any).workbench = workbench;
|
||||
|
||||
const views = useLiveData(workbench.views);
|
||||
const views = useLiveData(workbench.views$);
|
||||
|
||||
const location = useLocation();
|
||||
const basename = location.pathname.match(/\/workspace\/[^/]+/g)?.[0] ?? '/';
|
||||
@@ -40,8 +40,8 @@ export const WorkbenchRoot = () => {
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
workbench.basename.next(basename);
|
||||
}, [basename, workbench.basename]);
|
||||
workbench.basename$.next(basename);
|
||||
}, [basename, workbench.basename$]);
|
||||
|
||||
return (
|
||||
<SplitView
|
||||
|
||||
@@ -5,20 +5,20 @@ import { LiveData } from '@toeverything/infra/livedata';
|
||||
* service to manage current workspace
|
||||
*/
|
||||
export class CurrentWorkspaceService {
|
||||
currentWorkspace = new LiveData<Workspace | null>(null);
|
||||
currentWorkspace$ = new LiveData<Workspace | null>(null);
|
||||
|
||||
/**
|
||||
* open workspace, current workspace will be set to the workspace
|
||||
* @param workspace
|
||||
*/
|
||||
openWorkspace(workspace: Workspace) {
|
||||
this.currentWorkspace.next(workspace);
|
||||
this.currentWorkspace$.next(workspace);
|
||||
}
|
||||
|
||||
/**
|
||||
* close current workspace, current workspace will be null
|
||||
*/
|
||||
closeWorkspace() {
|
||||
this.currentWorkspace.next(null);
|
||||
this.currentWorkspace$.next(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export const Component = () => {
|
||||
const [navigating, setNavigating] = useState(false);
|
||||
const [creating, setCreating] = useState(false);
|
||||
|
||||
const list = useLiveData(useService(WorkspaceListService).workspaceList);
|
||||
const list = useLiveData(useService(WorkspaceListService).workspaceList$);
|
||||
|
||||
const { openPage } = useNavigateHelper();
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ export const Component = () => {
|
||||
workspaceManager,
|
||||
]);
|
||||
|
||||
const pageTitle = useLiveData(page?.title);
|
||||
const pageTitle = useLiveData(page?.title$);
|
||||
|
||||
usePageDocumentTitle(pageTitle);
|
||||
const loginStatus = useCurrentLoginStatus();
|
||||
|
||||
@@ -26,7 +26,7 @@ export const AllCollection = () => {
|
||||
const [hideHeaderCreateNew, setHideHeaderCreateNew] = useState(true);
|
||||
|
||||
const collectionService = useService(CollectionService);
|
||||
const collections = useLiveData(collectionService.collections);
|
||||
const collections = useLiveData(collectionService.collections$);
|
||||
const config = useAllPageListConfig();
|
||||
|
||||
const collectionMetas = useMemo(() => {
|
||||
|
||||
@@ -32,11 +32,11 @@ const EmptyTagListHeader = () => {
|
||||
|
||||
export const AllTag = () => {
|
||||
const tagService = useService(TagService);
|
||||
const tags = useLiveData(tagService.tags);
|
||||
const tags = useLiveData(tagService.tags$);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [selectedTagIds, setSelectedTagIds] = useState<string[]>([]);
|
||||
|
||||
const tagMetas: TagMeta[] = useLiveData(tagService.tagMetas);
|
||||
const tagMetas: TagMeta[] = useLiveData(tagService.tagMetas$);
|
||||
|
||||
const handleCloseModal = useCallback(
|
||||
(open: boolean) => {
|
||||
|
||||
@@ -67,7 +67,7 @@ export const CollectionDetail = ({
|
||||
export const Component = function CollectionPage() {
|
||||
const collectionService = useService(CollectionService);
|
||||
|
||||
const collections = useLiveData(collectionService.collections);
|
||||
const collections = useLiveData(collectionService.collections$);
|
||||
const navigate = useNavigateHelper();
|
||||
const params = useParams();
|
||||
const workspace = useService(Workspace);
|
||||
@@ -76,7 +76,7 @@ export const Component = function CollectionPage() {
|
||||
useEffect(() => {
|
||||
if (!collection) {
|
||||
navigate.jumpToSubPath(workspace.id, WorkspaceSubPath.ALL);
|
||||
const collection = collectionService.collectionsTrash.value.find(
|
||||
const collection = collectionService.collectionsTrash$.value.find(
|
||||
v => v.collection.id === params.collectionId
|
||||
);
|
||||
let text = 'Collection does not exist';
|
||||
@@ -94,7 +94,7 @@ export const Component = function CollectionPage() {
|
||||
}
|
||||
}, [
|
||||
collection,
|
||||
collectionService.collectionsTrash.value,
|
||||
collectionService.collectionsTrash$.value,
|
||||
navigate,
|
||||
params.collectionId,
|
||||
pushNotification,
|
||||
|
||||
@@ -108,9 +108,9 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
||||
|
||||
const isInTrash = pageMeta?.trash;
|
||||
|
||||
const mode = useLiveData(page.mode);
|
||||
const mode = useLiveData(page.mode$);
|
||||
useRegisterBlocksuiteEditorCommands();
|
||||
const title = useLiveData(page.title);
|
||||
const title = useLiveData(page.title$);
|
||||
usePageDocumentTitle(title);
|
||||
|
||||
const onLoad = useCallback(
|
||||
@@ -156,13 +156,13 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
||||
const disposable = new DisposableGroup();
|
||||
|
||||
pageService.getEditorMode = (pageId: string) =>
|
||||
pageRecordList.record(pageId).value?.mode.value ?? 'page';
|
||||
pageRecordList.record$(pageId).value?.mode$.value ?? 'page';
|
||||
pageService.getDocUpdatedAt = (pageId: string) => {
|
||||
const linkedPage = pageRecordList.record(pageId).value;
|
||||
const linkedPage = pageRecordList.record$(pageId).value;
|
||||
if (!linkedPage) return new Date();
|
||||
|
||||
const updatedDate = linkedPage.meta.value.updatedDate;
|
||||
const createDate = linkedPage.meta.value.createDate;
|
||||
const updatedDate = linkedPage.meta$.value.updatedDate;
|
||||
const createDate = linkedPage.meta$.value.createDate;
|
||||
return updatedDate ? new Date(updatedDate) : new Date(createDate);
|
||||
};
|
||||
|
||||
@@ -278,9 +278,9 @@ export const DetailPage = ({ pageId }: { pageId: string }): ReactElement => {
|
||||
const currentWorkspace = useService(Workspace);
|
||||
const pageRecordList = useService(PageRecordList);
|
||||
|
||||
const pageListReady = useLiveData(pageRecordList.isReady);
|
||||
const pageListReady = useLiveData(pageRecordList.isReady$);
|
||||
|
||||
const pageRecords = useLiveData(pageRecordList.records);
|
||||
const pageRecords = useLiveData(pageRecordList.records$);
|
||||
|
||||
const pageRecord = useMemo(
|
||||
() => pageRecords.find(page => page.id === pageId),
|
||||
@@ -310,7 +310,7 @@ export const DetailPage = ({ pageId }: { pageId: string }): ReactElement => {
|
||||
};
|
||||
}, [currentWorkspace, pageId]);
|
||||
|
||||
const jumpOnce = useLiveData(pageRecord?.meta.map(meta => meta.jumpOnce));
|
||||
const jumpOnce = useLiveData(pageRecord?.meta$.map(meta => meta.jumpOnce));
|
||||
|
||||
useEffect(() => {
|
||||
if (jumpOnce) {
|
||||
|
||||
@@ -39,7 +39,7 @@ export const Component = (): ReactElement => {
|
||||
const params = useParams();
|
||||
|
||||
const { workspaceList, loading: listLoading } = useLiveData(
|
||||
useService(WorkspaceListService).status
|
||||
useService(WorkspaceListService).status$
|
||||
);
|
||||
const workspaceManager = useService(WorkspaceManager);
|
||||
|
||||
@@ -71,7 +71,7 @@ export const Component = (): ReactElement => {
|
||||
|
||||
// avoid doing operation, before workspace is loaded
|
||||
const isRootDocReady =
|
||||
useLiveData(workspace?.engine.rootDocState)?.ready ?? false;
|
||||
useLiveData(workspace?.engine.rootDocState$)?.ready ?? false;
|
||||
|
||||
// if listLoading is false, we can show 404 page, otherwise we should show loading page.
|
||||
if (listLoading === false && meta === undefined) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
ViewBodyIsland,
|
||||
ViewHeaderIsland,
|
||||
} from '@affine/core/modules/workbench';
|
||||
import { LiveData, useLiveData, useService } from '@toeverything/infra';
|
||||
import { useLiveData, useService } from '@toeverything/infra';
|
||||
import { Workspace } from '@toeverything/infra';
|
||||
import { useMemo } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
@@ -23,21 +23,9 @@ export const TagDetail = ({ tagId }: { tagId?: string }) => {
|
||||
const pageMetas = useBlockSuiteDocMeta(currentWorkspace.docCollection);
|
||||
|
||||
const tagService = useService(TagService);
|
||||
const currentTagLiveData = tagService.tagByTagId(tagId);
|
||||
const currentTag = useLiveData(currentTagLiveData);
|
||||
const currentTag = useLiveData(tagService.tagByTagId$(tagId));
|
||||
|
||||
const pageIdsLiveData = useMemo(
|
||||
() =>
|
||||
LiveData.computed(get => {
|
||||
const liveTag = get(currentTagLiveData);
|
||||
if (liveTag?.pageIds) {
|
||||
return get(liveTag.pageIds);
|
||||
}
|
||||
return [];
|
||||
}),
|
||||
[currentTagLiveData]
|
||||
);
|
||||
const pageIds = useLiveData(pageIdsLiveData);
|
||||
const pageIds = useLiveData(currentTag?.pageIds$);
|
||||
|
||||
const filteredPageMetas = useMemo(() => {
|
||||
const pageIdsSet = new Set(pageIds);
|
||||
|
||||
@@ -192,7 +192,7 @@ export const AuthModal = (): ReactElement => {
|
||||
|
||||
export function CurrentWorkspaceModals() {
|
||||
const currentWorkspace = useLiveData(
|
||||
useService(CurrentWorkspaceService).currentWorkspace
|
||||
useService(CurrentWorkspaceService).currentWorkspace$
|
||||
);
|
||||
const [openDisableCloudAlertModal, setOpenDisableCloudAlertModal] = useAtom(
|
||||
openDisableCloudAlertModalAtom
|
||||
@@ -227,10 +227,10 @@ export const SignOutConfirmModal = () => {
|
||||
const { openPage } = useNavigateHelper();
|
||||
const [open, setOpen] = useAtom(openSignOutModalAtom);
|
||||
const currentWorkspace = useLiveData(
|
||||
useService(CurrentWorkspaceService).currentWorkspace
|
||||
useService(CurrentWorkspaceService).currentWorkspace$
|
||||
);
|
||||
const workspaces = useLiveData(
|
||||
useService(WorkspaceManager).list.workspaceList
|
||||
useService(WorkspaceManager).list.workspaceList$
|
||||
);
|
||||
|
||||
const onConfirm = useAsyncCallback(async () => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useEffect, useRef } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
|
||||
export const createIsland = () => {
|
||||
const targetLiveData = new LiveData<HTMLDivElement | null>(null);
|
||||
const targetLiveData$ = new LiveData<HTMLDivElement | null>(null);
|
||||
let mounted = false;
|
||||
let provided = false;
|
||||
return {
|
||||
@@ -14,16 +14,16 @@ export const createIsland = () => {
|
||||
throw new Error('Island should not be mounted more than once');
|
||||
}
|
||||
mounted = true;
|
||||
targetLiveData.next(target.current);
|
||||
targetLiveData$.next(target.current);
|
||||
return () => {
|
||||
mounted = false;
|
||||
targetLiveData.next(null);
|
||||
targetLiveData$.next(null);
|
||||
};
|
||||
}, []);
|
||||
return <div {...other} ref={target}></div>;
|
||||
},
|
||||
Provider: ({ children }: React.PropsWithChildren) => {
|
||||
const target = useLiveData(targetLiveData);
|
||||
const target = useLiveData(targetLiveData$);
|
||||
useEffect(() => {
|
||||
if (provided === true && process.env.NODE_ENV !== 'production') {
|
||||
throw new Error('Island should not be provided more than once');
|
||||
|
||||
Reference in New Issue
Block a user