1
1
import { deleteCarbs } from '@/actions/delete-carbs'
2
2
import { validateRequest } from '@/auth'
3
3
import { CarbDialog } from '@/components/carb-dialog'
4
+ import CarbohydrateAbsorptionRate from '@/components/carbohydrate-absorption-rate'
5
+ import { CarbohydratesOnBoard } from '@/components/carbohydrates-on-board'
4
6
import { ClientDateTime } from '@/components/client-datetime'
5
7
import { DeleteDialog } from '@/components/delete-dialog'
6
8
import { PageDatePicker } from '@/components/page-date-picker'
7
9
import { Button } from '@/components/ui/button'
8
10
import { Progress } from '@/components/ui/progress'
9
11
import { Separator } from '@/components/ui/separator'
12
+ import { Tabs , TabsContent , TabsList , TabsTrigger } from '@/components/ui/tabs'
10
13
import { Statistics } from '@/lib/sql_utils'
11
14
import { addHours , subHours } from 'date-fns'
12
15
import { Pencil } from 'lucide-react'
@@ -18,7 +21,6 @@ interface Props {
18
21
date ?: string
19
22
}
20
23
}
21
-
22
24
export async function CarbsList ( { params } : Props ) {
23
25
const date = params ?. date ? new Date ( Number ( params . date ) ) : undefined
24
26
@@ -52,58 +54,84 @@ export async function CarbsList({ params }: Props) {
52
54
53
55
return (
54
56
< >
55
- < PageDatePicker baseUrl = "/carbs/list" date = { date } />
56
- < div className = "p-2" >
57
- < div className = " border bg-white max-w-5xl mx-auto rounded-md shadow p-2 mt-4" >
58
- { carbs . map ( ( carb , i , arr ) => {
59
- const over = carb . observedCarbs > carb . carbs
57
+ < PageDatePicker date = { date } baseUrl = "/carbs/list" />
58
+ < div className = "max-w-5xl mx-auto p-2" >
59
+ < div className = "hidden md:grid grid-cols-2 gap-2" >
60
+ < CarbohydratesOnBoard />
61
+ < CarbohydrateAbsorptionRate />
62
+ </ div >
60
63
61
- return (
62
- < div key = { carb . id } >
63
- < div className = "p-2" >
64
- < div className = "grid grid-cols-2 pb-2" >
65
- < div >
66
- < div > { Math . round ( carb . carbs ) } g </ div >
67
- < div > Observed: { Math . round ( carb . observedCarbs ) } g </ div >
68
- </ div >
69
- < div className = "flex items-center gap-2 justify-end" >
70
- < div >
71
- < ClientDateTime timestamp = { carb . timestamp } /> +{ ' ' }
72
- { ( carb . decay / 60 ) . toLocaleString ( [ ] , {
73
- maximumFractionDigits : 1 ,
74
- } ) }
75
- < span > h</ span >
76
- </ div >
77
- < div >
78
- < CarbDialog carb = { carb } >
79
- < Button variant = "ghost" className = "p-2" >
80
- < Pencil className = "cursor-pointer w-4 h-4" />
81
- </ Button >
82
- </ CarbDialog >
83
- < DeleteDialog id = { carb . id } action = { deleteCarbs } />
64
+ < Tabs defaultValue = "cob" className = "md:hidden" >
65
+ < TabsList >
66
+ < TabsTrigger value = "cob" > On board</ TabsTrigger >
67
+ < TabsTrigger value = "rate" > Absorption rate</ TabsTrigger >
68
+ </ TabsList >
69
+ < TabsContent value = "cob" >
70
+ < CarbohydratesOnBoard />
71
+ </ TabsContent >
72
+ < TabsContent value = "rate" >
73
+ < CarbohydrateAbsorptionRate />
74
+ </ TabsContent >
75
+ </ Tabs >
76
+
77
+ < >
78
+ < div className = "p-2" >
79
+ < div className = " border bg-white max-w-5xl mx-auto rounded-md shadow p-2 mt-4" >
80
+ { carbs . map ( ( carb , i , arr ) => {
81
+ const over = carb . observedCarbs > carb . carbs
82
+
83
+ return (
84
+ < div key = { carb . id } >
85
+ < div className = "p-2" >
86
+ < div className = "grid grid-cols-2 pb-2" >
87
+ < div >
88
+ < div > { Math . round ( carb . carbs ) } g </ div >
89
+ < div >
90
+ Observed: { Math . round ( carb . observedCarbs ) } g{ ' ' }
91
+ </ div >
92
+ </ div >
93
+ < div className = "flex items-center gap-2 justify-end" >
94
+ < div >
95
+ < ClientDateTime timestamp = { carb . timestamp } /> +{ ' ' }
96
+ { ( carb . decay / 60 ) . toLocaleString ( [ ] , {
97
+ maximumFractionDigits : 1 ,
98
+ } ) }
99
+ < span > h</ span >
100
+ </ div >
101
+ < div >
102
+ < CarbDialog carb = { carb } >
103
+ < Button variant = "ghost" className = "p-2" >
104
+ < Pencil className = "cursor-pointer w-4 h-4" />
105
+ </ Button >
106
+ </ CarbDialog >
107
+ < DeleteDialog id = { carb . id } action = { deleteCarbs } />
108
+ </ div >
109
+ </ div >
84
110
</ div >
111
+ { over ? (
112
+ < Progress
113
+ className = "h-2 bg-orange-400"
114
+ value = { ( carb . carbs / carb . observedCarbs ) * 100 }
115
+ />
116
+ ) : (
117
+ < Progress
118
+ className = "h-2 "
119
+ value = { ( carb . observedCarbs / carb . carbs ) * 100 }
120
+ />
121
+ ) }
85
122
</ div >
123
+ { arr . length - 1 !== i && < Separator className = "my-2" /> }
86
124
</ div >
87
- { over ? (
88
- < Progress
89
- className = "h-2 bg-orange-400"
90
- value = { ( carb . carbs / carb . observedCarbs ) * 100 }
91
- />
92
- ) : (
93
- < Progress
94
- className = "h-2 "
95
- value = { ( carb . observedCarbs / carb . carbs ) * 100 }
96
- />
97
- ) }
98
- </ div >
99
- { arr . length - 1 !== i && < Separator className = "my-2" /> }
100
- </ div >
101
- )
102
- } ) }
103
- { carbs . length === 0 && (
104
- < p className = "text-center p-2 text-slate-400" > No meal entries</ p >
105
- ) }
106
- </ div >
125
+ )
126
+ } ) }
127
+ { carbs . length === 0 && (
128
+ < p className = "text-center p-2 text-slate-400" >
129
+ No meal entries
130
+ </ p >
131
+ ) }
132
+ </ div >
133
+ </ div >
134
+ </ >
107
135
</ div >
108
136
</ >
109
137
)
0 commit comments