mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
feat: init affine blob storage (#2045)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||
import type { EditorContainer } from '@blocksuite/editor';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import { Workspace } from '@blocksuite/store';
|
||||
import { createMemoryStorage, Workspace } from '@blocksuite/store';
|
||||
import { expect } from '@storybook/jest';
|
||||
import type { Meta, StoryFn } from '@storybook/react';
|
||||
import { useState } from 'react';
|
||||
@@ -29,8 +29,9 @@ function initPage(page: Page): void {
|
||||
|
||||
const blockSuiteWorkspace = new Workspace({
|
||||
id: 'test',
|
||||
blobOptionsGetter: () => void 0,
|
||||
blobStorages: [createMemoryStorage],
|
||||
});
|
||||
|
||||
blockSuiteWorkspace.register(AffineSchemas).register(__unstableSchemas);
|
||||
const page = blockSuiteWorkspace.createPage('page0');
|
||||
initPage(page);
|
||||
|
||||
@@ -18,19 +18,28 @@ export const Default = () => {
|
||||
{
|
||||
id: '1',
|
||||
flavour: WorkspaceFlavour.LOCAL,
|
||||
blockSuiteWorkspace: createEmptyBlockSuiteWorkspace('1'),
|
||||
blockSuiteWorkspace: createEmptyBlockSuiteWorkspace(
|
||||
'1',
|
||||
WorkspaceFlavour.LOCAL
|
||||
),
|
||||
providers: [],
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
flavour: WorkspaceFlavour.LOCAL,
|
||||
blockSuiteWorkspace: createEmptyBlockSuiteWorkspace('2'),
|
||||
blockSuiteWorkspace: createEmptyBlockSuiteWorkspace(
|
||||
'2',
|
||||
WorkspaceFlavour.LOCAL
|
||||
),
|
||||
providers: [],
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
flavour: WorkspaceFlavour.LOCAL,
|
||||
blockSuiteWorkspace: createEmptyBlockSuiteWorkspace('3'),
|
||||
blockSuiteWorkspace: createEmptyBlockSuiteWorkspace(
|
||||
'3',
|
||||
WorkspaceFlavour.LOCAL
|
||||
),
|
||||
providers: [],
|
||||
},
|
||||
] satisfies WorkspaceListProps['items'];
|
||||
|
||||
@@ -31,7 +31,10 @@ function initPage(page: Page): void {
|
||||
page.resetHistory();
|
||||
}
|
||||
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace('test-workspace');
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(
|
||||
'test-workspace',
|
||||
WorkspaceFlavour.LOCAL
|
||||
);
|
||||
|
||||
initPage(blockSuiteWorkspace.createPage('page0'));
|
||||
initPage(blockSuiteWorkspace.createPage('page1'));
|
||||
|
||||
@@ -21,7 +21,6 @@ export default {
|
||||
|
||||
const basicBlockSuiteWorkspace = new Workspace({
|
||||
id: 'blocksuite-local',
|
||||
blobOptionsGetter: (_: string) => undefined,
|
||||
});
|
||||
|
||||
basicBlockSuiteWorkspace.meta.setName('Hello World');
|
||||
@@ -46,19 +45,17 @@ Basic.args = {
|
||||
|
||||
const avatarBlockSuiteWorkspace = new Workspace({
|
||||
id: 'blocksuite-local',
|
||||
blobOptionsGetter: (_: string) => undefined,
|
||||
});
|
||||
|
||||
avatarBlockSuiteWorkspace.meta.setName('Hello World');
|
||||
avatarBlockSuiteWorkspace.blobs.then(async blobs => {
|
||||
if (blobs) {
|
||||
const buffer = await (
|
||||
await fetch(new URL('@affine-test/fixtures/smile.png', import.meta.url))
|
||||
).arrayBuffer();
|
||||
const id = await blobs.set(new Blob([buffer], { type: 'image/png' }));
|
||||
fetch(new URL('@affine-test/fixtures/smile.png', import.meta.url))
|
||||
.then(res => res.arrayBuffer())
|
||||
.then(async buffer => {
|
||||
const id = await avatarBlockSuiteWorkspace.blobs.set(
|
||||
new Blob([buffer], { type: 'image/png' })
|
||||
);
|
||||
avatarBlockSuiteWorkspace.meta.setAvatar(id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
export const BlobExample: StoryFn<WorkspaceAvatarProps> = props => {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user