feat(core): import template (#8000)
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
import { useLiveData, useService, WorkspaceService } from '@toeverything/infra';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
export function useDocEngineStatus() {
|
||||
const workspace = useService(WorkspaceService).workspace;
|
||||
|
||||
const engineState = useLiveData(
|
||||
workspace.engine.docEngineState$.throttleTime(100)
|
||||
);
|
||||
const progress =
|
||||
(engineState.total - engineState.syncing) / engineState.total;
|
||||
|
||||
return useMemo(
|
||||
() => ({
|
||||
...engineState,
|
||||
progress,
|
||||
syncing: engineState.syncing > 0 || engineState.retrying,
|
||||
}),
|
||||
[engineState, progress]
|
||||
);
|
||||
}
|
||||
@@ -1,28 +1,28 @@
|
||||
import type { WorkspaceSubPath } from '@affine/core/shared';
|
||||
import { useCallback, useContext, useMemo } from 'react';
|
||||
import type { NavigateOptions, To } from 'react-router-dom';
|
||||
import { createContext, useCallback, useContext, useMemo } from 'react';
|
||||
import type { NavigateFunction, NavigateOptions } from 'react-router-dom';
|
||||
|
||||
import { NavigateContext, router } from '../router';
|
||||
/**
|
||||
* In workbench, we use nested react-router, so default `useNavigate` can't get correct navigate function in workbench.
|
||||
* We use this context to provide navigate function for whole app.
|
||||
*/
|
||||
export const NavigateContext = createContext<NavigateFunction | null>(null);
|
||||
|
||||
export enum RouteLogic {
|
||||
REPLACE = 'replace',
|
||||
PUSH = 'push',
|
||||
}
|
||||
|
||||
function defaultNavigate(to: To, option?: { replace?: boolean }) {
|
||||
setTimeout(() => {
|
||||
router?.navigate(to, option).catch(err => {
|
||||
console.error('Failed to navigate', err);
|
||||
});
|
||||
}, 100);
|
||||
}
|
||||
|
||||
// TODO(@eyhn): add a name -> path helper in the results
|
||||
/**
|
||||
* @deprecated use `WorkbenchService` instead
|
||||
* Use this for over workbench navigate, for navigate in workbench, use `WorkbenchService`.
|
||||
*/
|
||||
export function useNavigateHelper() {
|
||||
const navigate = useContext(NavigateContext) ?? defaultNavigate;
|
||||
const navigate = useContext(NavigateContext);
|
||||
|
||||
if (!navigate) {
|
||||
throw new Error('useNavigateHelper must be used within a NavigateProvider');
|
||||
}
|
||||
|
||||
const jumpToPage = useCallback(
|
||||
(
|
||||
@@ -147,7 +147,7 @@ export function useNavigateHelper() {
|
||||
const searchParams = new URLSearchParams();
|
||||
|
||||
if (redirectUri) {
|
||||
searchParams.set('redirect_uri', encodeURIComponent(redirectUri));
|
||||
searchParams.set('redirect_uri', redirectUri);
|
||||
}
|
||||
|
||||
if (params) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
registerAffineUpdatesCommands,
|
||||
} from '../commands';
|
||||
import { usePageHelper } from '../components/blocksuite/block-suite-page-list/utils';
|
||||
import { CreateWorkspaceDialogService } from '../modules/create-workspace';
|
||||
import { EditorSettingService } from '../modules/editor-settting';
|
||||
import { CMDKQuickSearchService } from '../modules/quicksearch/services/cmdk';
|
||||
import { useLanguageHelper } from './affine/use-language-helper';
|
||||
@@ -69,6 +70,7 @@ export function useRegisterWorkspaceCommands() {
|
||||
const [editor] = useActiveBlocksuiteEditor();
|
||||
const cmdkQuickSearchService = useService(CMDKQuickSearchService);
|
||||
const editorSettingService = useService(EditorSettingService);
|
||||
const createWorkspaceDialogService = useService(CreateWorkspaceDialogService);
|
||||
|
||||
useEffect(() => {
|
||||
const unsub = registerCMDKCommand(cmdkQuickSearchService, editor);
|
||||
@@ -131,7 +133,7 @@ export function useRegisterWorkspaceCommands() {
|
||||
// register AffineCreationCommands
|
||||
useEffect(() => {
|
||||
const unsub = registerAffineCreationCommands({
|
||||
store,
|
||||
createWorkspaceDialogService,
|
||||
pageHelper: pageHelper,
|
||||
t,
|
||||
});
|
||||
@@ -139,7 +141,7 @@ export function useRegisterWorkspaceCommands() {
|
||||
return () => {
|
||||
unsub();
|
||||
};
|
||||
}, [store, pageHelper, t]);
|
||||
}, [store, pageHelper, t, createWorkspaceDialogService]);
|
||||
|
||||
// register AffineHelpCommands
|
||||
useEffect(() => {
|
||||
|
||||
@@ -6,19 +6,19 @@ import {
|
||||
} from '@toeverything/infra';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export function useWorkspaceInfo(meta: WorkspaceMetadata) {
|
||||
export function useWorkspaceInfo(meta?: WorkspaceMetadata) {
|
||||
const workspacesService = useService(WorkspacesService);
|
||||
|
||||
const profile = workspacesService.getProfile(meta);
|
||||
const profile = meta ? workspacesService.getProfile(meta) : undefined;
|
||||
|
||||
useEffect(() => {
|
||||
profile.revalidate();
|
||||
profile?.revalidate();
|
||||
}, [meta, profile]);
|
||||
|
||||
return useLiveData(profile.profile$);
|
||||
return useLiveData(profile?.profile$);
|
||||
}
|
||||
|
||||
export function useWorkspaceName(meta: WorkspaceMetadata) {
|
||||
export function useWorkspaceName(meta?: WorkspaceMetadata) {
|
||||
const information = useWorkspaceInfo(meta);
|
||||
|
||||
return information?.name;
|
||||
|
||||
Reference in New Issue
Block a user