mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-23 07:51:45 +03:00
Merge pull request #360 from toeverything/feature-livedemo-database-dev
Feature livedemo database dev
This commit is contained in:
commit
0a79e30c54
@ -82,7 +82,7 @@ const GroupMenuWrapper = ({
|
|||||||
content={
|
content={
|
||||||
<GroupPanel>
|
<GroupPanel>
|
||||||
<ViewsMenu />
|
<ViewsMenu />
|
||||||
<AddViewMenu />
|
{/*<AddViewMenu />*/}
|
||||||
{
|
{
|
||||||
// // Closed beta period temporarily
|
// // Closed beta period temporarily
|
||||||
// filterSorterFlag && (
|
// filterSorterFlag && (
|
||||||
|
@ -14,7 +14,7 @@ import {
|
|||||||
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { EditorBoardSwitcher } from './EditorBoardSwitcher';
|
import { EditorBoardSwitcher } from './EditorBoardSwitcher';
|
||||||
import { FileSystem, fsApiSupported } from './FileSystem';
|
import { fsApiSupported } from './FileSystem';
|
||||||
import { CurrentPageTitle } from './Title';
|
import { CurrentPageTitle } from './Title';
|
||||||
|
|
||||||
export const LayoutHeader = () => {
|
export const LayoutHeader = () => {
|
||||||
@ -44,7 +44,6 @@ export const LayoutHeader = () => {
|
|||||||
</FlexContainer>
|
</FlexContainer>
|
||||||
<FlexContainer>
|
<FlexContainer>
|
||||||
<StyledHelper>
|
<StyledHelper>
|
||||||
<FileSystem />
|
|
||||||
<StyledShare disabled={true}>{t('Share')}</StyledShare>
|
<StyledShare disabled={true}>{t('Share')}</StyledShare>
|
||||||
<div style={{ margin: '0px 12px' }}>
|
<div style={{ margin: '0px 12px' }}>
|
||||||
<IconButton
|
<IconButton
|
||||||
@ -70,9 +69,6 @@ export const LayoutHeader = () => {
|
|||||||
<EditorBoardSwitcher />
|
<EditorBoardSwitcher />
|
||||||
</StyledContainerForEditorBoardSwitcher>
|
</StyledContainerForEditorBoardSwitcher>
|
||||||
</StyledHeaderRoot>
|
</StyledHeaderRoot>
|
||||||
<StyledUnstableTips>
|
|
||||||
<StyledUnstableTipsText>{warningTips}</StyledUnstableTipsText>
|
|
||||||
</StyledUnstableTips>
|
|
||||||
</StyledContainerForHeaderRoot>
|
</StyledContainerForHeaderRoot>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -58,8 +58,6 @@ function PageSettingPortal() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { user } = useUserAndSpaces();
|
const { user } = useUserAndSpaces();
|
||||||
const BooleanFullWidthChecked = useFlag('BooleanFullWidthChecked', false);
|
const BooleanFullWidthChecked = useFlag('BooleanFullWidthChecked', false);
|
||||||
const BooleanExportWorkspace = useFlag('BooleanExportWorkspace', false);
|
|
||||||
const BooleanImportWorkspace = useFlag('BooleanImportWorkspace', false);
|
|
||||||
const BooleanExportHtml = useFlag('BooleanExportHtml', false);
|
const BooleanExportHtml = useFlag('BooleanExportHtml', false);
|
||||||
const BooleanExportPdf = useFlag('BooleanExportPdf', false);
|
const BooleanExportPdf = useFlag('BooleanExportPdf', false);
|
||||||
const BooleanExportMarkdown = useFlag('BooleanExportMarkdown', false);
|
const BooleanExportMarkdown = useFlag('BooleanExportMarkdown', false);
|
||||||
@ -217,18 +215,14 @@ function PageSettingPortal() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<Divider />
|
<Divider />
|
||||||
{BooleanImportWorkspace && (
|
<ListButton
|
||||||
<ListButton
|
content="Import Workspace"
|
||||||
content="Import Workspace"
|
onClick={handleImportWorkspace}
|
||||||
onClick={handleImportWorkspace}
|
/>
|
||||||
/>
|
<ListButton
|
||||||
)}
|
content="Export Workspace"
|
||||||
{BooleanExportWorkspace && (
|
onClick={handleExportWorkspace}
|
||||||
<ListButton
|
/>
|
||||||
content="Export Workspace"
|
|
||||||
onClick={handleExportWorkspace}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<p className="textDescription">
|
<p className="textDescription">
|
||||||
Last edited by {user && user.nickname}
|
Last edited by {user && user.nickname}
|
||||||
|
@ -2,8 +2,6 @@ import { useFlag } from '@toeverything/datasource/feature-flags';
|
|||||||
|
|
||||||
export const useSettingFlags = () => {
|
export const useSettingFlags = () => {
|
||||||
const booleanFullWidthChecked = useFlag('BooleanFullWidthChecked', false);
|
const booleanFullWidthChecked = useFlag('BooleanFullWidthChecked', false);
|
||||||
const booleanExportWorkspace = useFlag('BooleanExportWorkspace', false);
|
|
||||||
const booleanImportWorkspace = useFlag('BooleanImportWorkspace', false);
|
|
||||||
const booleanExportHtml = useFlag('BooleanExportHtml', false);
|
const booleanExportHtml = useFlag('BooleanExportHtml', false);
|
||||||
const booleanExportPdf = useFlag('BooleanExportPdf', false);
|
const booleanExportPdf = useFlag('BooleanExportPdf', false);
|
||||||
const booleanExportMarkdown = useFlag('BooleanExportMarkdown', false);
|
const booleanExportMarkdown = useFlag('BooleanExportMarkdown', false);
|
||||||
@ -11,8 +9,6 @@ export const useSettingFlags = () => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
booleanFullWidthChecked,
|
booleanFullWidthChecked,
|
||||||
booleanExportWorkspace,
|
|
||||||
booleanImportWorkspace,
|
|
||||||
booleanExportHtml,
|
booleanExportHtml,
|
||||||
booleanExportPdf,
|
booleanExportPdf,
|
||||||
booleanExportMarkdown,
|
booleanExportMarkdown,
|
||||||
|
@ -145,26 +145,24 @@ export const useSettings = (): SettingItem[] => {
|
|||||||
type: 'separator',
|
type: 'separator',
|
||||||
key: 'separator2',
|
key: 'separator2',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
name: t('Clear Workspace'),
|
||||||
|
key: 'Clear Workspace',
|
||||||
|
onClick: () => clearWorkspace(workspaceId),
|
||||||
|
flag: 'booleanClearWorkspace',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: 'button',
|
type: 'button',
|
||||||
name: t('Import Workspace'),
|
name: t('Import Workspace'),
|
||||||
key: 'Import Workspace',
|
key: 'Import Workspace',
|
||||||
onClick: () => importWorkspace(workspaceId),
|
onClick: () => importWorkspace(),
|
||||||
flag: 'booleanImportWorkspace',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'button',
|
type: 'button',
|
||||||
name: t('Export Workspace'),
|
name: t('Export Workspace'),
|
||||||
key: 'Export Workspace',
|
key: 'Export Workspace',
|
||||||
onClick: () => exportWorkspace(),
|
onClick: () => exportWorkspace(),
|
||||||
flag: 'booleanExportWorkspace',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'button',
|
|
||||||
name: t('Clear Workspace'),
|
|
||||||
key: 'Clear Workspace',
|
|
||||||
onClick: () => clearWorkspace(workspaceId),
|
|
||||||
flag: 'booleanClearWorkspace',
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* @deprecated debugging method, deprecated
|
* @deprecated debugging method, deprecated
|
||||||
*/
|
*/
|
||||||
export const importWorkspace = (workspaceId: string) => {
|
export const importWorkspace = async () => {
|
||||||
//@ts-ignore
|
if (window.confirm('Your currently open data will be lost.')) {
|
||||||
window.client
|
//@ts-ignore
|
||||||
.inspector()
|
const status = await window.client.inspector().load();
|
||||||
.load()
|
|
||||||
.then(() => {
|
if (status) {
|
||||||
window.location.href = `/${workspaceId}/`;
|
window.location.reload();
|
||||||
});
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,7 +39,7 @@ async function _getCurrentToken() {
|
|||||||
|
|
||||||
const _enabled = {
|
const _enabled = {
|
||||||
demo: [],
|
demo: [],
|
||||||
AFFiNE: ['sqlite'],
|
AFFiNE: ['idb'],
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
async function _getBlockDatabase(
|
async function _getBlockDatabase(
|
||||||
|
@ -36,7 +36,7 @@ export class UserConfig extends ServiceBaseClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const db = await this.database.getDatabase(workspace);
|
const db = await this.database.getDatabase(workspace);
|
||||||
const newPage = await db.get('page');
|
const newPage = await db.getNamedBlock('start-page');
|
||||||
|
|
||||||
await this.get_dependency(PageTree).addPage(workspace, newPage.id);
|
await this.get_dependency(PageTree).addPage(workspace, newPage.id);
|
||||||
await this.addRecentPage(workspace, userId, newPage.id);
|
await this.addRecentPage(workspace, userId, newPage.id);
|
||||||
|
@ -357,7 +357,7 @@ export class BlockClient<
|
|||||||
* @param name block name
|
* @param name block name
|
||||||
* @returns block instance
|
* @returns block instance
|
||||||
*/
|
*/
|
||||||
private async get_named_block(
|
public async getNamedBlock(
|
||||||
name: string,
|
name: string,
|
||||||
options?: { workspace?: boolean }
|
options?: { workspace?: boolean }
|
||||||
): Promise<BaseBlock<B, C>> {
|
): Promise<BaseBlock<B, C>> {
|
||||||
@ -376,7 +376,7 @@ export class BlockClient<
|
|||||||
*/
|
*/
|
||||||
public async getWorkspace() {
|
public async getWorkspace() {
|
||||||
if (!this._root.node) {
|
if (!this._root.node) {
|
||||||
this._root.node = await this.get_named_block(this._workspace, {
|
this._root.node = await this.getNamedBlock(this._workspace, {
|
||||||
workspace: true,
|
workspace: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -324,53 +324,58 @@ export class YjsAdapter implements AsyncDatabaseAdapter<YjsContentOperation> {
|
|||||||
const binary = encodeStateAsUpdate(this._doc);
|
const binary = encodeStateAsUpdate(this._doc);
|
||||||
saveAs(
|
saveAs(
|
||||||
new Blob([binary]),
|
new Blob([binary]),
|
||||||
`affine_workspace_${new Date().toDateString()}.apk`
|
`affine_workspace_${new Date().toDateString()}.affine`
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
load: async () => {
|
load: async () => {
|
||||||
const handles = await window.showOpenFilePicker({
|
try {
|
||||||
types: [
|
const handles = await window.showOpenFilePicker({
|
||||||
{
|
types: [
|
||||||
description: 'AFFiNE Package',
|
{
|
||||||
accept: {
|
description: 'AFFiNE Package',
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
accept: {
|
||||||
'application/affine': ['.apk'],
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
|
'application/affine': ['.affine'],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
],
|
||||||
],
|
});
|
||||||
});
|
const [file] = (await fromEvent(handles)) as File[];
|
||||||
const [file] = (await fromEvent(handles)) as File[];
|
const binary = await file?.arrayBuffer();
|
||||||
const binary = await file?.arrayBuffer();
|
// await this._provider.idb.clearData();
|
||||||
// await this._provider.idb.clearData();
|
const doc = new Doc({ autoLoad: true, shouldLoad: true });
|
||||||
const doc = new Doc({ autoLoad: true, shouldLoad: true });
|
let updated = 0;
|
||||||
let updated = 0;
|
let isUpdated = false;
|
||||||
let isUpdated = false;
|
doc.on('update', () => {
|
||||||
doc.on('update', () => {
|
isUpdated = true;
|
||||||
isUpdated = true;
|
updated += 1;
|
||||||
updated += 1;
|
});
|
||||||
});
|
setInterval(() => {
|
||||||
setInterval(() => {
|
if (updated > 0) {
|
||||||
if (updated > 0) {
|
updated -= 1;
|
||||||
updated -= 1;
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
const update_check = new Promise<void>(resolve => {
|
|
||||||
const check = async () => {
|
|
||||||
while (!isUpdated || updated > 0) {
|
|
||||||
await sleep();
|
|
||||||
}
|
}
|
||||||
resolve();
|
}, 500);
|
||||||
};
|
|
||||||
check();
|
const update_check = new Promise<void>(resolve => {
|
||||||
});
|
const check = async () => {
|
||||||
// await new IndexedDBProvider(this._provider.idb.name, doc)
|
while (!isUpdated || updated > 0) {
|
||||||
// .whenSynced;
|
await sleep();
|
||||||
if (binary) {
|
}
|
||||||
applyUpdate(doc, new Uint8Array(binary));
|
resolve();
|
||||||
await update_check;
|
};
|
||||||
|
check();
|
||||||
|
});
|
||||||
|
// await new IndexedDBProvider(this._provider.idb.name, doc)
|
||||||
|
// .whenSynced;
|
||||||
|
if (binary) {
|
||||||
|
applyUpdate(doc, new Uint8Array(binary));
|
||||||
|
await update_check;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
console.log('load success');
|
|
||||||
},
|
},
|
||||||
parse: () => this._doc.toJSON(),
|
parse: () => this._doc.toJSON(),
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
|
@ -71,44 +71,20 @@ const _useUserAndSpacesForFreeLogin = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (loading) {
|
if (loading) {
|
||||||
if (location.pathname.startsWith('/local')) {
|
navigate(`/${BRAND_ID}`);
|
||||||
navigate('/local');
|
|
||||||
} else {
|
|
||||||
navigate('/demo');
|
|
||||||
}
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (localTrigger) {
|
setUser({
|
||||||
setUser({
|
photo: '',
|
||||||
photo: '',
|
id: BRAND_ID,
|
||||||
id: BRAND_ID,
|
username: BRAND_ID,
|
||||||
username: BRAND_ID,
|
nickname: BRAND_ID,
|
||||||
nickname: BRAND_ID,
|
email: '',
|
||||||
email: '',
|
});
|
||||||
});
|
}, [setUser]);
|
||||||
} else {
|
|
||||||
if (location.pathname.startsWith('/local')) {
|
|
||||||
setUser({
|
|
||||||
photo: '',
|
|
||||||
id: 'local',
|
|
||||||
username: 'local',
|
|
||||||
nickname: 'local',
|
|
||||||
email: '',
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
setUser({
|
|
||||||
photo: '',
|
|
||||||
id: 'demo',
|
|
||||||
username: 'demo',
|
|
||||||
nickname: 'demo',
|
|
||||||
email: '',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [localTrigger, location, setLoading, setUser]);
|
|
||||||
|
|
||||||
const currentSpaceId: string | undefined = useMemo(() => user?.id, [user]);
|
const currentSpaceId: string | undefined = useMemo(() => user?.id, [user]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user