Skip to content

Commit

Permalink
1.0.1 some bugfixes, fix warnings errors, can create logs by dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljonescodes committed Feb 22, 2024
1 parent 72ff437 commit 3c363b3
Show file tree
Hide file tree
Showing 38 changed files with 325 additions and 309 deletions.
2 changes: 1 addition & 1 deletion .erb/configs/webpack.config.renderer.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import { merge } from 'webpack-merge';
import TerserPlugin from 'terser-webpack-plugin';
import CopyPlugin from 'copy-webpack-plugin'
import CopyPlugin from 'copy-webpack-plugin';
import baseConfig from './webpack.config.base';
import webpackPaths from './webpack.paths';
import checkNodeEnv from '../scripts/check-node-env';
Expand Down
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ module.exports = {
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'import/prefer-default-export': 'off',
'react/require-default-props': 'off',
'react-hooks/exhaustive-deps': 'warn',
'react/jsx-props-no-spreading': 'warn',
'import/no-cycle': 'warn',
},
parserOptions: {
ecmaVersion: 2022,
Expand Down
4 changes: 2 additions & 2 deletions capacitor.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const config: CapacitorConfig = {
appName: 'Nutrition Planner',
webDir: 'release/app/dist/renderer',
server: {
androidScheme: 'https'
}
androidScheme: 'https',
},
};

export default config;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"description": "An offline first nutrition planner",
"version": "1.0.1",
"keywords": [
"nutrition"
],
Expand All @@ -26,6 +27,7 @@
"build:web": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.web.ts",
"postinstall": "ts-node .erb/scripts/check-native-dep.js && electron-builder install-app-deps && npm run build:dll",
"lint": "cross-env NODE_ENV=development eslint . --ext .js,.jsx,.ts,.tsx",
"lint:fix": "cross-env NODE_ENV=development eslint . --fix --ext .js,.jsx,.ts,.tsx",
"package": "ts-node ./.erb/scripts/clean.js dist && npm run build && electron-builder build --publish never && npm run build:dll",
"rebuild": "electron-rebuild --parallel --types prod,dev,optional --module-dir release/app",
"start": "ts-node ./.erb/scripts/check-port-in-use.js && npm run start:renderer",
Expand Down
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.0",
"version": "1.0.1",
"description": "A simple calculator for nutrition",
"license": "MIT",
"main": "./dist/main/main.js",
Expand Down
12 changes: 2 additions & 10 deletions src/main/menu.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
app,
Menu,
shell,
BrowserWindow,
MenuItemConstructorOptions,
} from 'electron';
import { app, Menu, BrowserWindow, MenuItemConstructorOptions } from 'electron';

