database connections

This commit is contained in:
Jan Prochazka
2020-05-01 17:38:25 +02:00
parent 3e07c2b76e
commit 7d36ddbc04
11 changed files with 173 additions and 39 deletions

View File

@@ -0,0 +1,22 @@
import React from 'react';
import _ from 'lodash';
import { useOpenedConnections, useCurrentDatabase } from './globalState';
import axios from './axios';
export default function ConnectionsPinger({ children }) {
const openedConnections = useOpenedConnections();
const currentDatabase = useCurrentDatabase();
React.useEffect(() => {
const handle = window.setInterval(() => {
axios.post('server-connections/ping', { connections: openedConnections });
const database = _.get(currentDatabase, 'name');
const conid = _.get(currentDatabase, 'connection._id');
if (conid && database) {
axios.post('database-connections/ping', { conid });
}
}, 30 * 1000);
return () => window.clearInterval(handle);
}, [openedConnections, currentDatabase]);
return children;
}

View File

@@ -1,14 +0,0 @@
import React from 'react';
import { useOpenedConnections } from './globalState';
import axios from './axios';
export default function OpenedConnectionsPinger({ children }) {
const openedConnections = useOpenedConnections();
React.useEffect(() => {
const handle = window.setInterval(() => {
axios.post('server-connections/ping', { connections: openedConnections });
}, 30 * 1000);
return () => window.clearInterval(handle);
}, [openedConnections]);
return children;
}