From 3472add5d4ada9bcb9f264e7ffb5708adcd85db3 Mon Sep 17 00:00:00 2001 From: Fangdun Tsai Date: Sat, 26 Oct 2024 15:58:12 +0800 Subject: [PATCH] fix: types --- .../windows-manager/tab-views-meta-schema.ts | 2 ++ .../components/attachment-viewer/titlebar.tsx | 19 ++++++++++++------- .../src/components/attachment-viewer/utils.ts | 2 +- .../pages/workspace/attachment/index.tsx | 2 ++ yarn.lock | 4 ++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/frontend/apps/electron/src/main/windows-manager/tab-views-meta-schema.ts b/packages/frontend/apps/electron/src/main/windows-manager/tab-views-meta-schema.ts index 18a77dba12438..4fca530a475cf 100644 --- a/packages/frontend/apps/electron/src/main/windows-manager/tab-views-meta-schema.ts +++ b/packages/frontend/apps/electron/src/main/windows-manager/tab-views-meta-schema.ts @@ -9,6 +9,8 @@ export const workbenchViewIconNameSchema = z.enum([ 'page', 'edgeless', 'journal', + 'attachment', + 'pdf', ]); export const workbenchViewMetaSchema = z.object({ diff --git a/packages/frontend/component/src/components/attachment-viewer/titlebar.tsx b/packages/frontend/component/src/components/attachment-viewer/titlebar.tsx index 9b3817767b0b1..0874a8e10ac8f 100644 --- a/packages/frontend/component/src/components/attachment-viewer/titlebar.tsx +++ b/packages/frontend/component/src/components/attachment-viewer/titlebar.tsx @@ -1,4 +1,4 @@ -import type { AttachmentBlockModel } from '@blocksuite/blocks'; +import type { AttachmentBlockModel } from '@blocksuite/affine/blocks'; import { EditIcon, LocalDataIcon, @@ -12,23 +12,28 @@ import { useState } from 'react'; import { IconButton } from '../../ui/button'; import { Menu, MenuItem } from '../../ui/menu'; import * as styles from './styles.css'; +import { saveBufferToFile } from './utils'; const items = [ { name: 'Rename', icon: , - action() {}, + action(_model: AttachmentBlockModel) {}, }, { name: 'Download', icon: , - action() {}, + action(model: AttachmentBlockModel) { + const { sourceId, name } = model; + if (!sourceId) return; + saveBufferToFile(sourceId, name).catch(console.error); + }, }, ]; -export const MenuItems = () => +export const MenuItems = ({ model }: { model: AttachmentBlockModel }) => items.map(({ name, icon, action }) => ( - + action(model)} prefixIcon={icon}> {name} )); @@ -43,7 +48,7 @@ export interface TitlebarProps { } export const Titlebar = ({ - model: _, + model, name, ext, size, @@ -62,7 +67,7 @@ export const Titlebar = ({
{size}
}> } + items={} rootOptions={{ open: openMenu, onOpenChange: setOpenMenu, diff --git a/packages/frontend/component/src/components/attachment-viewer/utils.ts b/packages/frontend/component/src/components/attachment-viewer/utils.ts index 2e8ae60f6883e..2238b3eb09857 100644 --- a/packages/frontend/component/src/components/attachment-viewer/utils.ts +++ b/packages/frontend/component/src/components/attachment-viewer/utils.ts @@ -1,6 +1,6 @@ import { fileTypeFromBuffer } from 'file-type'; -async function _saveBufferToFile(url: string, filename: string) { +export async function saveBufferToFile(url: string, filename: string) { // given input url may not have correct mime type const blob = await attachmentUrlToBlob(url); if (!blob) { diff --git a/packages/frontend/core/src/desktop/pages/workspace/attachment/index.tsx b/packages/frontend/core/src/desktop/pages/workspace/attachment/index.tsx index 6ba1a9a60922b..4f95a5abca858 100644 --- a/packages/frontend/core/src/desktop/pages/workspace/attachment/index.tsx +++ b/packages/frontend/core/src/desktop/pages/workspace/attachment/index.tsx @@ -47,7 +47,9 @@ const useLoadAttachment = (pageId?: string, attachmentId?: string) => { const disposable = doc.blockSuiteDoc.slots.blockUpdated .filter(({ type, id }) => type === 'add' && id === attachmentId) + // @ts-expect-error allow .filter(({ model }) => matchFlavours(model, ['affine:attachment'])) + // @ts-expect-error allow .once(({ model }) => setModel(model as AttachmentBlockModel)); return () => { diff --git a/yarn.lock b/yarn.lock index 377f86dc9ac82..e90737a1c8757 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2502,7 +2502,7 @@ __metadata: "@blocksuite/affine-shared": "npm:0.0.0-canary-20241028080828" "@blocksuite/block-std": "npm:0.0.0-canary-20241028080828" "@blocksuite/global": "npm:0.0.0-canary-20241028080828" - "@blocksuite/icons": "npm:^2.1.69" + "@blocksuite/icons": "npm:^2.1.68" "@blocksuite/inline": "npm:0.0.0-canary-20241028080828" "@blocksuite/store": "npm:0.0.0-canary-20241028080828" "@floating-ui/dom": "npm:^1.6.10" @@ -2591,7 +2591,7 @@ __metadata: "@blocksuite/affine-shared": "npm:0.0.0-canary-20241028080828" "@blocksuite/block-std": "npm:0.0.0-canary-20241028080828" "@blocksuite/global": "npm:0.0.0-canary-20241028080828" - "@blocksuite/icons": "npm:^2.1.69" + "@blocksuite/icons": "npm:^2.1.68" "@blocksuite/inline": "npm:0.0.0-canary-20241028080828" "@blocksuite/store": "npm:0.0.0-canary-20241028080828" "@floating-ui/dom": "npm:^1.6.10"