Skip to content

Commit

Permalink
Merge pull request #6 from fkleon/fix-age-refresh
Browse files Browse the repository at this point in the history
Fix stale age being displayed
  • Loading branch information
fkleon authored May 9, 2024
2 parents a323f14 + 8376fe2 commit cd5ef7c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
3 changes: 0 additions & 3 deletions src/models/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const reviver = (key: string, value: any): any => {
if (key === 'dateOfBirth' || key === 'date') {
return LocalDate.parse(value);
}
if (key === 'age') {
return Period.parse(value);
}
return value;
};

Expand Down
7 changes: 1 addition & 6 deletions src/models/state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {LocalDate, Period} from '@js-joda/core';
import {LocalDate} from '@js-joda/core';
import charts, {ChartConfig} from '../data/who';
import {SeriesObject} from 'chartist';
import {COLOURS, TAGLINES} from './constants';
Expand Down Expand Up @@ -58,7 +58,6 @@ interface Child {
sex: Sex | null;
open: boolean;
colourHex?: string;
age?: Period; // computed
measurements: Measurement[];
}

Expand All @@ -81,7 +80,6 @@ const ChildState = (): Child => ({
dateOfBirth: undefined,
sex: null,
colourHex: COLOURS[0],
age: undefined,
measurements: [],
});

Expand All @@ -90,9 +88,6 @@ const ChildActions = (app: IAppActions, child: Child): IChildActions => ({
child.name = name;
child.dateOfBirth = dateOfBirth;
child.sex = sex;
if (dateOfBirth) {
child.age = Period.between(dateOfBirth, LocalDate.now());
}
child.measurements.forEach(m => (m.dateOfBirth = dateOfBirth));
},
pickColour: (hex: string) => {
Expand Down
9 changes: 6 additions & 3 deletions src/views/child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ const ChildComponent: m.Component<MitosisAttr<Child, IChildActions>> = {
(dom as HTMLElement).querySelector('input')?.focus();
},
view({attrs: {state, actions}}) {
const now = LocalDate.now();
const name = state.name ?? 'Unnamed';
const summary = `${name}${
state.age ? `, ${formatAge(state.age)} old` : ''
}`;
const age = state.dateOfBirth
? Period.between(state.dateOfBirth, now)
: null;

const summary = `${name}${age ? `, ${formatAge(age)} old` : ''}`;

return m(
'details',
Expand Down
15 changes: 14 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,21 @@ module.exports = (env, argv) => {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'bundle.js',
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'build/dist'),
},
optimization: {
moduleIds: 'deterministic',
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
},
};
};

0 comments on commit cd5ef7c

Please sign in to comment.