axiosInstance replaced with apiCall

This commit is contained in:
Jan Prochazka
2021-12-22 10:16:44 +01:00
parent 148af24b2c
commit f9c54cdce2
55 changed files with 257 additions and 328 deletions

View File

@@ -3,6 +3,7 @@ import { currentDatabase, getCurrentDatabase } from '../stores';
import getElectron from '../utility/getElectron';
import registerCommand from './registerCommand';
import axiosInstance from '../utility/axiosInstance';
import { apiCall } from '../utility/api';
registerCommand({
id: 'database.changeState',
@@ -20,20 +21,20 @@ registerCommand({
{
text: 'Sync model',
onClick: () => {
axiosInstance().post('database-connections/sync-model', dbid);
apiCall('database-connections/sync-model', dbid);
},
},
{
text: 'Reopen',
onClick: () => {
axiosInstance().post('database-connections/refresh', dbid);
apiCall('database-connections/refresh', dbid);
},
},
{
text: 'Disconnect',
onClick: () => {
const electron = getElectron();
if (electron) axiosInstance().post('database-connections/disconnect', dbid);
if (electron) apiCall('database-connections/disconnect', dbid);
currentDatabase.set(null);
},
},

View File

@@ -25,6 +25,7 @@ import { openArchiveFolder } from '../utility/openArchiveFolder';
import InputTextModal from '../modals/InputTextModal.svelte';
import { removeLocalStorage } from '../utility/storageCache';
import { showSnackbarSuccess } from '../utility/snackbar';
import { apiCall } from '../utility/api';
function themeCommand(theme: ThemeDefinition) {
return {
@@ -121,7 +122,7 @@ registerCommand({
label: 'New archive folder name',
header: 'Create archive folder',
onConfirm: async folder => {
axiosInstance().post('archive/create-folder', { folder });
apiCall('archive/create-folder', { folder });
},
});
},
@@ -188,13 +189,8 @@ registerCommand({
label: 'New collection name',
header: 'Create collection',
onConfirm: async newCollection => {
await axiosInstance().request({
url: 'database-connections/run-script',
method: 'post',
params: dbid,
data: { sql: `db.createCollection('${newCollection}')` },
});
axiosInstance().post('database-connections/sync-model', dbid);
await apiCall('database-connections/run-script', { ...dbid, sql: `db.createCollection('${newCollection}')` });
apiCall('database-connections/sync-model', dbid);
},
});
},
@@ -256,8 +252,8 @@ registerCommand({
label: 'New database name',
header: 'Create SQLite database',
onConfirm: async file => {
const resp = await axiosInstance().post('connections/new-sqlite-database', { file });
const connection = resp.data;
const resp = await apiCall('connections/new-sqlite-database', { file });
const connection = resp;
currentDatabase.set({ connection, name: `${file}.sqlite` });
},
});