-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
276 additions
and
7 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/components/FormattedDataTime/FormattedDateTimeShort.res
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
@react.component | ||
let make = (~value) => { | ||
let now = Js.Date.make() | ||
let todayEOD = Js.Date.makeWithYMD( | ||
~year=Js.Date.getFullYear(now), | ||
~month=Js.Date.getMonth(now), | ||
~date=Js.Date.getDate(now) +. 1.0, | ||
(), | ||
) | ||
let differenceInDays = Js.Math.floor_int( | ||
(todayEOD->Js.Date.getTime -. value->Js.Date.getTime) /. | ||
DateUtils.dayInMilliseconds->Float.fromInt, | ||
) | ||
switch differenceInDays { | ||
| 0 => <ReactIntl.FormattedTime hour=#numeric minute=#numeric value /> | ||
| 1 => | ||
<> | ||
{React.string("včera\xA0")} | ||
<ReactIntl.FormattedTime hour=#numeric minute=#numeric value /> | ||
</> | ||
| 2 => | ||
<> | ||
{React.string("předevčírem\xA0")} | ||
<ReactIntl.FormattedTime hour=#numeric minute=#numeric value /> | ||
</> | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 => | ||
<ReactIntl.FormattedDate | ||
year=?None month=?None day=?None hour=#numeric minute=#numeric value weekday=#long | ||
/> | ||
| _ => | ||
<ReactIntl.FormattedDate | ||
year=#numeric month=#numeric day=#numeric hour=#numeric minute=#numeric value | ||
/> | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
src/components/FormattedRelativeTime/FormattedRelativeTime.res
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
@react.component | ||
let make = (~dateTime) => { | ||
let make = React.memo((~dateTime) => { | ||
let timeDiff = (dateTime->Js.Date.getTime -. Js.Date.now()) /. 1000.0 | ||
<ReactIntl.FormattedRelativeTime numeric=#auto updateIntervalInSeconds={1.0} value={timeDiff} /> | ||
} | ||
}) |
69 changes: 69 additions & 0 deletions
69
src/components/TableConsumptions/TableConsumptions.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
.table { | ||
--cell-inline-padding: var(--padding-inline, 8px); | ||
} | ||
|
||
.table > * { | ||
display: contents; | ||
} | ||
|
||
.table th[scope="row"] { | ||
font-weight: var(--font-weight-regular); | ||
} | ||
|
||
.table tr { | ||
display: grid; | ||
grid-template-areas: "beer volume dateTime action"; | ||
grid-template-columns: 1fr 7ch 13ch 13ch; | ||
} | ||
.table :where(th, td) { | ||
padding-inline: var(--cell-inline-padding); | ||
} | ||
.table :where(th, td):nth-child(1) { | ||
grid-area: beer; | ||
text-align: left; | ||
} | ||
.table :where(th, td):nth-child(2) { | ||
grid-area: volume; | ||
text-align: right; | ||
place-content: end; | ||
} | ||
.table :where(th, td):nth-child(3) { | ||
grid-area: dateTime; | ||
text-align: right; | ||
} | ||
.table :where(th, td):nth-child(4) { | ||
grid-area: action; | ||
text-align: right; | ||
place-content: center; | ||
} | ||
|
||
@supports (grid-template-columns: subgrid) { | ||
.table { | ||
display: grid; | ||
grid-template-columns: repeat(4, auto); | ||
} | ||
.table tr { | ||
grid-column: 1 / -1; | ||
grid-template-columns: subgrid !important; | ||
} | ||
} | ||
|
||
@media screen and (max-width: 33rem) { | ||
.table { | ||
grid-template-columns: auto 1fr auto; | ||
} | ||
.table tr { | ||
grid-template-areas: | ||
"beer volume action" | ||
"dateTime dateTime action"; | ||
grid-template-columns: 7ch 1fr auto; | ||
} | ||
.table :where(th, td):nth-child(3) { | ||
padding-inline-start: var(--dialog-padding-inline); | ||
text-align: right; | ||
} | ||
.deleteButton { | ||
white-space: wrap; | ||
inline-size: min-content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* TypeScript file generated from DrinkDialog.res by genType. */ | ||
|
||
/* eslint-disable */ | ||
/* tslint:disable */ | ||
|
||
import * as DrinkDialogJS from './DrinkDialog.bs.js'; | ||
|
||
import type {kegConverted as Db_kegConverted} from '../../../src/backend/Db.gen'; | ||
|
||
import type {userConsumption as Db_userConsumption} from '../../../src/backend/Db.gen'; | ||
|
||
export type FormFields_state = { readonly tap: string; readonly consumption: number }; | ||
|
||
export type props<personName,preferredTap,onDeleteConsumption,onDismiss,onSubmit,tapsWithKegs,unfinishedConsumptions> = { | ||
readonly personName: personName; | ||
readonly preferredTap: preferredTap; | ||
readonly onDeleteConsumption: onDeleteConsumption; | ||
readonly onDismiss: onDismiss; | ||
readonly onSubmit: onSubmit; | ||
readonly tapsWithKegs: tapsWithKegs; | ||
readonly unfinishedConsumptions: unfinishedConsumptions | ||
}; | ||
|
||
export const make: React.ComponentType<{ | ||
readonly personName: string; | ||
readonly preferredTap: string; | ||
readonly onDeleteConsumption: (_1:Db_userConsumption) => void; | ||
readonly onDismiss: () => void; | ||
readonly onSubmit: (_1:FormFields_state) => T1; | ||
readonly tapsWithKegs: {[id: string]: Db_kegConverted}; | ||
readonly unfinishedConsumptions: Db_userConsumption[] | ||
}> = DrinkDialogJS.make as any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { userEvent, waitFor, within } from "@storybook/testing-library"; | ||
|
||
import { make as DrinkDialog } from "./DrinkDialog.gen"; | ||
import { getKegMock, getUserConsumptionMock } from "../../test/mockGenerators"; | ||
import { dayInMilliseconds } from "../../utils/DateUtils.gen"; | ||
|
||
const meta: Meta<typeof DrinkDialog> = { | ||
component: DrinkDialog, | ||
title: "components/DrinkDialog", | ||
parameters: { | ||
layout: `centered`, | ||
}, | ||
args: { | ||
personName: `Vašík`, | ||
preferredTap: `Hlavní`, | ||
tapsWithKegs: { | ||
Hlavní: getKegMock(), | ||
}, | ||
unfinishedConsumptions: [ | ||
{ | ||
...getUserConsumptionMock(), | ||
createdAt: new Date(Date.now() - 4 * dayInMilliseconds), | ||
}, | ||
{ | ||
...getUserConsumptionMock(), | ||
createdAt: new Date(Date.now() - dayInMilliseconds), | ||
}, | ||
getUserConsumptionMock(), | ||
], | ||
}, | ||
argTypes: { | ||
onDeleteConsumption: { action: "onDeleteConsumption" }, | ||
onDismiss: { action: "onDismiss" }, | ||
onSubmit: { action: "onSubmit" }, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof DrinkDialog>; | ||
|
||
export const Default: Story = { | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
const unfinishedBeersSumarry = await canvas.findByText(`Nezaúčtovaná piva`); | ||
await userEvent.click(unfinishedBeersSumarry); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Timestamp } from "firebase/firestore"; | ||
import { kegConverted, userConsumption } from "../backend/Db.gen"; | ||
import { | ||
hourInMilliseconds, | ||
monthInMilliseconds, | ||
} from "../utils/DateUtils.gen"; | ||
|
||
export const getRandomDateInstanceInHistory = ( | ||
lowerBound: Date | number | string = Date.now() - monthInMilliseconds | ||
): Date => { | ||
const now = new Date(); | ||
const diff = (now as any) - (new Date(lowerBound) as any); | ||
return new Date(Date.now() - Math.round(Math.random() * diff)); | ||
}; | ||
|
||
export const getRandomDateInHistory = ( | ||
lowerBound: Date | number | string = Date.now() - monthInMilliseconds | ||
): string => { | ||
return getRandomDateInstanceInHistory(lowerBound).toISOString(); | ||
}; | ||
|
||
export const getKegMock = (): kegConverted => { | ||
return { | ||
beer: `Pilsner Urquell`, | ||
consumptions: {}, | ||
consumptionsSum: 0, | ||
createdAt: Timestamp.fromDate(getRandomDateInstanceInHistory()), | ||
donors: {}, | ||
depletedAt: null, | ||
milliliters: 50000, | ||
price: 1000, | ||
recentConsumptionAt: null, | ||
serial: 1, | ||
serialFormatted: `1`, | ||
}; | ||
}; | ||
|
||
export const getUserConsumptionMock = (): userConsumption => { | ||
return { | ||
consumptionId: `1`, | ||
kegId: `1`, | ||
beer: `Pilsner Urquell`, | ||
milliliters: 500, | ||
createdAt: getRandomDateInstanceInHistory(Date.now() - hourInMilliseconds), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* TypeScript file generated from DateUtils.res by genType. */ | ||
|
||
/* eslint-disable */ | ||
/* tslint:disable */ | ||
|
||
import * as DateUtilsJS from './DateUtils.bs.js'; | ||
|
||
export const hourInMilliseconds: number = DateUtilsJS.hourInMilliseconds as any; | ||
|
||
export const dayInMilliseconds: number = DateUtilsJS.dayInMilliseconds as any; | ||
|
||
export const monthInMilliseconds: number = DateUtilsJS.monthInMilliseconds as any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters