mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-09 05:05:52 +08:00
Merge branch 'feat/filesystem_and_search' of github.com:toeverything/AFFiNE into feat/filesystem_and_search
This commit is contained in:
@@ -13,6 +13,7 @@ import { ModalCloseButton } from '@/ui/modal';
|
|||||||
import { Button } from '@/ui/button';
|
import { Button } from '@/ui/button';
|
||||||
import { deleteWorkspace } from '@pathfinder/data-services';
|
import { deleteWorkspace } from '@pathfinder/data-services';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
|
import { useAppState } from '@/providers/app-state-provider';
|
||||||
|
|
||||||
interface WorkspaceDeleteProps {
|
interface WorkspaceDeleteProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@@ -31,6 +32,7 @@ export const WorkspaceDelete = ({
|
|||||||
}: WorkspaceDeleteProps) => {
|
}: WorkspaceDeleteProps) => {
|
||||||
const [deleteStr, setDeleteStr] = useState<string>('');
|
const [deleteStr, setDeleteStr] = useState<string>('');
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { refreshWorkspacesMeta } = useAppState();
|
||||||
|
|
||||||
const handlerInputChange = (workspaceName: string) => {
|
const handlerInputChange = (workspaceName: string) => {
|
||||||
setDeleteStr(workspaceName);
|
setDeleteStr(workspaceName);
|
||||||
@@ -39,6 +41,7 @@ export const WorkspaceDelete = ({
|
|||||||
const handleDelete = async () => {
|
const handleDelete = async () => {
|
||||||
await deleteWorkspace({ id: workspaceId });
|
await deleteWorkspace({ id: workspaceId });
|
||||||
router.push(`/workspace/${nextWorkSpaceId}`);
|
router.push(`/workspace/${nextWorkSpaceId}`);
|
||||||
|
refreshWorkspacesMeta();
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import {
|
|||||||
Workspace,
|
Workspace,
|
||||||
Member,
|
Member,
|
||||||
removeMember,
|
removeMember,
|
||||||
|
updateWorkspace,
|
||||||
} from '@pathfinder/data-services';
|
} from '@pathfinder/data-services';
|
||||||
import { Avatar } from '@mui/material';
|
import { Avatar } from '@mui/material';
|
||||||
import { Menu, MenuItem } from '@/ui/menu';
|
import { Menu, MenuItem } from '@/ui/menu';
|
||||||
@@ -158,7 +159,9 @@ export const WorkspaceSetting = ({
|
|||||||
{activeTab === ActiveTab.members && workspace && (
|
{activeTab === ActiveTab.members && workspace && (
|
||||||
<MembersPage workspace={workspace} />
|
<MembersPage workspace={workspace} />
|
||||||
)}
|
)}
|
||||||
{activeTab === ActiveTab.publish && <PublishPage />}
|
{activeTab === ActiveTab.publish && (
|
||||||
|
<PublishPage workspace={workspace} />
|
||||||
|
)}
|
||||||
</StyledSettingContent>
|
</StyledSettingContent>
|
||||||
</StyledSettingContainer>
|
</StyledSettingContainer>
|
||||||
</Modal>
|
</Modal>
|
||||||
@@ -286,31 +289,69 @@ const MembersPage = ({ workspace }: { workspace: Workspace }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const PublishPage = () => {
|
const PublishPage = ({ workspace }: { workspace: Workspace }) => {
|
||||||
|
const { refreshWorkspacesMeta } = useAppState();
|
||||||
|
const shareUrl = window.location.host + '/workspace/' + workspace.id;
|
||||||
|
const togglePublic = (flag: boolean) => {
|
||||||
|
updateWorkspace({
|
||||||
|
id: workspace.id,
|
||||||
|
public: flag,
|
||||||
|
}).then(data => {
|
||||||
|
refreshWorkspacesMeta();
|
||||||
|
toast('Updated');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const copyUrl = () => {
|
||||||
|
navigator.clipboard.writeText(shareUrl);
|
||||||
|
toast('Copied');
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<StyledPublishContent>
|
<StyledPublishContent>
|
||||||
<StyledPublishExplanation>
|
{workspace.public ? (
|
||||||
After publishing to the web, everyone can view the content of this
|
<StyledPublishExplanation>
|
||||||
workspace through the link.
|
After publishing to the web, everyone can view the content of this
|
||||||
</StyledPublishExplanation>
|
workspace through the link.
|
||||||
<StyledSettingH2 marginTop={48}>Share with link</StyledSettingH2>
|
</StyledPublishExplanation>
|
||||||
<StyledPublishCopyContainer>
|
) : (
|
||||||
<Input
|
<>
|
||||||
width={500}
|
<StyledPublishExplanation>
|
||||||
value={'www.baidu.com/asdsadas/asdsadasd'}
|
The current workspace has been published to the web, everyone can
|
||||||
disabled
|
view the contents of this workspace through the link.
|
||||||
></Input>
|
</StyledPublishExplanation>
|
||||||
<StyledCopyButtonContainer>
|
<StyledSettingH2 marginTop={48}>Share with link</StyledSettingH2>
|
||||||
<Button type="primary" shape="circle">
|
<StyledPublishCopyContainer>
|
||||||
Copy Link
|
<Input width={500} value={shareUrl} disabled={true}></Input>
|
||||||
</Button>
|
<StyledCopyButtonContainer>
|
||||||
</StyledCopyButtonContainer>
|
<Button onClick={copyUrl} type="primary" shape="circle">
|
||||||
</StyledPublishCopyContainer>
|
Copy Link
|
||||||
|
</Button>
|
||||||
|
</StyledCopyButtonContainer>
|
||||||
|
</StyledPublishCopyContainer>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</StyledPublishContent>
|
</StyledPublishContent>
|
||||||
<Button type="primary" shape="circle">
|
{!workspace.public ? (
|
||||||
Publish to web
|
<Button
|
||||||
</Button>
|
onClick={() => {
|
||||||
|
togglePublic(true);
|
||||||
|
}}
|
||||||
|
type="primary"
|
||||||
|
shape="circle"
|
||||||
|
>
|
||||||
|
Publish to web
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
togglePublic(false);
|
||||||
|
}}
|
||||||
|
type="primary"
|
||||||
|
shape="circle"
|
||||||
|
>
|
||||||
|
Stop publishing
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-4
@@ -103,10 +103,8 @@ export const SelectorPopperContent = ({
|
|||||||
workspaces[id] = workspace;
|
workspaces[id] = workspace;
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('workspaces', workspaces);
|
|
||||||
|
|
||||||
setWorkspaces(workspaces);
|
setWorkspaces(workspaces);
|
||||||
}, []);
|
}, [workspacesMeta]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isShow) {
|
if (isShow) {
|
||||||
@@ -144,7 +142,7 @@ export const SelectorPopperContent = ({
|
|||||||
workspaces[workspace.id]?.meta.name ||
|
workspaces[workspace.id]?.meta.name ||
|
||||||
(workspace.type === WorkspaceType.Private
|
(workspace.type === WorkspaceType.Private
|
||||||
? user.name
|
? user.name
|
||||||
: `workspace-${workspace.id}`)
|
: `loading...`) // workspace-${workspace.id}
|
||||||
}
|
}
|
||||||
memberCount={workSpaceDetails[workspace.id]?.memberCount || 1}
|
memberCount={workSpaceDetails[workspace.id]?.memberCount || 1}
|
||||||
/>
|
/>
|
||||||
|
|||||||
+3
@@ -17,6 +17,7 @@ import {
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { ModalCloseButton } from '@/ui/modal';
|
import { ModalCloseButton } from '@/ui/modal';
|
||||||
import router from 'next/router';
|
import router from 'next/router';
|
||||||
|
import { useAppState } from '@/providers/app-state-provider';
|
||||||
|
|
||||||
interface WorkspaceCreateProps {
|
interface WorkspaceCreateProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@@ -34,6 +35,7 @@ const DefaultHeadImgColors = [
|
|||||||
export const WorkspaceCreate = ({ open, onClose }: WorkspaceCreateProps) => {
|
export const WorkspaceCreate = ({ open, onClose }: WorkspaceCreateProps) => {
|
||||||
const [workspaceName, setWorkspaceId] = useState<string>('');
|
const [workspaceName, setWorkspaceId] = useState<string>('');
|
||||||
const [canCreate, setCanCreate] = useState<boolean>(false);
|
const [canCreate, setCanCreate] = useState<boolean>(false);
|
||||||
|
const { refreshWorkspacesMeta } = useAppState();
|
||||||
const handlerInputChange = (workspaceName: string) => {
|
const handlerInputChange = (workspaceName: string) => {
|
||||||
setWorkspaceId(workspaceName);
|
setWorkspaceId(workspaceName);
|
||||||
};
|
};
|
||||||
@@ -74,6 +76,7 @@ export const WorkspaceCreate = ({ open, onClose }: WorkspaceCreateProps) => {
|
|||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
router.push(`/workspace/${data.created_at}`);
|
router.push(`/workspace/${data.created_at}`);
|
||||||
|
refreshWorkspacesMeta();
|
||||||
onClose();
|
onClose();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ const User = ({ name, avatar }: { name: string; avatar?: string }) => {
|
|||||||
export default function DevPage() {
|
export default function DevPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [successInvited, setSuccessInvited] = useState<boolean>(false);
|
const [successInvited, setSuccessInvited] = useState<boolean>(false);
|
||||||
|
const [inviteData, setInviteData] = useState<any>(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
acceptInviting({ invitingCode: router.query.invite_code as string })
|
acceptInviting({ invitingCode: router.query.invite_code as string })
|
||||||
.then(data => {
|
.then(data => {
|
||||||
setSuccessInvited(true);
|
setSuccessInvited(true);
|
||||||
|
setInviteData(data);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log('err: ', err);
|
console.log('err: ', err);
|
||||||
@@ -35,9 +37,13 @@ export default function DevPage() {
|
|||||||
<Invited>
|
<Invited>
|
||||||
<div>
|
<div>
|
||||||
<Empty width={310} height={310}></Empty>
|
<Empty width={310} height={310}></Empty>
|
||||||
|
|
||||||
<Content>
|
<Content>
|
||||||
<User name={'Svaney'}></User> invited you to join
|
<User name={inviteData?.name ? inviteData.name : '-'}></User> invited
|
||||||
<User name={'Dev Space'}></User>
|
you to join
|
||||||
|
<User
|
||||||
|
name={inviteData?.workspaceName ? inviteData.workspaceName : '-'}
|
||||||
|
></User>
|
||||||
{successInvited ? (
|
{successInvited ? (
|
||||||
<Status>
|
<Status>
|
||||||
<svg
|
<svg
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export interface AppStateValue {
|
|||||||
|
|
||||||
editor: EditorContainer | null;
|
editor: EditorContainer | null;
|
||||||
synced: boolean;
|
synced: boolean;
|
||||||
|
refreshWorkspacesMeta: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppStateContext extends AppStateValue {
|
export interface AppStateContext extends AppStateValue {
|
||||||
@@ -55,7 +56,7 @@ export const AppState = createContext<AppStateContext>({
|
|||||||
loadPage: () => Promise.resolve(null),
|
loadPage: () => Promise.resolve(null),
|
||||||
createPage: () => Promise.resolve(null),
|
createPage: () => Promise.resolve(null),
|
||||||
synced: false,
|
synced: false,
|
||||||
// workspaces: {},
|
refreshWorkspacesMeta: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const useAppState = () => {
|
export const useAppState = () => {
|
||||||
|
|||||||
@@ -19,6 +19,13 @@ const DynamicBlocksuite = dynamic(() => import('./dynamic-blocksuite'), {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
|
export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
|
||||||
|
const refreshWorkspacesMeta = useCallback(async () => {
|
||||||
|
const workspacesMeta = await getWorkspaces().catch(() => {
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
setState(state => ({ ...state, workspacesMeta }));
|
||||||
|
}, []);
|
||||||
|
|
||||||
const [state, setState] = useState<AppStateValue>({
|
const [state, setState] = useState<AppStateValue>({
|
||||||
user: null,
|
user: null,
|
||||||
workspacesMeta: [],
|
workspacesMeta: [],
|
||||||
@@ -29,6 +36,7 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
|
|||||||
// Synced is used to ensure that the provider has synced with the server,
|
// Synced is used to ensure that the provider has synced with the server,
|
||||||
// So after Synced set to true, the other state is sure to be set.
|
// So after Synced set to true, the other state is sure to be set.
|
||||||
synced: false,
|
synced: false,
|
||||||
|
refreshWorkspacesMeta,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [loadWorkspaceHandler, _setLoadWorkspaceHandler] =
|
const [loadWorkspaceHandler, _setLoadWorkspaceHandler] =
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { client } from '../request';
|
import { client, bareClient } from '../request';
|
||||||
import { User } from './user';
|
import { User } from './user';
|
||||||
|
|
||||||
export interface GetWorkspaceDetailParams {
|
export interface GetWorkspaceDetailParams {
|
||||||
@@ -142,7 +142,7 @@ export interface AcceptInvitingParams {
|
|||||||
export async function acceptInviting(
|
export async function acceptInviting(
|
||||||
params: AcceptInvitingParams
|
params: AcceptInvitingParams
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await client.post(`/api/invitation/${params.invitingCode}`);
|
await bareClient.post(`/api/invitation/${params.invitingCode}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DownloadWOrkspaceParams {
|
export interface DownloadWOrkspaceParams {
|
||||||
@@ -155,7 +155,7 @@ export async function downloadWorkspace(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function uploadBlob(params: { blob: Blob }): Promise<string> {
|
export async function uploadBlob(params: { blob: Blob }): Promise<string> {
|
||||||
return client.post('/api/blob', { body: params.blob }).text();
|
return client.put('/api/blob', { body: params.blob }).text();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getBlob(params: {
|
export async function getBlob(params: {
|
||||||
|
|||||||
Reference in New Issue
Block a user