hunk.code_window:   await page
       .getByTestId('upload-avatar')
       .setInputFiles('./tests/fixtures/smile.png');
     await page.getByTestId('workspace-name').click();
     await page.getByTestId('workspace-card').nth(0).click();
     await page.waitForTimeout(1000);
     await page.getByTestId('workspace-name').click();
     await page.getByTestId('workspace-card').nth(1).click();
  
hunk.labels: keep keep add keep keep keep keep keep
hunk.after_edit:   await page.mouse.click(0, 0);
  
hunk.file_path: tests/parallels/local-first-avatar.spec.ts
hunk.type: add
file: import { DebugLogger } from '@affine/debug';
  import type { BlobManager } from '@blocksuite/store';
  import { useEffect, useMemo, useRef, useState } from 'react';
  
  import type { BlockSuiteWorkspace } from '../shared';
  
  const logger = new DebugLogger('useWorkspaceBlob');
  
  export function useWorkspaceBlob(
    blockSuiteWorkspace: BlockSuiteWorkspace
  ): BlobManager {
    return useMemo(() => blockSuiteWorkspace.blobs, [blockSuiteWorkspace.blobs]);
  }
  
  export function useWorkspaceBlobImage(
    key: string | null,
    blockSuiteWorkspace: BlockSuiteWorkspace
  ) {
    const blobManager = useWorkspaceBlob(blockSuiteWorkspace);
    const [blob, setBlob] = useState<Blob | null>(null);
    useEffect(() => {
      const controller = new AbortController();
      if (key === null) {
        setBlob(null);
        return;
      }
      blobManager
        ?.get(key)
        .then(blob => {
          if (controller.signal.aborted) {
            return;
          }
          if (blob) {
            setBlob(blob);
          }
        })
        .catch(err => {
          logger.error('Failed to get blob', err);
        });
      return () => {
        controller.abort();
      };
    }, [blobManager, key]);
    const [url, setUrl] = useState<string | null>(null);
    const ref = useRef<string | null>(null);
  
    useEffect(() => {
      if (ref.current) {
        URL.revokeObjectURL(ref.current);
      }
      if (blob) {
        const url = URL.createObjectURL(blob);
        setUrl(url);
        ref.current = url;
      }
    }, [blob]);
    return url;
  }
  