1 Commits
Author SHA1 Message Date
kennyboy55 36881293ed AI Changes: scan page fix, filters improvements
Build dev docker image / build (push) Successful in 23s
Build dev docker image / build (push) Successful in 36s
Build dev docker image / release (push) Successful in 1s
2026-08-07 11:53:20 +02:00
5 changed files with 122 additions and 53 deletions
+5
View File
@@ -1,5 +1,10 @@
Beer-inventory project for home use.
The project has three aspects.
- The website, which people can visit to see the current inventory of drinks. They can see in which section a drink is stored.
- The Admin website, which is part of the main website but only to logged in admin users. Which allows updating drinks, inventory, and adding or editing data.
- The scanner, which is a raspberry pi with touchscreen display and a USB barcode scanner. This is next to the fridge, and people use it to scan a drink to remove it from the inventory.
Used technology:
- remix.run (now known as react router)
- prisma
+97 -38
View File
@@ -2,7 +2,7 @@
import { useSubmit } from '@remix-run/react';
import { BeerStyle, Manufacturer, WineStyle } from '@zenstackhq/runtime/models';
import { useRef, useState } from 'react';
import { Form, Col, Row } from 'react-bootstrap';
import { Button, Form, Col, Row } from 'react-bootstrap';
interface Arguments {
beerStyles: BeerStyle[];
@@ -20,11 +20,28 @@ function DrinkFilter(arg : Arguments) {
const showSodaFilter = arg.searchParams.has("drink", "Soda");
const showCocktailFilter = arg.searchParams.has("drink", "Cocktail");
const form = useRef(null);
const form = useRef<HTMLFormElement | null>(null);
const drinkTypes = ["Beer", "Wine", "Soda", "Cocktail"];
const [beerStyleExpanded, setBeerStyleExpanded] = useState(false);
const [wineStyleExpanded, setWineStyleExpanded] = useState(false);
const submitAfterRender = function(){
setTimeout(() => submit(form.current), 10);
}
const toggleDrinkType = (drinkType: string) => {
const params = new URLSearchParams(arg.searchParams.toString());
const values = params.getAll("drink");
if (values.includes(drinkType)) {
params.delete("drink");
values.filter((value) => value !== drinkType).forEach((value) => params.append("drink", value));
} else {
params.append("drink", drinkType);
}
if (params.get("abv") === "all") {
params.delete("abv");
}
submit(params, { method: "get", replace: true });
};
const handleFormChange = (event: React.ChangeEvent<HTMLFormElement>) => {
const formData = new FormData(event.currentTarget);
@@ -37,6 +54,8 @@ function DrinkFilter(arg : Arguments) {
}
const abvSelection = arg.searchParams.get("abv") || "all";
const selectedBeerStyleCount = arg.searchParams.getAll("beerstyle").length;
const selectedWineStyleCount = arg.searchParams.getAll("winestyle").length;
const abvOptions = [
{ value: "all", label: "All" },
{ value: "alcohol-free", label: "Alcohol free" },
@@ -87,17 +106,24 @@ function DrinkFilter(arg : Arguments) {
</Form.Group>
<Form.Group controlId="drink-type" className='bg-body-secondary rounded p-3 mt-3'>
<Form.Label className='fw-bold'>Drink Type</Form.Label>
{ ["Beer", "Wine", "Soda", "Cocktail"].map(key => (
<Form.Check
id={"drink-" + key}
type="checkbox"
label={key}
name="drink"
value={key}
defaultChecked={arg.searchParams.has("drink", key) ? true : false}
/>
<div className='row row-cols-2 g-2'>
{drinkTypes.map((key) => (
<div className='col' key={key}>
<Button
type="button"
variant={arg.searchParams.has("drink", key) ? "primary" : "outline-primary"}
className='w-100 text-start'
aria-pressed={arg.searchParams.has("drink", key)}
onClick={() => toggleDrinkType(key)}
>
{key}
</Button>
</div>
))}
</div>
{arg.searchParams.getAll("drink").map((drinkValue) => (
<input key={drinkValue} type="hidden" name="drink" value={drinkValue} />
))}
</Form.Group>
<Form.Group controlId="drink-abv" className='bg-body-secondary rounded p-3 mt-3'>
<Form.Label className='fw-bold'>Alcohol Percentage</Form.Label>
@@ -119,34 +145,67 @@ function DrinkFilter(arg : Arguments) {
{ showBeerFilter ? (
<>
<Form.Group controlId="beer-style" className='bg-body-secondary rounded p-3 mt-3'>
<Form.Label className='fw-bold mt-3'>Beer style</Form.Label>
{ arg.beerStyles.map(style => (
<Form.Check
id={"beerstyle-" + style.name}
type="checkbox"
label={style.name}
name="beerstyle"
value={style.id}
defaultChecked={arg.searchParams.has("beerstyle", style.id.toString()) ? true : false}
/>
))}
<div className='d-flex justify-content-between align-items-center'>
<Form.Label className='fw-bold mb-0'>Beer style {selectedBeerStyleCount > 0 ? ( <span className="badge text-bg-dark">{selectedBeerStyleCount} selected</span>) : ''}</Form.Label>
<Button
type='button'
variant='outline-secondary'
size='sm'
onClick={() => setBeerStyleExpanded((current) => !current)}
>
{beerStyleExpanded ? 'Collapse' : 'Expand'}
</Button>
</div>
{beerStyleExpanded ? (
<div className='mt-3'>
{ arg.beerStyles.map(style => (
<Form.Check
key={style.id}
id={"beerstyle-" + style.name}
type="checkbox"
label={style.name}
name="beerstyle"
value={style.id}
defaultChecked={arg.searchParams.has("beerstyle", style.id.toString()) ? true : false}
/>
))}
</div>
) : (
<div className='text-muted mt-3'>Tap expand to show beer styles</div>
)}
</Form.Group>
</>
) : ""}
{ showWineFilter ? (
<Form.Group controlId="wine-style" className='bg-body-secondary rounded p-3 mt-3'>
<Form.Label className='fw-bold'>Wine style</Form.Label>
{ arg.wineStyles.map(style => (
<Form.Check
id={"winestyle-" + style.name}
type="checkbox"
label={style.name}
name="winestyle"
value={style.id}
defaultChecked={arg.searchParams.has("winestyle", style.id.toString()) ? true : false}
/>
))}
</Form.Group>
<div className='d-flex justify-content-between align-items-center'>
<Form.Label className='fw-bold mb-0'>Wine style {selectedWineStyleCount > 0 ? ( <span className="badge text-bg-dark">{selectedWineStyleCount} selected</span>) : ''}</Form.Label>
<Button
type='button'
variant='outline-secondary'
size='sm'
onClick={() => setWineStyleExpanded((current) => !current)}
>
{wineStyleExpanded ? 'Collapse' : 'Expand'}
</Button>
</div>
{wineStyleExpanded ? (
<div className='mt-3'>
{ arg.wineStyles.map(style => (
<Form.Check
id={"winestyle-" + style.name}
type="checkbox"
label={style.name}
name="winestyle"
value={style.id}
defaultChecked={arg.searchParams.has("winestyle", style.id.toString()) ? true : false}
/>
))}
</div>
) : (
<div className='text-muted mt-3'>Tap expand to show wine styles</div>
)}
</Form.Group>
) : ""}
{ showSodaFilter ? (
<Form.Group controlId="soda-carbonated" className='bg-body-secondary rounded p-3 mt-3'>
+3 -3
View File
@@ -83,7 +83,7 @@ export function ErrorBoundary() {
const hourly = window.setInterval(() => {
tryRefresh();
}, 60 * 60 * 1000);
}, 15 * 60 * 1000); // Every 15 minutes
return () => {
window.removeEventListener("online", handleOnline);
@@ -120,7 +120,7 @@ export function ErrorBoundary() {
>
Try refresh now
</button>
<div className="mt-2">Status: {isOnline ? "Online" : "Offline"}. Will retry automatically every hour.</div>
<div className="mt-2">Status: {isOnline ? "Online" : "Offline"}. Will retry automatically every 15 minutes.</div>
</div>
</div>
</Col>
@@ -159,7 +159,7 @@ export function ErrorBoundary() {
>
Try refresh now
</button>
<div className="mt-2">Status: {isOnline ? "Online" : "Offline"}. Will retry automatically every hour.</div>
<div className="mt-2">Status: {isOnline ? "Online" : "Offline"}. Will retry automatically every 15 minutes.</div>
</div>
</div>
</Col>
+1 -1
View File
@@ -41,7 +41,7 @@ export default function InventoryLayout() {
setCheckouts(newCheckouts);
}
}, 5000);
}, 30000);
return () => clearTimeout(timer);
});
+16 -11
View File
@@ -1,8 +1,8 @@
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { useActionData, useLoaderData } from "@remix-run/react";
import { Form as RemixForm, useActionData, useLoaderData } from "@remix-run/react";
import { useEffect, useRef, useState } from "react";
import { Col, Container, Form, Row, Table } from "react-bootstrap";
import { Col, Container, Form as BootstrapForm, Row, Table } from "react-bootstrap";
import timeAgo from "~/utils/datetime";
import { enhance } from "~/utils/db.server";
@@ -16,7 +16,7 @@ export async function loader({
return redirect("/");
}
const history = await dbe.history.findMany({select: {id: true, checkoutAt: true, inventoryAfter: true, container: {select: {drink: true}}}, take: 10, orderBy: {checkoutAt: "desc"}});
const history = await dbe.history.findMany({select: {id: true, checkoutAt: true, inventoryAfter: true, container: {select: {drink: true}}}, take: 5, orderBy: {checkoutAt: "desc"}});
return json({history});
}
@@ -116,6 +116,10 @@ export default function ScanRoute() {
return;
}
if (inputRef.current) {
inputRef.current.value = "";
}
setLastScanned(aData.lastScanned);
setShowLastScanned(true);
@@ -137,7 +141,7 @@ export default function ScanRoute() {
<tr>
<th>Drink</th>
<th>When</th>
<th>Amount left</th>
<th># Left</th>
</tr>
</thead>
<tbody>
@@ -158,14 +162,15 @@ export default function ScanRoute() {
<Col>
{/* Hidden fullscreen toggle button - triggered by clicking the h3 headers */}
<button
type="button"
ref={fullscreenBtnRef}
onClick={toggleFullscreen}
style={{ display: 'none' }}
aria-hidden="true"
/>
<Form method="post" action="/scan?index" noValidate>
<Form.Group>
<Form.Control
<RemixForm method="post" action="/scan?index" noValidate>
<BootstrapForm.Group>
<BootstrapForm.Control
ref={inputRef}
type="text"
name="barcode"
@@ -175,11 +180,11 @@ export default function ScanRoute() {
inputMode="text"
style={{ height: '3rem', fontSize: '1.8rem', textAlign: 'center' }}
/>
<Form.Control.Feedback type="invalid">
<BootstrapForm.Control.Feedback type="invalid">
{aData?.error}
</Form.Control.Feedback>
</Form.Group>
</Form>
</BootstrapForm.Control.Feedback>
</BootstrapForm.Group>
</RemixForm>
</Col>
</Row>
<Row>