Skip to content

Commit

Permalink
feat: remove default drives info from connect + add default drives to…
Browse files Browse the repository at this point in the history
… reactor config
  • Loading branch information
gpuente committed Sep 3, 2024
1 parent c145848 commit 3545f17
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 204 deletions.
274 changes: 238 additions & 36 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"@sentry/vite-plugin": "^2.22.2",
"@tanstack/react-virtual": "^3.8.1",
"did-key-creator": "^1.2.0",
"document-drive": "^1.0.0-alpha.88",
"document-drive": "1.0.0-alpha.89",
"document-model": "1.7.0",
"document-model-libs": "^1.83.0",
"electron-is-dev": "^3.0.1",
Expand Down
2 changes: 2 additions & 0 deletions src/app/document-drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { IpcMain, webContents } from 'electron';
import { join } from 'path';
import { logger } from 'src/services/logger';
import { getReactorDefaultDrivesConfig } from 'src/utils/reactor';

export default (
documentModels: DocumentModel[],
Expand All @@ -28,6 +29,7 @@ export default (
new FilesystemStorage(join(path, 'Document Drives')),
new InMemoryCache(),
new BaseQueueManager(1, 10),
{ ...getReactorDefaultDrivesConfig() },
);

const promise = documentDrive
Expand Down
11 changes: 0 additions & 11 deletions src/components/modal/modals/SettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,6 @@ export const SettingsModal: React.FC<SettingsModalProps> = props => {
onContinue: () => {
clearStorage()
.then(() => {
// resets the default drive to unloaded if it is defined
setConfig(conf => ({
...conf,
defaultDrives: conf.defaultDrives
? conf.defaultDrives.map(drive => ({
...drive,
loaded: false,
}))
: undefined,
}));

// refreshes the page to reload default drive
onRefresh();
})
Expand Down
11 changes: 0 additions & 11 deletions src/hooks/useFeatureFlags/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,16 @@ const ENABLED_EDITORS = import.meta.env.VITE_ENABLED_EDITORS || undefined;
const enabledEditors = ENABLED_EDITORS?.split(',');

const DISABLED_EDITORS = import.meta.env.VITE_DISABLED_EDITORS || undefined;
const DEFAULT_DRIVES_URL = import.meta.env.VITE_DEFAULT_DRIVES_URL || undefined;
const disabledEditors = DISABLED_EDITORS?.split(',');

export interface FeatureFlag {
defaultDrives?: {
url: string;
loaded: boolean;
}[];
editors: {
enabledEditors?: '*' | string[];
disabledEditors?: '*' | string[];
};
}

const defaultConfig: FeatureFlag = {
defaultDrives: DEFAULT_DRIVES_URL
? DEFAULT_DRIVES_URL.split(',').map(url => ({
url,
loaded: false,
}))
: undefined,
editors: {
enabledEditors: ENABLED_EDITORS === '*' ? '*' : enabledEditors,
disabledEditors: DISABLED_EDITORS === '*' ? '*' : disabledEditors,
Expand Down
139 changes: 0 additions & 139 deletions src/hooks/useLoadDefaultDrives.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/hooks/useLoadInitialData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { useUiNodes } from 'src/hooks/useUiNodes';
import { DefaultDocumentDriveServer as server } from 'src/utils/document-drive-server';
import { useClientErrorHandler } from './useClientErrorHandler';
import { useDocumentDrives } from './useDocumentDrives';
import { useLoadDefaultDrives } from './useLoadDefaultDrives';
import { isLatestVersion } from './utils';

export const useLoadInitialData = () => {
Expand All @@ -32,8 +31,6 @@ export const useLoadInitialData = () => {
const [, , serverSubscribeUpdates] = useDocumentDrives(server);
const clientErrorHandler = useClientErrorHandler();

useLoadDefaultDrives();

async function checkLatestVersion() {
const result = await isLatestVersion();
if (result === null) return;
Expand Down
17 changes: 14 additions & 3 deletions src/hooks/useUiNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ export function useUiNodes() {
) as SharingType;
const driveSyncStatus = await getSyncStatus(id, sharingType);

const normalizedDriveSyncStatus =
driveSyncStatus === 'INITIAL_SYNC'
? 'SYNCING'
: driveSyncStatus;

const driveNode: UiDriveNode = {
id,
name,
Expand All @@ -92,7 +97,7 @@ export function useUiNodes() {
children: [],
nodeMap: {},
sharingType,
syncStatus: driveSyncStatus,
syncStatus: normalizedDriveSyncStatus,
availableOffline,
icon,
parentFolder: null,
Expand All @@ -106,7 +111,7 @@ export function useUiNodes() {
driveId: id,
parentFolder: n.parentFolder || id,
kind: n.kind.toUpperCase(),
syncStatus: driveSyncStatus,
syncStatus: normalizedDriveSyncStatus,
sharingType,
};

Expand All @@ -130,10 +135,16 @@ export function useUiNodes() {

for await (const node of nodes) {
if (node.kind === FILE) {
node.syncStatus = await getSyncStatus(
const fileSyncStatus = await getSyncStatus(
node.synchronizationUnits[0].syncId,
sharingType,
);
const normalizedFileSyncStatus =
fileSyncStatus === 'INITIAL_SYNC'
? 'SYNCING'
: fileSyncStatus;

node.syncStatus = normalizedFileSyncStatus;
}

if (node.parentFolder === id) {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/browser-document-drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { BrowserStorage } from 'document-drive/storage/browser';
import { utils } from 'document-model/document';
import { logger } from 'src/services/logger';
import { documentModels } from 'src/store/document-model';
import { getReactorDefaultDrivesConfig } from './reactor';

export const BrowserDocumentDriveServer = new DocumentDriveServer(
documentModels,
new BrowserStorage(connectConfig.routerBasename),
new InMemoryCache(),
new BaseQueueManager(1, 10),
{ ...getReactorDefaultDrivesConfig() },
);

async function init() {
Expand Down
47 changes: 47 additions & 0 deletions src/utils/reactor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { DocumentDriveServerOptions } from 'document-drive/server';

const DEFAULT_DRIVES_URL = import.meta.env.VITE_DEFAULT_DRIVES_URL || undefined;
const defaultDrivesUrl = DEFAULT_DRIVES_URL?.split(',');

export const getReactorDefaultDrivesConfig = (): Pick<
DocumentDriveServerOptions,
'defaultRemoteDrives' | 'removeOldRemoteDrives'
> => {
const defaultDrives: DocumentDriveServerOptions['defaultRemoteDrives'] =
defaultDrivesUrl?.map(driveUrl => ({
url: driveUrl,
options: {
sharingType: 'PUBLIC',
availableOffline: true,
listeners: [
{
block: true,
callInfo: {
data: driveUrl,
name: 'switchboard-push',
transmitterType: 'SwitchboardPush',
},
filter: {
branch: ['main'],
documentId: ['*'],
documentType: ['*'],
scope: ['global'],
},
label: 'Switchboard Sync',
listenerId: '1',
system: true,
},
],
triggers: [],
pullInterval: 3000,
},
}));

return {
defaultRemoteDrives: defaultDrives,
removeOldRemoteDrives: {
strategy: 'preserve-by-url',
urls: defaultDrivesUrl || [],
},
};
};

0 comments on commit 3545f17

Please sign in to comment.