mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
fix: public workspace loading (#1144)
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
import { WorkspaceUnit } from '@affine/datacenter';
|
||||
import { dataCenterPromise } from '@affine/store';
|
||||
import { useRouter } from 'next/router';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export function useLoadPublicWorkspace(workspaceId: string) {
|
||||
const router = useRouter();
|
||||
const [workspace, setWorkspace] = useState<WorkspaceUnit | null>();
|
||||
const [status, setStatus] = useState<'loading' | 'error' | 'success'>(
|
||||
'loading'
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setStatus('loading');
|
||||
|
||||
const init = async () => {
|
||||
const dataCenter = await dataCenterPromise;
|
||||
|
||||
dataCenter
|
||||
.loadPublicWorkspace(workspaceId)
|
||||
.then(data => {
|
||||
setWorkspace(data);
|
||||
setStatus('success');
|
||||
})
|
||||
.catch(() => {
|
||||
// if (!cancel) {
|
||||
// router.push('/404');
|
||||
// }
|
||||
setStatus('error');
|
||||
});
|
||||
};
|
||||
init();
|
||||
}, [router, workspaceId]);
|
||||
|
||||
return { status, workspace };
|
||||
}
|
||||
Reference in New Issue
Block a user