mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-02 18:09:58 +08:00
feat: workspace router
This commit is contained in:
+9
-2
@@ -1,3 +1,4 @@
|
|||||||
|
import { useRouter } from 'next/router';
|
||||||
import { styled } from '@/styles';
|
import { styled } from '@/styles';
|
||||||
import {
|
import {
|
||||||
WorkspaceItemAvatar,
|
WorkspaceItemAvatar,
|
||||||
@@ -13,9 +14,15 @@ interface WorkspaceItemProps {
|
|||||||
icon: string;
|
icon: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WorkspaceItem = ({ name, icon }: WorkspaceItemProps) => {
|
export const WorkspaceItem = ({ id, name, icon }: WorkspaceItemProps) => {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledWrapper>
|
<StyledWrapper
|
||||||
|
onClick={() => {
|
||||||
|
router.push(`/workspace/${id}`);
|
||||||
|
}}
|
||||||
|
>
|
||||||
<WorkspaceItemAvatar alt={name} src={icon}>
|
<WorkspaceItemAvatar alt={name} src={icon}>
|
||||||
{name.charAt(0)}
|
{name.charAt(0)}
|
||||||
</WorkspaceItemAvatar>
|
</WorkspaceItemAvatar>
|
||||||
|
|||||||
+1
@@ -8,6 +8,7 @@ export const WorkspaceSelector = () => {
|
|||||||
content={<SelectorPopperContent />}
|
content={<SelectorPopperContent />}
|
||||||
zIndex={1000}
|
zIndex={1000}
|
||||||
placement="bottom-start"
|
placement="bottom-start"
|
||||||
|
trigger="hover"
|
||||||
>
|
>
|
||||||
<SelectorWrapper>
|
<SelectorWrapper>
|
||||||
<Avatar alt="Affine" />
|
<Avatar alt="Affine" />
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import type { NextPage } from 'next';
|
||||||
|
import { styled } from '@/styles';
|
||||||
|
import { EditorHeader } from '@/components/header';
|
||||||
|
import EdgelessToolbar from '@/components/edgeless-toolbar';
|
||||||
|
import MobileModal from '@/components/mobile-modal';
|
||||||
|
import Editor from '@/components/editor';
|
||||||
|
|
||||||
|
const StyledEditorContainer = styled('div')(({ theme }) => {
|
||||||
|
return {
|
||||||
|
height: 'calc(100vh - 60px)',
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const Home: NextPage = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<EditorHeader />
|
||||||
|
<MobileModal />
|
||||||
|
<StyledEditorContainer>
|
||||||
|
<Editor />
|
||||||
|
</StyledEditorContainer>
|
||||||
|
<EdgelessToolbar />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Home;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
const Page = () => {
|
||||||
|
return <div>Hello, there is [pageId]/index</div>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Page;
|
||||||
@@ -1,6 +1,13 @@
|
|||||||
import type { EditorContainer } from '@blocksuite/editor';
|
import type { EditorContainer } from '@blocksuite/editor';
|
||||||
import { createContext, useContext, useEffect, useState } from 'react';
|
import {
|
||||||
|
createContext,
|
||||||
|
useContext,
|
||||||
|
useEffect,
|
||||||
|
useState,
|
||||||
|
useCallback,
|
||||||
|
} from 'react';
|
||||||
import type { PropsWithChildren } from 'react';
|
import type { PropsWithChildren } from 'react';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
import dynamic from 'next/dynamic';
|
import dynamic from 'next/dynamic';
|
||||||
import Loading from './loading';
|
import Loading from './loading';
|
||||||
import { Page, Workspace } from '@blocksuite/store';
|
import { Page, Workspace } from '@blocksuite/store';
|
||||||
@@ -35,8 +42,17 @@ export const useEditor = () => useContext(EditorContext);
|
|||||||
export const EditorProvider = ({
|
export const EditorProvider = ({
|
||||||
children,
|
children,
|
||||||
}: PropsWithChildren<EditorContextProps>) => {
|
}: PropsWithChildren<EditorContextProps>) => {
|
||||||
|
const router = useRouter();
|
||||||
const [workspace, setWorkspace] = useState<Workspace>();
|
const [workspace, setWorkspace] = useState<Workspace>();
|
||||||
const [page, setPage] = useState<Page>();
|
const [page, _setPage] = useState<Page>();
|
||||||
|
const workspaceId = router.query.workspaceId as string;
|
||||||
|
const setPage = useCallback(
|
||||||
|
(page: Page) => {
|
||||||
|
_setPage(page);
|
||||||
|
router.push(`/workspace/${workspaceId}/${page.id.replace('space:', '')}`);
|
||||||
|
},
|
||||||
|
[_setPage, workspaceId]
|
||||||
|
);
|
||||||
const [pageList, setPageList] = useState<PageMeta[]>([]);
|
const [pageList, setPageList] = useState<PageMeta[]>([]);
|
||||||
const [editor, setEditor] = useState<EditorContainer>();
|
const [editor, setEditor] = useState<EditorContainer>();
|
||||||
|
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ import {
|
|||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { createPage } from '@/providers/editor-provider/utils';
|
import { createPage } from '@/providers/editor-provider/utils';
|
||||||
|
|
||||||
const getEditorParams = () => {
|
const getEditorParams = (workspaceId: string) => {
|
||||||
const providers = [];
|
const providers = [];
|
||||||
const params = new URLSearchParams(location.search);
|
const params = new URLSearchParams(location.search);
|
||||||
const room = params.get('room') ?? 'AFFINE-pathfinder';
|
// const room = params.get('room') ?? 'AFFINE-pathfinder';
|
||||||
if (params.get('syncMode') === 'websocket') {
|
if (params.get('syncMode') === 'websocket') {
|
||||||
const WebsocketDocProvider = createWebsocketDocProvider(
|
const WebsocketDocProvider = createWebsocketDocProvider(
|
||||||
'ws://127.0.0.1:3000/collaboration/AFFiNE'
|
`ws://${window.location.host}/collaboration/`
|
||||||
);
|
);
|
||||||
providers.push(WebsocketDocProvider);
|
providers.push(WebsocketDocProvider);
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ const getEditorParams = () => {
|
|||||||
providers.push(IndexedDBDocProvider);
|
providers.push(IndexedDBDocProvider);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
room,
|
room: workspaceId,
|
||||||
providers,
|
providers,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -53,12 +53,12 @@ const EditorReactor = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const shouldInitIntroduction = useRef(false);
|
const shouldInitIntroduction = useRef(false);
|
||||||
const {
|
const {
|
||||||
query: { pageId: routerPageId },
|
query: { pageId: routerPageId, workspaceId },
|
||||||
} = useRouter();
|
} = useRouter();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const workspace = new Workspace({
|
const workspace = new Workspace({
|
||||||
...getEditorParams(),
|
...getEditorParams(workspaceId as string),
|
||||||
}).register(BlockSchema);
|
}).register(BlockSchema);
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
window.workspace = workspace;
|
window.workspace = workspace;
|
||||||
@@ -72,7 +72,7 @@ const EditorReactor = ({
|
|||||||
} else {
|
} else {
|
||||||
setWorkspace(workspace);
|
setWorkspace(workspace);
|
||||||
}
|
}
|
||||||
}, [setWorkspace]);
|
}, [setWorkspace, workspaceId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!workspace) {
|
if (!workspace) {
|
||||||
|
|||||||
Reference in New Issue
Block a user