Skip to content

Commit

Permalink
1.0.13 replication tools
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljonescodes committed Feb 28, 2024
1 parent 6bda08d commit fde9dd8
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"description": "An offline first nutrition planner",
"version": "1.0.12",
"version": "1.0.13",
"keywords": [
"nutrition"
],
Expand Down
4 changes: 2 additions & 2 deletions release/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nutrition-planner",
"version": "1.0.12",
"version": "1.0.13",
"description": "A simple calculator for nutrition",
"license": "MIT",
"main": "./dist/main/main.js",
Expand Down
8 changes: 4 additions & 4 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
* When running `npm run build` or `npm run build:main`, this file is compiled to
* `./src/main.js` using webpack. This gives us some performance wins.
*/
import path from 'path';
import { app, BrowserWindow, shell, ipcMain } from 'electron';
import { autoUpdater } from 'electron-updater';
import { BrowserWindow, app, ipcMain, shell } from 'electron';
import log from 'electron-log';
import { autoUpdater } from 'electron-updater';
import path from 'path';
import MenuBuilder from './menu';
import { resolveHtmlPath } from './util';

Expand Down Expand Up @@ -81,7 +81,7 @@ const createWindow = async () => {
},
});

mainWindow.loadURL(resolveHtmlPath('/index.html'));
mainWindow.loadURL(resolveHtmlPath('./index.html'));

