fix: should show workspace avatar using blob url (#949)

This commit is contained in:
Peng Xiao
2023-02-13 17:43:44 +08:00
committed by GitHub
parent 98ceb082fc
commit 298f2c1feb
3 changed files with 91 additions and 69 deletions

View File

@@ -0,0 +1,31 @@
import { useAppState } from '@/providers/app-state-provider';
import { WorkspaceUnit } from '@affine/datacenter';
import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
export function usePublicWorkspace(workspaceId: string) {
const { dataCenter } = useAppState();
const router = useRouter();
const [workspace, setWorkspace] = useState<WorkspaceUnit>();
useEffect(() => {
let cancel = false;
dataCenter
.loadPublicWorkspace(workspaceId)
.then(data => {
if (!cancel) {
setWorkspace(data);
}
})
.catch(() => {
if (!cancel) {
router.push('/404');
}
});
return () => {
cancel = true;
};
}, [router, workspaceId, dataCenter]);
return workspace;
}