1.adjust export/import database;
This commit is contained in:
@@ -80,34 +80,20 @@ export const FileSystem = () => {
|
|||||||
|
|
||||||
if (apiSupported && !selected) {
|
if (apiSupported && !selected) {
|
||||||
return (
|
return (
|
||||||
<>
|
<MuiSnackbar
|
||||||
<MuiSnackbar
|
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
|
||||||
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
|
open={error}
|
||||||
open={error}
|
message="Request File Permission failed, please check if you have permission"
|
||||||
message="Request File Permission failed, please check if you have permission"
|
sx={{ marginTop: '3em' }}
|
||||||
sx={{ marginTop: '3em' }}
|
action={
|
||||||
action={
|
<IconButton
|
||||||
<IconButton
|
aria-label="close"
|
||||||
aria-label="close"
|
onClick={() => setError(false)}
|
||||||
onClick={() => setError(false)}
|
>
|
||||||
>
|
<CloseIcon />
|
||||||
<CloseIcon />
|
</IconButton>
|
||||||
</IconButton>
|
}
|
||||||
}
|
/>
|
||||||
/>
|
|
||||||
<StyledFileSystem
|
|
||||||
onClick={async () => {
|
|
||||||
try {
|
|
||||||
await requestPermission('AFFiNE');
|
|
||||||
onSelected();
|
|
||||||
} catch (e) {
|
|
||||||
onError();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t('Sync to Disk')}
|
|
||||||
</StyledFileSystem>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -70,9 +70,6 @@ export const LayoutHeader = () => {
|
|||||||
<EditorBoardSwitcher />
|
<EditorBoardSwitcher />
|
||||||
</StyledContainerForEditorBoardSwitcher>
|
</StyledContainerForEditorBoardSwitcher>
|
||||||
</StyledHeaderRoot>
|
</StyledHeaderRoot>
|
||||||
<StyledUnstableTips>
|
|
||||||
<StyledUnstableTipsText>{warningTips}</StyledUnstableTipsText>
|
|
||||||
</StyledUnstableTips>
|
|
||||||
</StyledContainerForHeaderRoot>
|
</StyledContainerForHeaderRoot>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ 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 booleanExportWorkspace = useFlag('BooleanExportAffineDb', true);
|
||||||
const booleanImportWorkspace = useFlag('BooleanImportWorkspace', false);
|
const booleanImportWorkspace = useFlag('BooleanImportAffineDb', true);
|
||||||
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);
|
||||||
|
|||||||
@@ -145,12 +145,19 @@ 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(workspaceId),
|
||||||
flag: 'booleanImportWorkspace',
|
flag: 'booleanClearWorkspace',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'button',
|
type: 'button',
|
||||||
@@ -159,13 +166,6 @@ export const useSettings = (): SettingItem[] => {
|
|||||||
onClick: () => exportWorkspace(),
|
onClick: () => exportWorkspace(),
|
||||||
flag: 'booleanExportWorkspace',
|
flag: 'booleanExportWorkspace',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
type: 'button',
|
|
||||||
name: t('Clear Workspace'),
|
|
||||||
key: 'Clear Workspace',
|
|
||||||
onClick: () => clearWorkspace(workspaceId),
|
|
||||||
flag: 'booleanClearWorkspace',
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return filterSettings(settings, settingFlags);
|
return filterSettings(settings, settingFlags);
|
||||||
|
|||||||
@@ -6,8 +6,12 @@ export const importWorkspace = (workspaceId: string) => {
|
|||||||
window.client
|
window.client
|
||||||
.inspector()
|
.inspector()
|
||||||
.load()
|
.load()
|
||||||
.then(() => {
|
.then(status => {
|
||||||
window.location.href = `/${workspaceId}/`;
|
if (status) {
|
||||||
|
if (window.confirm('Your currently open data will be lost.')) {
|
||||||
|
window.location.href = `/${workspaceId}/`;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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.get_named_block('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 get_named_block(
|
||||||
name: string,
|
name: string,
|
||||||
options?: { workspace?: boolean }
|
options?: { workspace?: boolean }
|
||||||
): Promise<BaseBlock<B, C>> {
|
): Promise<BaseBlock<B, C>> {
|
||||||
|
|||||||
@@ -324,53 +324,59 @@ 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;
|
||||||
|
}
|
||||||
|
console.log('load success');
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
@@ -74,41 +74,21 @@ const _useUserAndSpacesForFreeLogin = () => {
|
|||||||
if (location.pathname.startsWith('/local')) {
|
if (location.pathname.startsWith('/local')) {
|
||||||
navigate('/local');
|
navigate('/local');
|
||||||
} else {
|
} else {
|
||||||
navigate('/demo');
|
navigate(`/${BRAND_ID}`);
|
||||||
}
|
}
|
||||||
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]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user