Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Oct 26, 2024
1 parent 2193470 commit 8ae1ffb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const workbenchViewIconNameSchema = z.enum([
'page',
'edgeless',
'journal',
'attachment',
'pdf',
]);

export const workbenchViewMetaSchema = z.object({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AttachmentBlockModel } from '@blocksuite/blocks';
import type { AttachmentBlockModel } from '@blocksuite/affine/blocks';
import {
EditIcon,
LocalDataIcon,
Expand All @@ -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: <EditIcon />,
action() {},
action(_model: AttachmentBlockModel) {},
},
{
name: 'Download',
icon: <LocalDataIcon />,
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 }) => (
<MenuItem key={name} onClick={action} prefixIcon={icon}>
<MenuItem key={name} onClick={() => action(model)} prefixIcon={icon}>
{name}
</MenuItem>
));
Expand All @@ -43,7 +48,7 @@ export interface TitlebarProps {
}

export const Titlebar = ({
model: _,
model,
name,
ext,
size,
Expand All @@ -62,7 +67,7 @@ export const Titlebar = ({
<div>{size}</div>
<IconButton icon={<LocalDataIcon />}></IconButton>
<Menu
items={<MenuItems />}
items={<MenuItems model={model} />}
rootOptions={{
open: openMenu,
onOpenChange: setOpenMenu,
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 8ae1ffb

Please sign in to comment.