From 6c1d599387500107c117e032b696a3232009bf58 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 ++ 4 files changed, 17 insertions(+), 8 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 () => {