mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-02 22:59:56 +08:00
feat: get default head img blob
This commit is contained in:
+34
-15
@@ -25,6 +25,39 @@ export const WorkspaceCreate = ({ open, onClose }: WorkspaceCreateProps) => {
|
|||||||
const handlerInputChange = (workspaceName: string) => {
|
const handlerInputChange = (workspaceName: string) => {
|
||||||
setWorkspaceId(workspaceName);
|
setWorkspaceId(workspaceName);
|
||||||
};
|
};
|
||||||
|
const createDefaultHeadImg = (workspaceName: string) => {
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
canvas.height = 100;
|
||||||
|
canvas.width = 100;
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
if (ctx) {
|
||||||
|
// TODO: add a image list
|
||||||
|
ctx.fillStyle = '#FFDE03';
|
||||||
|
ctx.fillRect(0, 0, 100, 100);
|
||||||
|
ctx.font = "600 50px 'PingFang SC', 'Microsoft Yahei'";
|
||||||
|
ctx.fillStyle = '#FFF';
|
||||||
|
ctx.textAlign = 'center';
|
||||||
|
ctx.textBaseline = 'middle';
|
||||||
|
ctx.fillText(workspaceName[0], 50, 50);
|
||||||
|
const blob = canvas.toBlob(blob => {}, 'image/png');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const handleCreateWorkspace = () => {
|
||||||
|
setCanCreate(true);
|
||||||
|
createDefaultHeadImg(workspaceName);
|
||||||
|
createWorkspace({ name: workspaceName, avatar: '' })
|
||||||
|
.then(data => {
|
||||||
|
// @ts-ignore
|
||||||
|
router.push(`/workspace/${data.created_at}`);
|
||||||
|
onClose();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err, 'err');
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setCanCreate(false);
|
||||||
|
});
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<Modal open={open} onClose={onClose}>
|
<Modal open={open} onClose={onClose}>
|
||||||
<StyledModalWrapper>
|
<StyledModalWrapper>
|
||||||
@@ -44,21 +77,7 @@ export const WorkspaceCreate = ({ open, onClose }: WorkspaceCreateProps) => {
|
|||||||
<StyledButtonContent>
|
<StyledButtonContent>
|
||||||
<StyledButton
|
<StyledButton
|
||||||
disabled={!workspaceName.length || canCreate}
|
disabled={!workspaceName.length || canCreate}
|
||||||
onClick={() => {
|
onClick={handleCreateWorkspace}
|
||||||
setCanCreate(true);
|
|
||||||
createWorkspace({ name: workspaceName, avatar: '' })
|
|
||||||
.then(data => {
|
|
||||||
// @ts-ignore
|
|
||||||
router.push(`/workspace/${data.created_at}`);
|
|
||||||
onClose();
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.log(err, 'err');
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
setCanCreate(false);
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
Create
|
Create
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
|
|||||||
const callback = async (user: AccessTokenMessage | null) => {
|
const callback = async (user: AccessTokenMessage | null) => {
|
||||||
const workspacesMeta = user ? await getWorkspaces() : [];
|
const workspacesMeta = user ? await getWorkspaces() : [];
|
||||||
const workspaces = await Promise.all(
|
const workspaces = await Promise.all(
|
||||||
workspacesMeta.map(async ({ id }) => {
|
workspacesMeta?.map(async ({ id }) => {
|
||||||
const workspace = (await loadWorkspaceHandler?.(id)) || null;
|
const workspace = (await loadWorkspaceHandler?.(id)) || null;
|
||||||
return workspace;
|
return workspace;
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user