refactor: move useBlockSuiteWorkspaceAvatarUrl (#1802)

This commit is contained in:
Himself65 2023-04-03 17:35:57 -05:00 committed by GitHub
parent 5c46c7d9fc
commit dbcadbaf60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 15 deletions

View File

@ -1,12 +1,12 @@
import { Button, FlexWrapper, MuiFade } from '@affine/component';
import { useTranslation } from '@affine/i18n';
import { WorkspaceFlavour } from '@affine/workspace/type';
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
import type React from 'react';
import { useState } from 'react';
import { useIsWorkspaceOwner } from '../../../../../hooks/affine/use-is-workspace-owner';
import { useBlockSuiteWorkspaceAvatarUrl } from '../../../../../hooks/use-blocksuite-workspace-avatar-url';
import { Upload } from '../../../../pure/file-upload';
import {
CloudWorkspaceIcon,

View File

@ -1,11 +1,11 @@
import { Content, FlexWrapper, styled } from '@affine/component';
import { Trans, useTranslation } from '@affine/i18n';
import { WorkspaceFlavour } from '@affine/workspace/type';
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
import type React from 'react';
import { useCurrentUser } from '../../../../../hooks/current/use-current-user';
import { useBlockSuiteWorkspaceAvatarUrl } from '../../../../../hooks/use-blocksuite-workspace-avatar-url';
import { WorkspaceAvatar } from '../../../../pure/footer';
import type { PanelProps } from '../../index';

View File

@ -1,8 +1,8 @@
import { UNTITLED_WORKSPACE_NAME } from '@affine/env';
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
import type React from 'react';
import { memo } from 'react';
import { useBlockSuiteWorkspaceAvatarUrl } from '../../../hooks/use-blocksuite-workspace-avatar-url';
import type { AllWorkspace, BlockSuiteWorkspace } from '../../../shared';
import { stringToColour } from '../../../utils';

View File

@ -1,5 +1,6 @@
import { Breadcrumbs, IconButton, ListSkeleton } from '@affine/component';
import { SearchIcon } from '@blocksuite/icons';
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
import { useAtomValue, useSetAtom } from 'jotai';
import dynamic from 'next/dynamic';
@ -16,7 +17,6 @@ import { QueryParamError } from '../../components/affine/affine-error-eoundary';
import { StyledTableContainer } from '../../components/blocksuite/block-suite-page-list/page-list/styles';
import { WorkspaceAvatar } from '../../components/pure/footer';
import { PageLoading } from '../../components/pure/loading';
import { useBlockSuiteWorkspaceAvatarUrl } from '../../hooks/use-blocksuite-workspace-avatar-url';
import { PublicWorkspaceLayout } from '../../layouts/public-workspace-layout';
import type { NextPageWithLayout } from '../../shared';
import { NavContainer, StyledBreadcrumbs } from './[workspaceId]/[pageId]';

View File

@ -1,6 +1,7 @@
import { Breadcrumbs, displayFlex, styled } from '@affine/component';
import { useTranslation } from '@affine/i18n';
import { PageIcon } from '@blocksuite/icons';
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
import { useAtomValue, useSetAtom } from 'jotai';
import Link from 'next/link';
@ -16,7 +17,6 @@ import { QueryParamError } from '../../../components/affine/affine-error-eoundar
import { PageDetailEditor } from '../../../components/page-detail-editor';
import { WorkspaceAvatar } from '../../../components/pure/footer';
import { PageLoading } from '../../../components/pure/loading';
import { useBlockSuiteWorkspaceAvatarUrl } from '../../../hooks/use-blocksuite-workspace-avatar-url';
import { PublicWorkspaceLayout } from '../../../layouts/public-workspace-layout';
import type { NextPageWithLayout } from '../../../shared';
import { initPage } from '../../../utils';

View File

@ -1,23 +1,26 @@
import type { Workspace } from '@blocksuite/store';
import { assertExists } from '@blocksuite/store';
import { useCallback } from 'react';
import useSWR from 'swr';
import { QueryKey } from '../plugins/affine/fetcher';
import type { BlockSuiteWorkspace } from '../shared';
export function useBlockSuiteWorkspaceAvatarUrl(
// todo: remove `null` from type
blockSuiteWorkspace: BlockSuiteWorkspace | null
blockSuiteWorkspace: Workspace | null
) {
const { data: avatar, mutate } = useSWR(
blockSuiteWorkspace
? [
QueryKey.getImage,
blockSuiteWorkspace.id,
blockSuiteWorkspace.meta.avatar,
]
blockSuiteWorkspace && blockSuiteWorkspace.meta.avatar
? [blockSuiteWorkspace.id, blockSuiteWorkspace.meta.avatar]
: null,
{
fetcher: async ([id, avatar]) => {
assertExists(blockSuiteWorkspace);
const blobs = await blockSuiteWorkspace.blobs;
if (blobs) {
return blobs.get(avatar);
}
return null;
},
suspense: true,
fallbackData: null,
}
);