Merge pull request #360 from toeverything/feature-livedemo-database-dev

Feature livedemo database dev
This commit is contained in:
DarkSky 2022-09-05 17:51:44 +08:00 committed by GitHub
commit 0a79e30c54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 86 additions and 120 deletions

View File

@ -82,7 +82,7 @@ const GroupMenuWrapper = ({
content={
<GroupPanel>
<ViewsMenu />
<AddViewMenu />
{/*<AddViewMenu />*/}
{
// // Closed beta period temporarily
// filterSorterFlag && (

View File

@ -14,7 +14,7 @@ import {
import { useTranslation } from 'react-i18next';
import { EditorBoardSwitcher } from './EditorBoardSwitcher';
import { FileSystem, fsApiSupported } from './FileSystem';
import { fsApiSupported } from './FileSystem';
import { CurrentPageTitle } from './Title';
export const LayoutHeader = () => {
@ -44,7 +44,6 @@ export const LayoutHeader = () => {
</FlexContainer>
<FlexContainer>
<StyledHelper>
<FileSystem />
<StyledShare disabled={true}>{t('Share')}</StyledShare>
<div style={{ margin: '0px 12px' }}>
<IconButton
@ -70,9 +69,6 @@ export const LayoutHeader = () => {
<EditorBoardSwitcher />
</StyledContainerForEditorBoardSwitcher>
</StyledHeaderRoot>
<StyledUnstableTips>
<StyledUnstableTipsText>{warningTips}</StyledUnstableTipsText>
</StyledUnstableTips>
</StyledContainerForHeaderRoot>
);
};

View File

@ -58,8 +58,6 @@ function PageSettingPortal() {
const navigate = useNavigate();
const { user } = useUserAndSpaces();
const BooleanFullWidthChecked = useFlag('BooleanFullWidthChecked', false);
const BooleanExportWorkspace = useFlag('BooleanExportWorkspace', false);
const BooleanImportWorkspace = useFlag('BooleanImportWorkspace', false);
const BooleanExportHtml = useFlag('BooleanExportHtml', false);
const BooleanExportPdf = useFlag('BooleanExportPdf', false);
const BooleanExportMarkdown = useFlag('BooleanExportMarkdown', false);
@ -217,18 +215,14 @@ function PageSettingPortal() {
/>
)}
<Divider />
{BooleanImportWorkspace && (
<ListButton
content="Import Workspace"
onClick={handleImportWorkspace}
/>
)}
{BooleanExportWorkspace && (
<ListButton
content="Export Workspace"
onClick={handleExportWorkspace}
/>
)}
<p className="textDescription">
Last edited by {user && user.nickname}

View File

@ -2,8 +2,6 @@ import { useFlag } from '@toeverything/datasource/feature-flags';
export const useSettingFlags = () => {
const booleanFullWidthChecked = useFlag('BooleanFullWidthChecked', false);
const booleanExportWorkspace = useFlag('BooleanExportWorkspace', false);
const booleanImportWorkspace = useFlag('BooleanImportWorkspace', false);
const booleanExportHtml = useFlag('BooleanExportHtml', false);
const booleanExportPdf = useFlag('BooleanExportPdf', false);
const booleanExportMarkdown = useFlag('BooleanExportMarkdown', false);
@ -11,8 +9,6 @@ export const useSettingFlags = () => {
return {
booleanFullWidthChecked,
booleanExportWorkspace,
booleanImportWorkspace,
booleanExportHtml,
booleanExportPdf,
booleanExportMarkdown,

View File

@ -145,26 +145,24 @@ export const useSettings = (): SettingItem[] => {
type: 'separator',
key: 'separator2',
},
{
type: 'button',
name: t('Clear Workspace'),
key: 'Clear Workspace',
onClick: () => clearWorkspace(workspaceId),
flag: 'booleanClearWorkspace',
},
{
type: 'button',
name: t('Import Workspace'),
key: 'Import Workspace',
onClick: () => importWorkspace(workspaceId),
flag: 'booleanImportWorkspace',
onClick: () => importWorkspace(),
},
{
type: 'button',
name: t('Export Workspace'),
key: 'Export Workspace',
onClick: () => exportWorkspace(),
flag: 'booleanExportWorkspace',
},
{
type: 'button',
name: t('Clear Workspace'),
key: 'Clear Workspace',
onClick: () => clearWorkspace(workspaceId),
flag: 'booleanClearWorkspace',
},
];

View File

@ -1,14 +1,15 @@
/**
* @deprecated debugging method, deprecated
*/
export const importWorkspace = (workspaceId: string) => {
export const importWorkspace = async () => {
if (window.confirm('Your currently open data will be lost.')) {
//@ts-ignore
window.client
.inspector()
.load()
.then(() => {
window.location.href = `/${workspaceId}/`;
});
const status = await window.client.inspector().load();
if (status) {
window.location.reload();
}
}
};
/**

View File

@ -39,7 +39,7 @@ async function _getCurrentToken() {
const _enabled = {
demo: [],
AFFiNE: ['sqlite'],
AFFiNE: ['idb'],
} as any;
async function _getBlockDatabase(

View File

@ -36,7 +36,7 @@ export class UserConfig extends ServiceBaseClass {
}
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.addRecentPage(workspace, userId, newPage.id);

View File

@ -357,7 +357,7 @@ export class BlockClient<
* @param name block name
* @returns block instance
*/
private async get_named_block(
public async getNamedBlock(
name: string,
options?: { workspace?: boolean }
): Promise<BaseBlock<B, C>> {
@ -376,7 +376,7 @@ export class BlockClient<
*/
public async getWorkspace() {
if (!this._root.node) {
this._root.node = await this.get_named_block(this._workspace, {
this._root.node = await this.getNamedBlock(this._workspace, {
workspace: true,
});
}

View File

@ -324,17 +324,18 @@ export class YjsAdapter implements AsyncDatabaseAdapter<YjsContentOperation> {
const binary = encodeStateAsUpdate(this._doc);
saveAs(
new Blob([binary]),
`affine_workspace_${new Date().toDateString()}.apk`
`affine_workspace_${new Date().toDateString()}.affine`
);
},
load: async () => {
try {
const handles = await window.showOpenFilePicker({
types: [
{
description: 'AFFiNE Package',
accept: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'application/affine': ['.apk'],
'application/affine': ['.affine'],
},
},
],
@ -370,7 +371,11 @@ export class YjsAdapter implements AsyncDatabaseAdapter<YjsContentOperation> {
applyUpdate(doc, new Uint8Array(binary));
await update_check;
}
console.log('load success');
return true;
} catch (err) {
return false;
}
},
parse: () => this._doc.toJSON(),
// eslint-disable-next-line @typescript-eslint/naming-convention

View File

@ -71,17 +71,12 @@ const _useUserAndSpacesForFreeLogin = () => {
useEffect(() => {
if (loading) {
if (location.pathname.startsWith('/local')) {
navigate('/local');
} else {
navigate('/demo');
}
navigate(`/${BRAND_ID}`);
setLoading(false);
}
}, []);
useEffect(() => {
if (localTrigger) {
setUser({
photo: '',
id: BRAND_ID,
@ -89,26 +84,7 @@ const _useUserAndSpacesForFreeLogin = () => {
nickname: BRAND_ID,
email: '',
});
} 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]);
}, [setUser]);
const currentSpaceId: string | undefined = useMemo(() => user?.id, [user]);