mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-19 23:37:15 +08:00
fix: fix image preview modal story (#5879)
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { BlockSuiteEditor } from '@affine/core/components/blocksuite/block-suite-editor';
|
||||
import { ImagePreviewModal } from '@affine/core/components/image-preview';
|
||||
import { CurrentPageService } from '@affine/core/modules/page';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import type { Meta } from '@storybook/react';
|
||||
import { useService, Workspace } from '@toeverything/infra';
|
||||
import { PageManager, useService, Workspace } from '@toeverything/infra';
|
||||
import { initEmptyPage } from '@toeverything/infra/blocksuite';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
@@ -14,27 +15,35 @@ export default {
|
||||
|
||||
export const Default = () => {
|
||||
const workspace = useService(Workspace);
|
||||
const pageManager = useService(PageManager);
|
||||
const currentPageService = useService(CurrentPageService);
|
||||
|
||||
const [page, setPage] = useState<Page | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const page = workspace.blockSuiteWorkspace.createPage('page0');
|
||||
initEmptyPage(page);
|
||||
const bsPage = workspace.blockSuiteWorkspace.createPage('page0');
|
||||
initEmptyPage(bsPage);
|
||||
|
||||
const { page, release } = pageManager.open(bsPage.meta);
|
||||
currentPageService.openPage(page);
|
||||
|
||||
fetch(new URL('@affine-test/fixtures/large-image.png', import.meta.url))
|
||||
.then(res => res.arrayBuffer())
|
||||
.then(async buffer => {
|
||||
const id = await workspace.blockSuiteWorkspace.blob.set(
|
||||
new Blob([buffer], { type: 'image/png' })
|
||||
);
|
||||
const frameId = page.getBlockByFlavour('affine:note')[0].id;
|
||||
page.addBlock(
|
||||
const frameId = bsPage.getBlockByFlavour('affine:note')[0].id;
|
||||
bsPage.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text: new page.Text('Please double click the image to preview it.'),
|
||||
text: new bsPage.Text(
|
||||
'Please double click the image to preview it.'
|
||||
),
|
||||
},
|
||||
frameId
|
||||
);
|
||||
page.addBlock(
|
||||
bsPage.addBlock(
|
||||
'affine:image',
|
||||
{
|
||||
sourceId: id,
|
||||
@@ -45,8 +54,13 @@ export const Default = () => {
|
||||
.catch(err => {
|
||||
console.error('Failed to load large-image.png', err);
|
||||
});
|
||||
setPage(page);
|
||||
}, [workspace]);
|
||||
setPage(bsPage);
|
||||
|
||||
return () => {
|
||||
release();
|
||||
currentPageService.closePage();
|
||||
};
|
||||
}, [currentPageService, pageManager, workspace]);
|
||||
|
||||
if (!page) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user