interface DarwinMenuItemConstructorOptions extends MenuItemConstructorOptions {
selector?: string;
Expand All @@ -27,9 +21,7 @@ export default class MenuBuilder {
}

const template =
process.platform === 'darwin'
? this.buildDarwinTemplate()
: [];
process.platform === 'darwin' ? this.buildDarwinTemplate() : [];

const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { MenuHStack } from './components/MenuHStack';
import { LocalStorageKeysEnum } from './constants';
import { initRxNPDatabase } from './data/rxnp/RxNPDatabaseHelpers';
import { RxNPDatabaseType } from './data/rxnp/RxNPDatabaseType';
import { RxNPItemDocument } from './data/rxnp/RxNPItemSchema';
import LogPage from './pages';
import GroupsPage from './pages/groups';
import ItemsPage from './pages/items';
Expand Down Expand Up @@ -52,7 +53,7 @@ export default function App() {
'en',
);
const [replicationState, setReplicationState] =
useState<RxCouchDBReplicationState | null>(null);
useState<RxCouchDBReplicationState<RxNPItemDocument> | null>(null);

useEffect(() => {
i18n.changeLanguage(languageLocalStorage);
Expand All @@ -76,6 +77,7 @@ export default function App() {
} else if (replicationState !== null) {
replicationState.cancel();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [couchDbUrlLocalStorage, database]);

useEffect(() => {
Expand All @@ -84,6 +86,7 @@ export default function App() {
addRxPlugin(RxDBQueryBuilderPlugin);
addRxPlugin(RxDBJsonDumpPlugin);
addRxPlugin(RxDBLeaderElectionPlugin);
// eslint-disable-next-line promise/catch-or-return
initRxNPDatabase('nutrition-planner-db', getRxStorageDexie()).then(
setDatabase,
);
Expand Down
25 changes: 13 additions & 12 deletions src/renderer/components/BigCalendarChakraToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useTranslation } from 'react-i18next';
import { dateIsToday } from '../utilities/dateIsToday';

export function BigCalendarChakraToolbar(props: ToolbarProps) {
const { onNavigate, date, label, view, onView } = props;
const { t } = useTranslation();
return (
<HStack>
Expand All @@ -24,24 +25,24 @@ export function BigCalendarChakraToolbar(props: ToolbarProps) {
width={{ base: 'full', sm: 'initial' }}
>
<IconButton
onClick={() => props.onNavigate('PREV')}
onClick={() => onNavigate('PREV')}
icon={<ArrowBackIcon />}
aria-label={t('previous')}
variant="outline"
flexGrow={{ base: 1, sm: 'initial' }}
/>
<Button
onClick={() => props.onNavigate('TODAY')}
onClick={() => onNavigate('TODAY')}
variant="outline"
flexGrow={{ base: 1, sm: 'initial' }}
isActive={dateIsToday(props.date)}
isActive={dateIsToday(date)}
>
<Show below="sm">{props.label}</Show>
<Show below="sm">{label}</Show>
<Show above="sm">{t('today')}</Show>
</Button>
<IconButton
flexGrow={{ base: 1, sm: 'initial' }}
onClick={() => props.onNavigate('NEXT')}
onClick={() => onNavigate('NEXT')}
icon={<ArrowForwardIcon />}
aria-label={t('next')}
variant="outline"
Expand All @@ -52,31 +53,31 @@ export function BigCalendarChakraToolbar(props: ToolbarProps) {
</Show>
<Show above="sm">
<Center>
<Text>{props.label}</Text>
<Text>{label}</Text>
</Center>
</Show>
<Show above="sm">
<Spacer />
<ButtonGroup isAttached pb={3} pt={3}>
<Button
onClick={() => props.onView('day')}
onClick={() => onView('day')}
variant="outline"
isActive={props.view === 'day'}
isActive={view === 'day'}
>
{t('day')}
</Button>
<Button
onClick={() => props.onView('week')}
onClick={() => onView('week')}
variant="outline"
isActive={props.view === 'week'}
isActive={view === 'week'}
>
{t('week')}
</Button>
<Show above="md">
<Button
onClick={() => props.onView('month')}
onClick={() => onView('month')}
variant="outline"
isActive={props.view === 'month'}
isActive={view === 'month'}
>
{t('month')}
</Button>
Expand Down
12 changes: 6 additions & 6 deletions src/renderer/components/ItemTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Text,
Tr,
useColorModeValue,
useToast
useToast,
} from '@chakra-ui/react';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -24,8 +24,6 @@ import { RxNPItemDocument } from '../data/rxnp/RxNPItemSchema';
import { ServingOrTotalEnum } from '../data/interfaces/ServingOrTotalEnum';
import { LocalStorageKeysEnum } from '../constants';



export function ItemTableRow(props: {
document: RxNPItemDocument;
priceType: ServingOrTotalEnum;
Expand Down Expand Up @@ -98,8 +96,10 @@ export function ItemTableRow(props: {
icon={<CopyIcon />}
aria-label={t('copy')}
onClick={async () => {
const baseItems = getBaseItems(await document.recursivelyPopulateSubitems());
navigator.clipboard.writeText(baseItems.join("\n"));
const baseItems = getBaseItems(
await document.recursivelyPopulateSubitems(),
);
navigator.clipboard.writeText(baseItems.join('\n'));
toast({
title: t('copied'),
status: 'success',
Expand All @@ -108,7 +108,7 @@ export function ItemTableRow(props: {
/>
<IconButton
icon={<DeleteIcon />}
aria-label={t("delete")}
aria-label={t('delete')}
onClick={onDelete}
/>
</ButtonGroup>
Expand Down
1 change: 0 additions & 1 deletion src/renderer/components/form-controls/ItemFormControls.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FormikProps } from 'formik';
import { t } from 'i18next';
import { RefObject } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocalStorage } from 'usehooks-ts';
Expand Down
15 changes: 2 additions & 13 deletions src/renderer/components/form-controls/LogSubitemFormControls.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FormikProps } from 'formik';
import { t } from 'i18next';
import { RefObject } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocalStorage } from 'usehooks-ts';
Expand All @@ -13,25 +12,15 @@ export function LogSubitemFormControls(props: {
onPaste: (text: string) => Promise<void>;
firstInputFieldRef: RefObject<HTMLInputElement> | undefined;
}) {
const { formikProps, onPaste } = props;
const { formikProps, onPaste, firstInputFieldRef } = props;

const { t } = useTranslation();

const [languageLocalStorage] = useLocalStorage(
LocalStorageKeysEnum.language,
'en',
);

const [currencyLocalStorage] = useLocalStorage(
LocalStorageKeysEnum.currency,
'USD',
);

const currencyFormatter = new Intl.NumberFormat(languageLocalStorage, {
style: 'currency',
currency: currencyLocalStorage,
});

const currencyDenominator = currencyLocalStorage === 'JPY' ? 1 : 100;

return (
Expand All @@ -44,7 +33,7 @@ export function LogSubitemFormControls(props: {
placeholder={t('name')}
formikProps={formikProps}
spaceProps={{ pb: 2 }}
inputFieldRef={props.firstInputFieldRef}
inputFieldRef={firstInputFieldRef}
/>
<ValidatedFormikNumberControl
isRequired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ export function SubitemAutoCompleteInput(props: SubitemAutoCompleteInputProps) {
}}
/>
<AutoCompleteList>
{result.map((value) => {
{result.map((aValue) => {
return (
<AutoCompleteItem
key={value.id}
value={value}
key={aValue.id}
value={aValue}
getValue={(item) => {
return item.name;
}}
>
{value.name}
{aValue.name}
</AutoCompleteItem>
);
})}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/form-controls/SubitemField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ interface SubitemFieldProps {
}

export function SubitemField(props: SubitemFieldProps) {
const {formikProps, fieldArrayHelpers, itemTypesIn, label} = props;
const { formikProps, fieldArrayHelpers, itemTypesIn, label } = props;
return (
<VStack spacing={0} pb={2}>
<FormLabel>{label}</FormLabel>
{formikProps.values.subitems?.map((value, index) => {
return (
<SubitemAutoCompleteInput
key={`${index}-${value.itemId}`}
key={`${value.itemId}`}
value={value}
index={index}
itemTypesIn={itemTypesIn}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,13 @@ export function ValidatedDatetimeControl<T>(
},
}}
closeOnSelect
onChange={(value: string | moment.Moment) => {
let formattedValue = value;
if (moment.isMoment(value)) {
formattedValue = value.toISOString();
onChange={(aValue: string | moment.Moment) => {
let formattedValue = aValue;
if (moment.isMoment(aValue)) {
formattedValue = aValue.toISOString();
}
formikProps.setFieldValue(name, formattedValue);
}}
//
value={value ?? ''}
/>
{error && <FormErrorMessage>{error}</FormErrorMessage>}
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/form/LogForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
TabPanel,
} from '@chakra-ui/react';
import { Form, FormikProps } from 'formik';
import { FormEvent, Fragment, RefObject, useState } from 'react';
import { FormEvent, Fragment, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { ItemInterface } from '../../data/interfaces/ItemInterface';
import { ItemTypeEnum } from '../../data/interfaces/ItemTypeEnum';
Expand All @@ -20,7 +20,6 @@ import { LogSubitemFormControls } from '../form-controls/LogSubitemFormControls'

type LogFormProps = {
formikProps: FormikProps<ItemInterface>;
firstInputFieldRef: RefObject<HTMLInputElement> | undefined;
onDelete?: (item: ItemInterface | null) => void;
onPaste: (text: string) => Promise<void>;
onChangeType: (isLog: boolean) => void;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/components/formik/GroupFormik.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function GroupFormik(props: GroupFormikProps) {
}}
validateOnChange={false}
validateOnBlur={false}
// eslint-disable-next-line react/no-unstable-nested-components
component={(formikProps) => {
return (
<GroupForm
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/components/formik/ItemFormik.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function ItemFormik(props: ItemFormProps) {
}}
validateOnChange={false}
validateOnBlur={false}
// eslint-disable-next-line react/no-unstable-nested-components
component={(formikProps) => {
async function onPaste(text: string) {
const parsedNutritionDictionary: { [key: string]: number } =
Expand All @@ -72,6 +73,7 @@ export function ItemFormik(props: ItemFormProps) {

return (
<ItemForm
// eslint-disable-next-line react/jsx-no-bind
onPaste={onPaste}
firstInputFieldRef={firstInputFieldRef}
formikProps={formikProps}
Expand Down
Loading

0 comments on commit 3c363b3

Please sign in to comment.