mainWindow.on('ready-to-show', () => {
if (!mainWindow) {
Expand Down
9 changes: 8 additions & 1 deletion src/main/menu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, Menu, BrowserWindow, MenuItemConstructorOptions } from 'electron';
import { BrowserWindow, Menu, MenuItemConstructorOptions, app } from 'electron';

interface DarwinMenuItemConstructorOptions extends MenuItemConstructorOptions {
selector?: string;
Expand Down Expand Up @@ -128,6 +128,13 @@ export default class MenuBuilder {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen());
},
},
{
label: 'Toggle Developer Tools',
accelerator: 'Alt+Command+I',
click: () => {
this.mainWindow.webContents.toggleDevTools();
},
},
],
};
const subMenuWindow: DarwinMenuItemConstructorOptions = {
Expand Down
70 changes: 64 additions & 6 deletions src/renderer/components/drawers/SettingsDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Capacitor } from '@capacitor/core';
import { Directory, Encoding, Filesystem } from '@capacitor/filesystem';
import { DeleteIcon, DownloadIcon } from '@chakra-ui/icons';
import { DeleteIcon, DownloadIcon, WarningIcon } from '@chakra-ui/icons';
import {
Button,
Link as ChakraLink,
Expand Down Expand Up @@ -44,7 +44,14 @@ export function SettingsDrawer(props: SettingsDrawerProps) {
const { isOpen, onClose } = props;
const { t } = useTranslation();
const [importLoadingState, setImportLoadingState] = useState(false);
const [showDeleteDialogState, setShowDeleteDialogState] = useState(false);
const [
showRemoveDeleteAlertDialogState,
setShowRemoveDeleteAlertDialogState,
] = useState(false);
const [
showDeleteDeleteAlertDialogState,
setShowDeleteDeleteAlertDialogState,
] = useState(false);

const [couchDbUrlLocalStorage, setCouchDbUrlLocalStorage] = useLocalStorage<
string | undefined
Expand Down Expand Up @@ -204,16 +211,50 @@ export function SettingsDrawer(props: SettingsDrawerProps) {
>
{t('importJson')}
</Button>
<Button
width="full"
disabled={loading}
onClick={() => {
window.location.reload();
}}
>
{t('reload')}
</Button>
<Button
width="full"
colorScheme="yellow"
disabled={loading}
onClick={async () => {
await collection?.cleanup(0);
toast({
title: t('success'),
status: 'success',
});
}}
>
{t('cleanup')}
</Button>
<Button
width="full"
colorScheme="orange"
disabled={loading}
leftIcon={<WarningIcon />}
onClick={() => {
setShowRemoveDeleteAlertDialogState(true);
}}
>
{t('remove')}
</Button>
<Button
width="full"
colorScheme="red"
disabled={loading}
leftIcon={<DeleteIcon />}
onClick={() => {
setShowDeleteDialogState(true);
setShowDeleteDeleteAlertDialogState(true);
}}
>
{t('reset')}
{t('delete')}
</Button>
<HStack width="full" justify="space-between">
<ChakraLink
Expand Down Expand Up @@ -243,9 +284,9 @@ export function SettingsDrawer(props: SettingsDrawerProps) {
</DrawerContent>
</Drawer>
<DeleteAlertDialog
isOpen={showDeleteDialogState}
isOpen={showRemoveDeleteAlertDialogState}
onResult={async (result) => {
setShowDeleteDialogState(false);
setShowRemoveDeleteAlertDialogState(false);
if (result) {
await collection?.find().remove();
toast({
Expand All @@ -255,6 +296,23 @@ export function SettingsDrawer(props: SettingsDrawerProps) {
}
}}
/>
<DeleteAlertDialog
isOpen={showDeleteDeleteAlertDialogState}
onResult={async (result) => {
setShowDeleteDeleteAlertDialogState(false);
if (result) {
const databases = await indexedDB.databases();

// Iterate through the databases and delete them
databases.forEach((db) => {
if (db.name) {
indexedDB.deleteDatabase(db.name);
}
});
window.location.reload();
}
}}
/>
</>
);
}
20 changes: 14 additions & 6 deletions src/renderer/data/rxnp/RxNPDatabaseHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { createRxDatabase, RxStorage, RxCollection } from 'rxdb';
import { RxCollection, RxStorage, createRxDatabase } from 'rxdb';
import { dataid } from '../../utilities/dataid';
import { ItemInterface } from '../interfaces/ItemInterface';
import { ItemTypeEnum } from '../interfaces/ItemTypeEnum';
import { RxNPDatabaseCollections } from './RxNPDatabaseCollections';
import { RxNPDatabaseType } from './RxNPDatabaseType';
import {
RxNPItemDocument,
rxnpItemDocumentMethods,
rxnpItemSchema,
} from './RxNPItemSchema';
import { RxNPDatabaseCollections } from './RxNPDatabaseCollections';
import { RxNPDatabaseType } from './RxNPDatabaseType';
import { ItemInterface } from '../interfaces/ItemInterface';
import { dataid } from '../../utilities/dataid';
import { ItemTypeEnum } from '../interfaces/ItemTypeEnum';

export async function initRxNPDatabase(
name: string,
Expand All @@ -20,8 +20,16 @@ export async function initRxNPDatabase(
database = await createRxDatabase<RxNPDatabaseCollections>({
name,
storage,
cleanupPolicy: {
minimumDeletedTime: 1000 * 60 * 60 * 24 * 31, // one month,
minimumCollectionAge: 1000 * 60, // 60 seconds
runEach: 1000 * 60 * 5, // 5 minutes
awaitReplicationsInSync: true,
waitForLeadership: true,
},
});
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
}

Expand Down
14 changes: 11 additions & 3 deletions src/renderer/data/rxnp/useRxNPDatabase.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react';
import { addRxPlugin } from 'rxdb';
import { RxDBCleanupPlugin } from 'rxdb/plugins/cleanup';
import { RxDBJsonDumpPlugin } from 'rxdb/plugins/json-dump';
import { RxDBLeaderElectionPlugin } from 'rxdb/plugins/leader-election';
import { RxDBQueryBuilderPlugin } from 'rxdb/plugins/query-builder';
Expand Down Expand Up @@ -28,7 +29,11 @@ export const useRxNPDatabase = () => {

useEffect(() => {
async function replicate() {
if (couchDbUrlLocalStorage != null && database != null) {
if (
couchDbUrlLocalStorage != null &&
couchDbUrlLocalStorage.length > 0 &&
database != null
) {
try {
setReplicationState(
replicateCouchDB({
Expand All @@ -46,8 +51,10 @@ export const useRxNPDatabase = () => {
// eslint-disable-next-line no-console
console.log(error);
}
} else if (replicationState !== null) {
} else if (replicationState != null) {
replicationState.cancel();
// eslint-disable-next-line no-console
console.log('Replication cancelled');
}
}
replicate();
Expand All @@ -56,10 +63,11 @@ export const useRxNPDatabase = () => {

useEffect(() => {
if (!database) {
// addRxPlugin(RxDBDevModePlugin);
//addRxPlugin(RxDBDevModePlugin);

Check failure on line 66 in src/renderer/data/rxnp/useRxNPDatabase.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

Expected exception block, space or tab after '//' in comment
addRxPlugin(RxDBQueryBuilderPlugin);
addRxPlugin(RxDBJsonDumpPlugin);
addRxPlugin(RxDBLeaderElectionPlugin);
addRxPlugin(RxDBCleanupPlugin);
// eslint-disable-next-line promise/catch-or-return
initRxNPDatabase('nutrition-planner-db', getRxStorageDexie()).then(
setDatabase,
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/i18n/dictionaries/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"carbs": "كربوهيدرات",
"CHF": "فرنك سويسري",
"cholesterol": "كوليسترول",
"cleanup": "تنظيف",
"cmCentimeters": "سم",
"CNY": "يوان صيني",
"copied": "تم النسخ",
Expand Down Expand Up @@ -72,7 +73,8 @@
"privacy": "الخصوصية",
"protein": "بروتين",
"proteinTarget": "هدف البروتين",
"reset": "إعادة تعيين",
"reload": "إعادة تحميل",
"remove": "إعادة تعيين",
"saturatedFat": "دهون مشبعة",
"sedentary": "قليل النشاط",
"servingPrice": "سعر الحصة",
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/i18n/dictionaries/cmn.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"carbs": "碳水",
"CHF": "瑞士法郎",
"cholesterol": "胆固醇",
"cleanup": "清理",
"cmCentimeters": "厘米",
"CNY": "人民币",
"copied": "已复制",
Expand Down Expand Up @@ -72,7 +73,8 @@
"privacy": "隐私",
"protein": "蛋白质",
"proteinTarget": "蛋白质目标",
"reset": "重置",
"reload": "重新加载",
"remove": "重置",
"saturatedFat": "饱和脂肪",
"sedentary": "久坐",
"servingPrice": "每份价格",
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/i18n/dictionaries/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"carbs": "Carbs",
"CHF": "Swiss Franc",
"cholesterol": "Cholesterol",
"cleanup": "Cleanup",
"cmCentimeters": "cm",
"CNY": "Chinese Yuan",
"copied": "Copied",
Expand Down Expand Up @@ -72,7 +73,8 @@
"privacy": "Privacy",
"protein": "Protein",
"proteinTarget": "Protein target",
"reset": "Reset",
"reload": "Reload",
"remove": "Remove",
"saturatedFat": "Saturated Fat",
"sedentary": "Sedentary",
"servingPrice": "Serving price",
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/i18n/dictionaries/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"carbs": "Carbos",
"CHF": "Franco suizo",
"cholesterol": "Colesterol",
"cleanup": "Limpieza",
"cmCentimeters": "cm",
"CNY": "Yuan chino",
"copied": "已复制",
Expand Down Expand Up @@ -72,7 +73,8 @@
"privacy": "Privacidad",
"protein": "Proteína",
"proteinTarget": "Objetivo de proteínas",
"reset": "Reiniciar",
"reload": "Recargar",
"remove": "Reiniciar",
"saturatedFat": "Grasa saturada",
"sedentary": "Sedentario",
"servingPrice": "Precio por porción",
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/i18n/dictionaries/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"carbs": "Glucides",
"CHF": "Franc suisse",
"cholesterol": "Cholestérol",
"cleanup": "Nettoyage",
"cmCentimeters": "cm",
"CNY": "Yuan chinois",
"copied": "Copié",
Expand Down Expand Up @@ -72,7 +73,7 @@
"privacy": "Confidentialité",
"protein": "Protéine",
"proteinTarget": "Objectif de protéines",
"reset": "Réinitialiser",
"remove": "Réinitialiser",
"saturatedFat": "Graisse saturée",
"sedentary": "Sédentaire",
"servingPrice": "Prix par portion",
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/i18n/dictionaries/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"carbs": "कार्ब्स",
"CHF": "स्विस फ्रैंक",
"cholesterol": "कोलेस्ट्रॉल",
"cleanup": "सफाई",
"cmCentimeters": "सेंटीमीटर",
"CNY": "चीनी युआन",
"copied": "कॉपी किया गया",
Expand Down Expand Up @@ -72,7 +73,8 @@
"privacy": "गोपनीयता",
"protein": "प्रोटीन",
"proteinTarget": "प्रोटीन लक्ष्य",
"reset": "रीसेट",
"reload": "पुनः लोड करें",
"remove": "रीसेट",
"saturatedFat": "संतृप्त वसा",
"sedentary": "गतिहीन",
"servingPrice": "प्रति सर्विंग मूल्य",
Expand Down

0 comments on commit fde9dd8

Please sign in to comment.