mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-23 02:21:49 +03:00
refactor: move useBlockSuiteWorkspaceAvatarUrl
(#1802)
This commit is contained in:
parent
5c46c7d9fc
commit
dbcadbaf60
@ -1,12 +1,12 @@
|
|||||||
import { Button, FlexWrapper, MuiFade } from '@affine/component';
|
import { Button, FlexWrapper, MuiFade } from '@affine/component';
|
||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
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 { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
import { useIsWorkspaceOwner } from '../../../../../hooks/affine/use-is-workspace-owner';
|
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 { Upload } from '../../../../pure/file-upload';
|
||||||
import {
|
import {
|
||||||
CloudWorkspaceIcon,
|
CloudWorkspaceIcon,
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { Content, FlexWrapper, styled } from '@affine/component';
|
import { Content, FlexWrapper, styled } from '@affine/component';
|
||||||
import { Trans, useTranslation } from '@affine/i18n';
|
import { Trans, useTranslation } from '@affine/i18n';
|
||||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
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 { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
|
|
||||||
import { useCurrentUser } from '../../../../../hooks/current/use-current-user';
|
import { useCurrentUser } from '../../../../../hooks/current/use-current-user';
|
||||||
import { useBlockSuiteWorkspaceAvatarUrl } from '../../../../../hooks/use-blocksuite-workspace-avatar-url';
|
|
||||||
import { WorkspaceAvatar } from '../../../../pure/footer';
|
import { WorkspaceAvatar } from '../../../../pure/footer';
|
||||||
import type { PanelProps } from '../../index';
|
import type { PanelProps } from '../../index';
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { UNTITLED_WORKSPACE_NAME } from '@affine/env';
|
import { UNTITLED_WORKSPACE_NAME } from '@affine/env';
|
||||||
|
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import { memo } from 'react';
|
import { memo } from 'react';
|
||||||
|
|
||||||
import { useBlockSuiteWorkspaceAvatarUrl } from '../../../hooks/use-blocksuite-workspace-avatar-url';
|
|
||||||
import type { AllWorkspace, BlockSuiteWorkspace } from '../../../shared';
|
import type { AllWorkspace, BlockSuiteWorkspace } from '../../../shared';
|
||||||
import { stringToColour } from '../../../utils';
|
import { stringToColour } from '../../../utils';
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { Breadcrumbs, IconButton, ListSkeleton } from '@affine/component';
|
import { Breadcrumbs, IconButton, ListSkeleton } from '@affine/component';
|
||||||
import { SearchIcon } from '@blocksuite/icons';
|
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 { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
|
||||||
import { useAtomValue, useSetAtom } from 'jotai';
|
import { useAtomValue, useSetAtom } from 'jotai';
|
||||||
import dynamic from 'next/dynamic';
|
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 { StyledTableContainer } from '../../components/blocksuite/block-suite-page-list/page-list/styles';
|
||||||
import { WorkspaceAvatar } from '../../components/pure/footer';
|
import { WorkspaceAvatar } from '../../components/pure/footer';
|
||||||
import { PageLoading } from '../../components/pure/loading';
|
import { PageLoading } from '../../components/pure/loading';
|
||||||
import { useBlockSuiteWorkspaceAvatarUrl } from '../../hooks/use-blocksuite-workspace-avatar-url';
|
|
||||||
import { PublicWorkspaceLayout } from '../../layouts/public-workspace-layout';
|
import { PublicWorkspaceLayout } from '../../layouts/public-workspace-layout';
|
||||||
import type { NextPageWithLayout } from '../../shared';
|
import type { NextPageWithLayout } from '../../shared';
|
||||||
import { NavContainer, StyledBreadcrumbs } from './[workspaceId]/[pageId]';
|
import { NavContainer, StyledBreadcrumbs } from './[workspaceId]/[pageId]';
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Breadcrumbs, displayFlex, styled } from '@affine/component';
|
import { Breadcrumbs, displayFlex, styled } from '@affine/component';
|
||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import { PageIcon } from '@blocksuite/icons';
|
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 { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
|
||||||
import { useAtomValue, useSetAtom } from 'jotai';
|
import { useAtomValue, useSetAtom } from 'jotai';
|
||||||
import Link from 'next/link';
|
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 { PageDetailEditor } from '../../../components/page-detail-editor';
|
||||||
import { WorkspaceAvatar } from '../../../components/pure/footer';
|
import { WorkspaceAvatar } from '../../../components/pure/footer';
|
||||||
import { PageLoading } from '../../../components/pure/loading';
|
import { PageLoading } from '../../../components/pure/loading';
|
||||||
import { useBlockSuiteWorkspaceAvatarUrl } from '../../../hooks/use-blocksuite-workspace-avatar-url';
|
|
||||||
import { PublicWorkspaceLayout } from '../../../layouts/public-workspace-layout';
|
import { PublicWorkspaceLayout } from '../../../layouts/public-workspace-layout';
|
||||||
import type { NextPageWithLayout } from '../../../shared';
|
import type { NextPageWithLayout } from '../../../shared';
|
||||||
import { initPage } from '../../../utils';
|
import { initPage } from '../../../utils';
|
||||||
|
@ -1,23 +1,26 @@
|
|||||||
|
import type { Workspace } from '@blocksuite/store';
|
||||||
import { assertExists } from '@blocksuite/store';
|
import { assertExists } from '@blocksuite/store';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
|
|
||||||
import { QueryKey } from '../plugins/affine/fetcher';
|
|
||||||
import type { BlockSuiteWorkspace } from '../shared';
|
|
||||||
|
|
||||||
export function useBlockSuiteWorkspaceAvatarUrl(
|
export function useBlockSuiteWorkspaceAvatarUrl(
|
||||||
// todo: remove `null` from type
|
// todo: remove `null` from type
|
||||||
blockSuiteWorkspace: BlockSuiteWorkspace | null
|
blockSuiteWorkspace: Workspace | null
|
||||||
) {
|
) {
|
||||||
const { data: avatar, mutate } = useSWR(
|
const { data: avatar, mutate } = useSWR(
|
||||||
blockSuiteWorkspace
|
blockSuiteWorkspace && blockSuiteWorkspace.meta.avatar
|
||||||
? [
|
? [blockSuiteWorkspace.id, blockSuiteWorkspace.meta.avatar]
|
||||||
QueryKey.getImage,
|
|
||||||
blockSuiteWorkspace.id,
|
|
||||||
blockSuiteWorkspace.meta.avatar,
|
|
||||||
]
|
|
||||||
: null,
|
: null,
|
||||||
{
|
{
|
||||||
|
fetcher: async ([id, avatar]) => {
|
||||||
|
assertExists(blockSuiteWorkspace);
|
||||||
|
const blobs = await blockSuiteWorkspace.blobs;
|
||||||
|
if (blobs) {
|
||||||
|
return blobs.get(avatar);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
suspense: true,
|
||||||
fallbackData: null,
|
fallbackData: null,
|
||||||
}
|
}
|
||||||
);
|
);
|
Loading…
Reference in New Issue
Block a user