mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 15:25:59 +00:00
refactor - handle cloud listeners
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
import { handleAuthOnStartup } from './clientAuth';
|
||||
import { initializeAppUpdates } from './utility/appUpdate';
|
||||
import { _t } from './translations';
|
||||
import { installCloudListeners } from './utility/cloudListeners';
|
||||
|
||||
export let isAdminPage = false;
|
||||
|
||||
@@ -58,6 +59,7 @@
|
||||
installNewVolatileConnectionListener();
|
||||
installNewCloudTokenListener();
|
||||
initializeAppUpdates();
|
||||
installCloudListeners();
|
||||
}
|
||||
|
||||
refreshPublicCloudFiles();
|
||||
|
||||
@@ -457,4 +457,10 @@ focusedTreeDbKey.subscribe(value => {
|
||||
});
|
||||
export const getFocusedTreeDbKey = () => focusedTreeDbKeyValue;
|
||||
|
||||
let cloudConnectionsStoreValue = {};
|
||||
cloudConnectionsStore.subscribe(value => {
|
||||
cloudConnectionsStoreValue = value;
|
||||
});
|
||||
export const getCloudConnectionsStore = () => cloudConnectionsStoreValue;
|
||||
|
||||
window['__changeCurrentTheme'] = theme => currentTheme.set(theme);
|
||||
|
||||
48
packages/web/src/utility/cloudListeners.ts
Normal file
48
packages/web/src/utility/cloudListeners.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { derived } from 'svelte/store';
|
||||
import {
|
||||
cloudConnectionsStore,
|
||||
currentDatabase,
|
||||
getCloudConnectionsStore,
|
||||
openedConnections,
|
||||
openedSingleDatabaseConnections,
|
||||
} from '../stores';
|
||||
import { apiCall, apiOn } from './api';
|
||||
import _ from 'lodash';
|
||||
|
||||
export const possibleCloudConnectionSources = derived(
|
||||
[currentDatabase, openedSingleDatabaseConnections, openedConnections],
|
||||
([$currentDatabase, $openedSingleDatabaseConnections, $openedConnections]) => {
|
||||
const conids = new Set<string>();
|
||||
if ($currentDatabase?.connection?._id) {
|
||||
conids.add($currentDatabase.connection._id);
|
||||
}
|
||||
$openedSingleDatabaseConnections.forEach(x => conids.add(x));
|
||||
$openedConnections.forEach(x => conids.add(x));
|
||||
return Array.from(conids).filter(x => x?.startsWith('cloud://'));
|
||||
}
|
||||
);
|
||||
|
||||
async function loadCloudConnection(conid) {
|
||||
const conn = await apiCall('connections/get', { conid });
|
||||
cloudConnectionsStore.update(store => ({
|
||||
...store,
|
||||
[conid]: conn,
|
||||
}));
|
||||
}
|
||||
|
||||
function ensureCloudConnectionsLoaded(...conids) {
|
||||
const conns = getCloudConnectionsStore();
|
||||
_.uniq(conids).forEach(conid => {
|
||||
if (!conns[conid]) {
|
||||
loadCloudConnection(conid);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function installCloudListeners() {
|
||||
possibleCloudConnectionSources.subscribe(conids => {
|
||||
ensureCloudConnectionsLoaded(...conids);
|
||||
});
|
||||
|
||||
apiOn('cloud-content-updated', () => cloudConnectionsStore.set({}));
|
||||
}
|
||||
@@ -67,27 +67,27 @@
|
||||
await apiCall('cloud/refresh-content');
|
||||
}
|
||||
|
||||
async function loadCloudConnection(conid) {
|
||||
const conn = await apiCall('connections/get', { conid });
|
||||
$cloudConnectionsStore = {
|
||||
...$cloudConnectionsStore,
|
||||
[conid]: conn,
|
||||
};
|
||||
}
|
||||
// async function loadCloudConnection(conid) {
|
||||
// const conn = await apiCall('connections/get', { conid });
|
||||
// $cloudConnectionsStore = {
|
||||
// ...$cloudConnectionsStore,
|
||||
// [conid]: conn,
|
||||
// };
|
||||
// }
|
||||
|
||||
function ensureCloudConnectionsLoaded(...conids) {
|
||||
_.uniq(conids).forEach(conid => {
|
||||
if (conid?.startsWith('cloud://') && !$cloudConnectionsStore[conid]) {
|
||||
loadCloudConnection(conid);
|
||||
}
|
||||
});
|
||||
}
|
||||
// function ensureCloudConnectionsLoaded(...conids) {
|
||||
// _.uniq(conids).forEach(conid => {
|
||||
// if (conid?.startsWith('cloud://') && !$cloudConnectionsStore[conid]) {
|
||||
// loadCloudConnection(conid);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
$: ensureCloudConnectionsLoaded(
|
||||
$currentDatabase?.connection?._id,
|
||||
...$openedSingleDatabaseConnections,
|
||||
...$openedConnections
|
||||
);
|
||||
// $: ensureCloudConnectionsLoaded(
|
||||
// $currentDatabase?.connection?._id,
|
||||
// ...$openedSingleDatabaseConnections,
|
||||
// ...$openedConnections
|
||||
// );
|
||||
|
||||
// onMount(() => {
|
||||
// const currentConid = $currentDatabase?.connection?._id;
|
||||
|
||||
Reference in New Issue
Block a user