mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
fix: should show workspace avatar using blob url (#949)
This commit is contained in:
31
apps/web/src/hooks/use-public-workspace.ts
Normal file
31
apps/web/src/hooks/use-public-workspace.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user