mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-29 00:06:09 +08:00
Merge branch 'feat/datacenter' of https://github.com/toeverything/AFFiNE into feat/datacenter
This commit is contained in:
@@ -1,19 +1,22 @@
|
|||||||
import { styled } from '@/styles';
|
import { styled } from '@/styles';
|
||||||
|
|
||||||
// Inspired by https://codepen.io/graphilla/pen/rNvBMYY
|
// Inspired by https://codepen.io/graphilla/pen/rNvBMYY
|
||||||
export const StyledLoadingWrapper = styled.div<{ size?: number }>(
|
export const StyledLoadingWrapper = styled('div', {
|
||||||
({ size = 40 }) => {
|
shouldForwardProp: prop => {
|
||||||
return {
|
return !['size'].includes(prop);
|
||||||
width: size * 4,
|
},
|
||||||
height: size * 4,
|
})<{ size?: number }>(({ size = 40 }) => {
|
||||||
position: 'relative',
|
return {
|
||||||
};
|
width: size * 4,
|
||||||
}
|
height: size * 4,
|
||||||
);
|
position: 'relative',
|
||||||
|
};
|
||||||
|
});
|
||||||
export const StyledLoading = styled.div`
|
export const StyledLoading = styled.div`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 25%;
|
left: 25%;
|
||||||
top: 25%;
|
top: 50%;
|
||||||
|
transform: rotateX(55deg) rotateZ(-45deg);
|
||||||
@keyframes slide {
|
@keyframes slide {
|
||||||
0% {
|
0% {
|
||||||
transform: translate(var(--sx), var(--sy));
|
transform: translate(var(--sx), var(--sy));
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ const FavoriteTag = ({
|
|||||||
style={{
|
style={{
|
||||||
color: favorite ? theme.colors.primaryColor : theme.colors.iconColor,
|
color: favorite ? theme.colors.primaryColor : theme.colors.iconColor,
|
||||||
}}
|
}}
|
||||||
className="favorite-button"
|
className={favorite ? '' : 'favorite-button'}
|
||||||
>
|
>
|
||||||
{favorite ? (
|
{favorite ? (
|
||||||
<FavouritedIcon data-testid="favourited-icon" />
|
<FavouritedIcon data-testid="favourited-icon" />
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
|
|||||||
router.replace(`/workspace/${item.id}`);
|
router.replace(`/workspace/${item.id}`);
|
||||||
onClose();
|
onClose();
|
||||||
}}
|
}}
|
||||||
active={item.id === currentWorkspace.room}
|
active={item.id === currentWorkspace?.room}
|
||||||
key={index}
|
key={index}
|
||||||
>
|
>
|
||||||
<span style={{ width: '100px' }}>
|
<span style={{ width: '100px' }}>
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { useAppState } from '@/providers/app-state-provider';
|
import { useAppState } from '@/providers/app-state-provider';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
const defaultOutLineWorkspaceId = 'affine';
|
|
||||||
// 'local-first-' + '85b4ca0b9081421d903bbc2501ea280f';
|
|
||||||
// It is a fully effective hook
|
// It is a fully effective hook
|
||||||
// Cause it not just ensure workspace loaded, but also have router change.
|
// Cause it not just ensure workspace loaded, but also have router change.
|
||||||
export const useEnsureWorkspace = () => {
|
export const useEnsureWorkspace = () => {
|
||||||
@@ -35,9 +33,8 @@ export const useEnsureWorkspace = () => {
|
|||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const workspaceId = user
|
const workspaceId =
|
||||||
? (router.query.workspaceId as string) || workspaceList[0]?.id
|
(router.query.workspaceId as string) || workspaceList[0]?.id;
|
||||||
: (router.query.workspaceId as string) || defaultOutLineWorkspaceId;
|
|
||||||
|
|
||||||
loadWorkspace(workspaceId).finally(() => {
|
loadWorkspace(workspaceId).finally(() => {
|
||||||
console.log('workspaceId: ', workspaceId);
|
console.log('workspaceId: ', workspaceId);
|
||||||
|
|||||||
@@ -22,35 +22,29 @@ export const AppStateProvider = ({
|
|||||||
const [appState, setAppState] = useState<AppStateValue>({} as AppStateValue);
|
const [appState, setAppState] = useState<AppStateValue>({} as AppStateValue);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const init = async () => {
|
const initState = async () => {
|
||||||
const dataCenter = await getDataCenter();
|
const dataCenter = await getDataCenter();
|
||||||
|
|
||||||
|
// Ensure datacenter has at least one workspace
|
||||||
if (dataCenter.workspaces.length === 0) {
|
if (dataCenter.workspaces.length === 0) {
|
||||||
await createDefaultWorkspace(dataCenter);
|
await createDefaultWorkspace(dataCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentWorkspace = await dataCenter.loadWorkspace(
|
|
||||||
dataCenter.workspaces[0].id
|
|
||||||
);
|
|
||||||
const currentMetaWorkSpace = dataCenter.workspaces.find(item => {
|
|
||||||
return item.id === currentWorkspace.room;
|
|
||||||
});
|
|
||||||
|
|
||||||
setAppState({
|
setAppState({
|
||||||
dataCenter,
|
dataCenter,
|
||||||
user: (await dataCenter.getUserInfo()) || null,
|
user: (await dataCenter.getUserInfo()) || null,
|
||||||
workspaceList: dataCenter.workspaces,
|
workspaceList: dataCenter.workspaces,
|
||||||
currentWorkspaceId: dataCenter.workspaces[0].id,
|
currentWorkspaceId: '',
|
||||||
currentWorkspace,
|
currentWorkspace: null,
|
||||||
pageList: currentWorkspace.meta.pageMetas as PageMeta[],
|
pageList: [],
|
||||||
currentPage: null,
|
currentPage: null,
|
||||||
editor: null,
|
editor: null,
|
||||||
synced: true,
|
synced: true,
|
||||||
currentMetaWorkSpace: currentMetaWorkSpace ?? null,
|
currentMetaWorkSpace: null,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
initState();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -95,6 +89,8 @@ export const AppStateProvider = ({
|
|||||||
|
|
||||||
const loadWorkspace = useRef<AppStateFunction['loadWorkspace']>();
|
const loadWorkspace = useRef<AppStateFunction['loadWorkspace']>();
|
||||||
loadWorkspace.current = async (workspaceId: string) => {
|
loadWorkspace.current = async (workspaceId: string) => {
|
||||||
|
console.log('loadWorkspace');
|
||||||
|
|
||||||
const { dataCenter, workspaceList, currentWorkspaceId, currentWorkspace } =
|
const { dataCenter, workspaceList, currentWorkspaceId, currentWorkspace } =
|
||||||
appState;
|
appState;
|
||||||
if (!workspaceList.find(v => v.id === workspaceId)) {
|
if (!workspaceList.find(v => v.id === workspaceId)) {
|
||||||
@@ -114,7 +110,7 @@ export const AppStateProvider = ({
|
|||||||
currentWorkspace: workspace,
|
currentWorkspace: workspace,
|
||||||
currentWorkspaceId: workspaceId,
|
currentWorkspaceId: workspaceId,
|
||||||
currentMetaWorkSpace: currentMetaWorkSpace ?? null,
|
currentMetaWorkSpace: currentMetaWorkSpace ?? null,
|
||||||
pageList: currentWorkspace.meta.pageMetas as PageMeta[],
|
pageList: currentWorkspace?.meta.pageMetas as PageMeta[],
|
||||||
currentPage: null,
|
currentPage: null,
|
||||||
editor: null,
|
editor: null,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export type AppStateValue = {
|
|||||||
dataCenter: DataCenter;
|
dataCenter: DataCenter;
|
||||||
user: User | null;
|
user: User | null;
|
||||||
workspaceList: WorkspaceInfo[];
|
workspaceList: WorkspaceInfo[];
|
||||||
currentWorkspace: StoreWorkspace;
|
currentWorkspace: StoreWorkspace | null;
|
||||||
currentMetaWorkSpace: WorkspaceInfo | null;
|
currentMetaWorkSpace: WorkspaceInfo | null;
|
||||||
currentWorkspaceId: string;
|
currentWorkspaceId: string;
|
||||||
pageList: PageMeta[];
|
pageList: PageMeta[];
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export const StyledTable = styled.table<{ tableLayout: 'auto' | 'fixed' }>(
|
|||||||
tableLayout,
|
tableLayout,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
borderCollapse: 'separate',
|
borderCollapse: 'separate',
|
||||||
borderSpacing: '0 25px',
|
borderSpacing: '0',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -52,7 +52,6 @@ export const StyledTableHead = styled.thead(() => {
|
|||||||
|
|
||||||
export const StyledTableRow = styled.tr(({ theme }) => {
|
export const StyledTableRow = styled.tr(({ theme }) => {
|
||||||
return {
|
return {
|
||||||
marginBottom: '25px',
|
|
||||||
td: {
|
td: {
|
||||||
transition: 'background .15s',
|
transition: 'background .15s',
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user