mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
refactor: use nano id (#1234)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useTranslation } from '@affine/i18n';
|
||||
import { PlusIcon } from '@blocksuite/icons';
|
||||
import { assertEquals, uuidv4 } from '@blocksuite/store';
|
||||
import { assertEquals, nanoid } from '@blocksuite/store';
|
||||
import { Command } from 'cmdk';
|
||||
import { NextRouter } from 'next/router';
|
||||
import React from 'react';
|
||||
@@ -30,7 +30,7 @@ export const Footer: React.FC<FooterProps> = ({
|
||||
data-testid="quick-search-add-new-page"
|
||||
onSelect={async () => {
|
||||
onClose();
|
||||
const id = uuidv4();
|
||||
const id = nanoid();
|
||||
const pageId = await createPage(id, query);
|
||||
assertEquals(pageId, id);
|
||||
router.push({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Workspace } from '@affine/datacenter';
|
||||
import { uuidv4 } from '@blocksuite/store';
|
||||
import { nanoid } from '@blocksuite/store';
|
||||
import { useCallback, useMemo, useSyncExternalStore } from 'react';
|
||||
import useSWR from 'swr';
|
||||
import { IndexeddbPersistence } from 'y-indexeddb';
|
||||
@@ -37,7 +37,7 @@ declare global {
|
||||
globalThis.dataCenter = dataCenter;
|
||||
|
||||
function createRemLocalWorkspace(name: string) {
|
||||
const id = uuidv4();
|
||||
const id = nanoid();
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(id);
|
||||
blockSuiteWorkspace.meta.setName(name);
|
||||
const workspace: LocalWorkspace = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { setUpLanguage, useTranslation } from '@affine/i18n';
|
||||
import { assertExists, uuidv4 } from '@blocksuite/store';
|
||||
import { assertExists, nanoid } from '@blocksuite/store';
|
||||
import { useAtom, useAtomValue } from 'jotai';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
import { useRouter } from 'next/router';
|
||||
@@ -84,7 +84,7 @@ export const WorkspaceLayout: React.FC<React.PropsWithChildren> = ({
|
||||
[currentWorkspace, isPublicWorkspace, router]
|
||||
);
|
||||
const handleCreatePage = useCallback(async () => {
|
||||
return helper.createPage(uuidv4());
|
||||
return helper.createPage(nanoid());
|
||||
}, [helper]);
|
||||
const handleOpenWorkspaceListModal = useCallback(() => {
|
||||
setOpenWorkspacesModal(true);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { assertEquals, uuidv4 } from '@blocksuite/store';
|
||||
import { assertEquals, nanoid } from '@blocksuite/store';
|
||||
import React from 'react';
|
||||
import { IndexeddbPersistence } from 'y-indexeddb';
|
||||
|
||||
@@ -33,7 +33,7 @@ export const LocalPlugin: WorkspacePlugin<RemWorkspaceFlavour.LOCAL> = {
|
||||
localStorage.setItem(kStoreKey, '[]');
|
||||
ids = [];
|
||||
}
|
||||
const id = uuidv4();
|
||||
const id = nanoid();
|
||||
const persistence = new IndexeddbPersistence(id, blockSuiteWorkspace.doc);
|
||||
await persistence.whenSynced.then(() => {
|
||||
persistence.destroy();
|
||||
@@ -135,11 +135,11 @@ export const LocalPlugin: WorkspacePlugin<RemWorkspaceFlavour.LOCAL> = {
|
||||
return;
|
||||
}
|
||||
console.info('no local workspace found, create a new one');
|
||||
const workspaceId = uuidv4();
|
||||
const workspaceId = nanoid();
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(workspaceId);
|
||||
blockSuiteWorkspace.meta.setName('Untitled Workspace');
|
||||
localStorage.setItem(kStoreKey, JSON.stringify([workspaceId]));
|
||||
blockSuiteWorkspace.createPage(uuidv4());
|
||||
blockSuiteWorkspace.createPage(nanoid());
|
||||
const workspace: LocalWorkspace = {
|
||||
id: workspaceId,
|
||||
flavour: RemWorkspaceFlavour.LOCAL,
|
||||
|
||||
Reference in New Issue
Block a user