Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
fgaudo committed Aug 5, 2024
1 parent dd8132a commit 5d7965c
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 166 deletions.
1 change: 1 addition & 0 deletions src/app/interfaces/read/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface ProductDTO {
id: string
name: string
expirationDate: OPT.Option<number>
creationDate: number
}

export const ProductDTO = {
Expand Down
24 changes: 15 additions & 9 deletions src/app/use-cases/product-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface ProductModel {
id: string
name: string
expirationDate: OPT.Option<number>
creationDate: number
isExpired: boolean
}

Expand All @@ -50,6 +51,7 @@ export interface UseCases {

interface ProductEntity {
id: string
creationDate: number
product: Product
}

Expand All @@ -70,6 +72,7 @@ const toProductEntitiesWithInvalid: (
({
id: entityDTO.id,
product,
creationDate: entityDTO.creationDate,
}) as const,
),
),
Expand All @@ -90,15 +93,18 @@ const toProductModels: (
T.map(timestamp =>
pipe(
products,
RoA.map(({ id, product }) => ({
id,
name: name(product),
isExpired: isExpired(
product,
timestamp,
),
expirationDate: expiration(product),
})),
RoA.map(
({ id, product, creationDate }) => ({
id,
name: name(product),
isExpired: isExpired(
product,
timestamp,
),
expirationDate: expiration(product),
creationDate,
}),
),
),
),
)
Expand Down
1 change: 1 addition & 0 deletions src/data/dexie/read/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const decodeProductRow = (
product.expiration_date,
OPT.fromNullable,
),
creationDate: product.creation_date,
})

const logErrors = flow(
Expand Down
4 changes: 2 additions & 2 deletions src/ui/core/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ export const formatRemainingTime = (
return `${differenceInHours(to, from).toString(10)}h`
}

if (days <= 31) {
if (days <= 28) {
return `${days.toString(10)}d`
}

return `>1m`
return `>4w`
}
39 changes: 35 additions & 4 deletions src/ui/pages/Home/components/ExpirationBar.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,49 @@
import type { Component } from 'solid-js'

import type { ProductModel } from '@/app/use-cases/product-list'
import { type Component, Show } from 'solid-js'

import { useUiStateContext } from '../context'

export const ExpirationBar: Component<{
expiration: () => number
creation: number
}> = props => {
const {
store: [state],
uiStore: [uiState, setUiState],
} = useUiStateContext()!

const isExpired = () =>
props.expiration() -
uiState.currentTimestamp <
0

const currentProgress = () => {
const totalDuration =
props.expiration() - props.creation
const remainingDuration =
props.expiration() -
uiState.currentTimestamp

return remainingDuration / totalDuration
}

return (
<div class="mt-[5px] h-[5px] w-full bg-red-400"></div>
<Show
fallback={
<div class="mt-[5px] h-[5px] w-full border-[1px] border-primary">
<div
class="h-full bg-primary"
style={{
width: `${(
currentProgress() * 100
).toString()}%`,
}}
/>
</div>
}
when={isExpired()}>
<p class="font-bold text-red-500">
Expired
</p>
</Show>
)
}
Loading

0 comments on commit 5d7965c

Please sign in to comment.