Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ba9b27019 | |||
| d7babf7230 | |||
| 224e12294a | |||
| 281b4db9fc | |||
| d7aa4e3534 |
4
.dockerignore
Normal file
4
.dockerignore
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
dist
|
||||||
|
node_modules
|
||||||
|
.git
|
||||||
|
.idea
|
||||||
26
Dockerfile
Normal file
26
Dockerfile
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
FROM node:20-alpine AS build
|
||||||
|
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
# install packages first
|
||||||
|
COPY package* .
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
# copy everything else and run the build
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM busybox:1.37 AS httpd
|
||||||
|
|
||||||
|
# add user to run web server as
|
||||||
|
RUN adduser -D static
|
||||||
|
USER static
|
||||||
|
WORKDIR /home/static
|
||||||
|
|
||||||
|
# copy build files from the node worker
|
||||||
|
COPY --from=build /build/dist /home/static
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
# run httpd in foreground, verbose, on port 3000
|
||||||
|
CMD ["busybox", "httpd", "-f", "-v", "-p", "3000"]
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ const schema = yup.object({
|
|||||||
startTime: yup.string().matches(timeRe, {message: '12 or 24 hr time format required'}).required(),
|
startTime: yup.string().matches(timeRe, {message: '12 or 24 hr time format required'}).required(),
|
||||||
target: yup.string().matches(durationRe, {message: 'duration in hh:mm or hrs and mins required'}).required(),
|
target: yup.string().matches(durationRe, {message: 'duration in hh:mm or hrs and mins required'}).required(),
|
||||||
break: yup.string().matches(durationRe, {message: 'duration in hh:mm or hrs and mins required'}).required(),
|
break: yup.string().matches(durationRe, {message: 'duration in hh:mm or hrs and mins required'}).required(),
|
||||||
breakTaken: yup.bool().required(),
|
breakTaken: yup.boolean().required(),
|
||||||
recorded: yup.string().matches(durationRe, {message: 'duration in hh:mm or hrs and mins required'}).required()
|
recorded: yup.string().matches(durationRe, {message: 'duration in hh:mm or hrs and mins required'}).required()
|
||||||
}).required();
|
}).required();
|
||||||
|
|
||||||
@@ -31,7 +31,9 @@ export function App() {
|
|||||||
startTime: '09:00',
|
startTime: '09:00',
|
||||||
target: '7.5h',
|
target: '7.5h',
|
||||||
break: '1h',
|
break: '1h',
|
||||||
recorded: getStoredRecordedTime(),
|
breakTaken: false,
|
||||||
|
recorded: '0',
|
||||||
|
...getStoredRecordedTime(),
|
||||||
...getStoredDefaults()
|
...getStoredDefaults()
|
||||||
},
|
},
|
||||||
resolver: yupResolver(schema)
|
resolver: yupResolver(schema)
|
||||||
@@ -52,8 +54,8 @@ export function App() {
|
|||||||
setRemaining(calculateRemaining(currentData));
|
setRemaining(calculateRemaining(currentData));
|
||||||
|
|
||||||
// save new values to storage
|
// save new values to storage
|
||||||
setStoredDefaults({ startTime: currentData.startTime, target: currentData.target });
|
setStoredDefaults(currentData);
|
||||||
setStoredRecordedTime(currentData.recorded);
|
setStoredRecordedTime(currentData.recorded, currentData.breakTaken);
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
setRemaining(calculateRemaining(currentData));
|
setRemaining(calculateRemaining(currentData));
|
||||||
@@ -67,6 +69,13 @@ export function App() {
|
|||||||
return () => sub.unsubscribe();
|
return () => sub.unsubscribe();
|
||||||
}, [handleSubmit, watch]);
|
}, [handleSubmit, watch]);
|
||||||
|
|
||||||
|
// submit form when loaded if we have a previously recorded time
|
||||||
|
useEffect(() => {
|
||||||
|
if (getStoredRecordedTime()) {
|
||||||
|
handleSubmit(onSubmit)(null);
|
||||||
|
}
|
||||||
|
}, [handleSubmit]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="window" style={{margin: "32px auto", width: "250px"}}>
|
<div class="window" style={{margin: "32px auto", width: "250px"}}>
|
||||||
<div class="title-bar">
|
<div class="title-bar">
|
||||||
|
|||||||
23
src/store.js
23
src/store.js
@@ -6,10 +6,12 @@ const RECORDED_KEY = 'recorded';
|
|||||||
const defaultsSchema = yup.object({
|
const defaultsSchema = yup.object({
|
||||||
startTime: yup.string().required(),
|
startTime: yup.string().required(),
|
||||||
target: yup.string().required(),
|
target: yup.string().required(),
|
||||||
|
break: yup.string().required(),
|
||||||
}).required();
|
}).required();
|
||||||
|
|
||||||
const recordedSchema = yup.object({
|
const recordedSchema = yup.object({
|
||||||
recorded: yup.string().required(),
|
recorded: yup.string().required(),
|
||||||
|
breakTaken: yup.boolean().required(),
|
||||||
updated: yup.number().required().nullable()
|
updated: yup.number().required().nullable()
|
||||||
}).required();
|
}).required();
|
||||||
|
|
||||||
@@ -39,11 +41,15 @@ export function getStoredDefaults() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setStoredDefaults(data) {
|
export function setStoredDefaults(data) {
|
||||||
localStorage.setItem(DEFAULTS_KEY, JSON.stringify(data));
|
try {
|
||||||
|
localStorage.setItem(DEFAULTS_KEY, JSON.stringify(defaultsSchema.cast(data, {stripUnknown: true})));
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Error setting stored defaults: ${e.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getStoredRecordedTime() {
|
export function getStoredRecordedTime() {
|
||||||
const info = getJsonValue(RECORDED_KEY, { recorded: '', updated: null });
|
const info = getJsonValue(RECORDED_KEY, { recorded: '', breakTaken: false, updated: null });
|
||||||
try {
|
try {
|
||||||
const data = recordedSchema.validateSync(info);
|
const data = recordedSchema.validateSync(info);
|
||||||
if (data.updated != null) {
|
if (data.updated != null) {
|
||||||
@@ -51,15 +57,18 @@ export function getStoredRecordedTime() {
|
|||||||
startOfDay.setHours(0, 0, 0, 0);
|
startOfDay.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
if (data.updated < startOfDay.valueOf()) {
|
if (data.updated < startOfDay.valueOf()) {
|
||||||
return '';
|
return { recorded: '0', breakTaken: false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data.recorded;
|
return {
|
||||||
|
recorded: data.recorded,
|
||||||
|
breakTaken: data.breakTaken,
|
||||||
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return '';
|
return { recorded: '0', breakTaken: false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setStoredRecordedTime(recorded) {
|
export function setStoredRecordedTime(recorded, breakTaken) {
|
||||||
localStorage.setItem(RECORDED_KEY, JSON.stringify({ recorded, updated: new Date().valueOf() }));
|
localStorage.setItem(RECORDED_KEY, JSON.stringify({ recorded, breakTaken, updated: new Date().valueOf() }));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user