hunk.code_window: import dynamic from 'next/dynamic';
   import { useRouter } from 'next/router';
   import type React from 'react';
   import { useCallback } from 'react';
   import {
     currentWorkspaceIdAtom,
  
hunk.labels: keep keep keep replace keep keep keep
hunk.after_edit: import { useCallback, useTransition } from 'react';
  
hunk.file_path: apps/web/src/providers/ModalProvider.tsx
hunk.type: replace
file: import { DebugLogger } from '@affine/debug';
  import { DEFAULT_WORKSPACE_NAME } from '@affine/env';
  import { jotaiStore, jotaiWorkspacesAtom } from '@affine/workspace/atom';
  import { CRUD } from '@affine/workspace/local/crud';
  import { LoadPriority, WorkspaceFlavour } from '@affine/workspace/type';
  import { createEmptyBlockSuiteWorkspace } from '@affine/workspace/utils';
  import { assertEquals, assertExists, nanoid } from '@blocksuite/store';
  import React from 'react';
  
  import { PageNotFoundError } from '../../components/affine/affine-error-eoundary';
  import { WorkspaceSettingDetail } from '../../components/affine/workspace-setting-detail';
  import { BlockSuitePageList } from '../../components/blocksuite/block-suite-page-list';
  import { PageDetailEditor } from '../../components/page-detail-editor';
  import { initPage } from '../../utils';
  import type { WorkspacePlugin } from '..';
  
  const logger = new DebugLogger('use-create-first-workspace');
  
  export const LocalPlugin: WorkspacePlugin<WorkspaceFlavour.LOCAL> = {
    flavour: WorkspaceFlavour.LOCAL,
    loadPriority: LoadPriority.LOW,
    Events: {
      'app:first-init': async () => {
        const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(
          nanoid(),
          (_: string) => undefined
        );
        blockSuiteWorkspace.meta.setName(DEFAULT_WORKSPACE_NAME);
        const id = await LocalPlugin.CRUD.create(blockSuiteWorkspace);
        const workspace = await LocalPlugin.CRUD.get(id);
        assertExists(workspace);
        assertEquals(workspace.id, id);
        // todo: use a better way to set initial workspace
        jotaiStore.set(jotaiWorkspacesAtom, ws => [
          ...ws,
          {
            id: workspace.id,
            flavour: WorkspaceFlavour.LOCAL,
          },
        ]);
        logger.debug('create first workspace', workspace);
      },
    },
    CRUD,
    UI: {
      Provider: ({ children }) => {
        return <>{children}</>;
      },
      PageDetail: ({ currentWorkspace, currentPageId }) => {
        const page = currentWorkspace.blockSuiteWorkspace.getPage(currentPageId);
        if (!page) {
          throw new PageNotFoundError(
            currentWorkspace.blockSuiteWorkspace,
            currentPageId
          );
        }
        return (
          <>
            <PageDetailEditor
              pageId={currentPageId}
              onInit={initPage}
              blockSuiteWorkspace={currentWorkspace.blockSuiteWorkspace}
            />
          </>
        );
      },
      PageList: ({ blockSuiteWorkspace, onOpenPage }) => {
        return (
          <BlockSuitePageList
            onOpenPage={onOpenPage}
            blockSuiteWorkspace={blockSuiteWorkspace}
          />
        );
      },
      SettingsDetail: ({
        currentWorkspace,
        onChangeTab,
        currentTab,
        onDeleteWorkspace,
        onTransformWorkspace,
      }) => {
        return (
          <WorkspaceSettingDetail
            onDeleteWorkspace={onDeleteWorkspace}
            onChangeTab={onChangeTab}
            currentTab={currentTab}
            workspace={currentWorkspace}
            onTransferWorkspace={onTransformWorkspace}
          />
        );
      },
    },
  };
  