insomnia/app/models/settings.js
Gregory Schier 1cf1037c93 Better Redux (#43)
* Started refactoring redux stores

* Oh God huge refactor here

* Sync contenst updates and nested folders

* Fixed render tests

* A bunch of tweaks
2016-11-16 09:18:39 -08:00

45 lines
920 B
JavaScript

import * as db from '../common/database';
export const type = 'Settings';
export const prefix = 'set';
export function init () {
return {
showPasswords: true,
useBulkHeaderEditor: false,
followRedirects: true,
editorFontSize: 12,
editorLineWrapping: true,
httpProxy: '',
httpsProxy: '',
timeout: 0,
validateSSL: true,
forceVerticalLayout: false,
};
}
export async function all () {
const settings = await db.all(type);
if (settings.length === 0) {
return [await getOrCreate()];
} else {
return settings;
}
}
export async function create (patch = {}) {
return db.docCreate(type, patch);
}
export async function update (settings, patch) {
return db.docUpdate(settings, patch);
}
export async function getOrCreate () {
const results = await db.all(type);
if (results.length === 0) {
return await create();
} else {
return results[0];
}
}