Fix dashboard for hour.datetime
This commit is contained in:
parent
fbfbdbefee
commit
4222c910eb
@ -57,7 +57,7 @@ export default function CategoriesView() {
|
||||
<TableCell className="py-1">{c.name}</TableCell>
|
||||
<TableCell className="py-1">{c.description}</TableCell>
|
||||
<TableCell className="py-1">
|
||||
categoryStats[c.id].numEntries
|
||||
{c.id}
|
||||
</TableCell>
|
||||
<TableCell className="flex gap-1 py-1">
|
||||
<ActionButtonWithTooltip
|
||||
|
||||
@ -49,7 +49,7 @@ export function EditableHourCode({
|
||||
}
|
||||
onSubmit({
|
||||
date: hour.date,
|
||||
hourTime: hour.time,
|
||||
datetime: hour.datetime,
|
||||
dayId: hour.dayId,
|
||||
code: newCode ?? "",
|
||||
comment: hour.comment,
|
||||
|
||||
@ -46,7 +46,7 @@ export function EditableHourComment({
|
||||
setText(ref.current?.value ?? originalText);
|
||||
onSubmit({
|
||||
date: hour.date,
|
||||
hourTime: hour.time,
|
||||
datetime: hour.datetime,
|
||||
dayId: hour.dayId,
|
||||
comment: ref.current?.value ?? "",
|
||||
code: hour.categoryCode.toString(),
|
||||
|
||||
@ -16,6 +16,7 @@ import { Trash, X } from "lucide-react";
|
||||
import { useDecrementCount, useIncrementCount, useSetValue, } from "@lifetracker/shared-react/hooks/measurements";
|
||||
import { Separator } from "@radix-ui/react-dropdown-menu";
|
||||
import { EditableText } from "../EditableText";
|
||||
import spacetime from "spacetime";
|
||||
|
||||
interface CreateMeasurementSchema {
|
||||
type: string;
|
||||
@ -168,31 +169,33 @@ export default function HourMeasurementsDialog({
|
||||
<DialogTrigger asChild>{children}</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Metrics for {hour.date} at {hour.datetime}</DialogTitle>
|
||||
<DialogTitle>Metrics for <span className={"secondary"}>{hour.date}</span> at {spacetime(hour.datetime).format("{hour} {ampm}")}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<Separator />
|
||||
{(hour.measurements && hour.measurements.length > 0) || pendingMeasurement ?
|
||||
(<>
|
||||
{/* <div className="font-bold">Measurements</div> */}
|
||||
<div className="mx-4 mb-4">
|
||||
{hour.measurements.map(measurement => {
|
||||
{hour.measurements!.map(measurement => {
|
||||
const metric = metrics.find(m => m.id === measurement.metricId);
|
||||
if (metric!.type === "timeseries") {
|
||||
return (
|
||||
<div key={measurement.id} className="flex items-center justify-between">
|
||||
<div className="gap-4 flex"><Icon name={titleCase(metric.icon)} size={24} />
|
||||
<div>{metric.name}</div></div>
|
||||
<div className="gap-4 flex"><Icon name={titleCase(metric!.icon)} size={24} />
|
||||
<div>{metric!.name}</div></div>
|
||||
<div className="flex gap-4 items-center">
|
||||
<EditableText originalText={measurement.value + " " + metric?.unit} onSave={(value) => {
|
||||
setValue({
|
||||
metricId: metric.id,
|
||||
hourId: hour.id,
|
||||
dayId: hour.dayId,
|
||||
value: parseFloat(value),
|
||||
});
|
||||
}} />
|
||||
<EditableText
|
||||
isSaving={false}
|
||||
originalText={measurement.value + " " + metric?.unit} onSave={(value) => {
|
||||
setValue({
|
||||
metricId: metric!.id,
|
||||
hourId: hour.id!,
|
||||
dayId: hour.dayId,
|
||||
value: parseFloat(value!),
|
||||
});
|
||||
}} />
|
||||
<Trash size={16} color="red" onClick={() => {
|
||||
decrement({ metricId: metric.id, hourId: hour.id, dayId: hour.dayId });
|
||||
decrement({ metricId: metric!.id!, hourId: hour.id! });
|
||||
}} />
|
||||
|
||||
</div>
|
||||
|
||||
@ -154,7 +154,7 @@ export const hoursAppRouter = router({
|
||||
.input(
|
||||
z.object({
|
||||
date: z.string(),
|
||||
hourTime: z.number(),
|
||||
datetime: z.date(),
|
||||
dayId: z.string(),
|
||||
code: z.string().nullish(),
|
||||
comment: z.string().nullable().optional(),
|
||||
@ -205,7 +205,7 @@ export const hoursAppRouter = router({
|
||||
.set(newProps)
|
||||
.where(
|
||||
and(
|
||||
eq(hours.time, input.hourTime),
|
||||
eq(hours.datetime, input.datetime),
|
||||
eq(hours.dayId, input.dayId),
|
||||
eq(hours.userId, ctx.user!.id)
|
||||
)
|
||||
@ -216,7 +216,7 @@ export const hoursAppRouter = router({
|
||||
// ...hourRes[0]
|
||||
// };
|
||||
|
||||
return hourJoinsQuery(ctx, input.hourTime, input.dayId,);
|
||||
return hourJoinsQuery(ctx, input.datetime, input.dayId,);
|
||||
|
||||
}),
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { and, desc, eq, inArray, notExists } from "drizzle-orm";
|
||||
import { and, asc, desc, eq, inArray, notExists } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
|
||||
import { DatabaseError, ErrorCodes } from "@lifetracker/db";
|
||||
@ -17,7 +17,9 @@ export const metricsAppRouter = router({
|
||||
const dbMeasurements = await ctx.db
|
||||
.select()
|
||||
.from(metrics)
|
||||
.where(eq(metrics.userId, ctx.user.id));
|
||||
.where(eq(metrics.userId, ctx.user.id))
|
||||
.orderBy(asc(metrics.name))
|
||||
;
|
||||
|
||||
return dbMeasurements;
|
||||
}),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user