Skip to content

Commit 5246e46

Browse files
committed
fix(frontend): add conditionals for workouts
1 parent ed960e3 commit 5246e46

File tree

6 files changed

+284
-286
lines changed

6 files changed

+284
-286
lines changed

apps/frontend/app/lib/hooks.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@ import {
1010
UserMetadataDetailsDocument,
1111
} from "@ryot/generated/graphql/backend/graphql";
1212
import { skipToken, useQuery } from "@tanstack/react-query";
13-
import { useAtom } from "jotai";
1413
import Cookies from "js-cookie";
1514
import {
1615
CurrentWorkoutKey,
1716
clientGqlService,
1817
dayjsLib,
1918
getStringAsciiValue,
2019
} from "~/lib/generals";
21-
import {
22-
type InProgressWorkout,
23-
currentWorkoutAtom,
24-
} from "~/lib/state/workout";
20+
import { type InProgressWorkout, useCurrentWorkout } from "~/lib/state/workout";
2521
import type { loader } from "~/routes/_dashboard";
2622

2723
export function useGetMantineColor() {
@@ -58,7 +54,7 @@ export function useSearchParam() {
5854

5955
export function getWorkoutStarter() {
6056
const navigate = useNavigate();
61-
const [_, setCurrentWorkout] = useAtom(currentWorkoutAtom);
57+
const [_, setCurrentWorkout] = useCurrentWorkout();
6258

6359
const fn = (wkt: InProgressWorkout) => {
6460
setCurrentWorkout(wkt);

apps/frontend/app/lib/state/workout.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import type { Dayjs } from "dayjs";
1313
import { createDraft, finishDraft } from "immer";
1414
import { useAtom } from "jotai";
1515
import { atomWithReset, atomWithStorage } from "jotai/utils";
16-
import invariant from "tiny-invariant";
1716
import { v4 as randomUUID } from "uuid";
1817
import { CurrentWorkoutKey, clientGqlService } from "~/lib/generals";
1918

@@ -56,14 +55,13 @@ export type InProgressWorkout = {
5655

5756
type CurrentWorkout = InProgressWorkout | null;
5857

59-
export const currentWorkoutAtom = atomWithStorage<CurrentWorkout>(
58+
const currentWorkoutAtom = atomWithStorage<CurrentWorkout>(
6059
CurrentWorkoutKey,
6160
null,
6261
);
6362

6463
export const useCurrentWorkout = () => {
6564
const [currentWorkout, setCurrentWorkout] = useAtom(currentWorkoutAtom);
66-
invariant(currentWorkout);
6765
return [currentWorkout, setCurrentWorkout] as const;
6866
};
6967

apps/frontend/app/root.tsx

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { $path } from "@ignisda/remix-routes";
21
import {
32
ActionIcon,
43
Alert,
@@ -15,7 +14,6 @@ import {
1514
type MetaFunction,
1615
unstable_defineLoader,
1716
} from "@remix-run/node";
18-
import { Form } from "@remix-run/react";
1917
import {
2018
Links,
2119
Meta,
@@ -163,37 +161,37 @@ export default function App() {
163161
);
164162
}
165163

166-
export function ErrorBoundary() {
167-
return (
168-
<html lang="en">
169-
<head>
170-
<DefaultHeadTags />
171-
<Meta />
172-
<Links />
173-
</head>
174-
<body>
175-
<div>
176-
We encountered an error. If you recently upgraded the server, you may
177-
have to logout and login again. If the error still persists, please
178-
create a new issue on{" "}
179-
<a
180-
href="https://github.com/ignisda/ryot/issues"
181-
target="_blank"
182-
rel="noreferrer noopener"
183-
>
184-
GitHub
185-
</a>
186-
.
187-
</div>
188-
<Form
189-
replace
190-
method="POST"
191-
action={$path("/actions", { intent: "logout" })}
192-
>
193-
<button type="submit">Logout</button>
194-
</Form>
195-
<Scripts />
196-
</body>
197-
</html>
198-
);
199-
}
164+
// export function ErrorBoundary() {
165+
// return (
166+
// <html lang="en">
167+
// <head>
168+
// <DefaultHeadTags />
169+
// <Meta />
170+
// <Links />
171+
// </head>
172+
// <body>
173+
// <div>
174+
// We encountered an error. If you recently upgraded the server, you may
175+
// have to logout and login again. If the error still persists, please
176+
// create a new issue on{" "}
177+
// <a
178+
// href="https://github.com/ignisda/ryot/issues"
179+
// target="_blank"
180+
// rel="noreferrer noopener"
181+
// >
182+
// GitHub
183+
// </a>
184+
// .
185+
// </div>
186+
// <Form
187+
// replace
188+
// method="POST"
189+
// action={$path("/actions", { intent: "logout" })}
190+
// >
191+
// <button type="submit">Logout</button>
192+
// </Form>
193+
// <Scripts />
194+
// </body>
195+
// </html>
196+
// );
197+
// }

apps/frontend/app/routes/_dashboard.fitness.exercises.item.$id._index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import {
4545
IconTrophy,
4646
IconUser,
4747
} from "@tabler/icons-react";
48-
import { useAtom } from "jotai";
4948
import { Fragment } from "react";
5049
import invariant from "tiny-invariant";
5150
import { match } from "ts-pattern";
@@ -57,7 +56,7 @@ import { DisplayCollection, MediaScrollArea } from "~/components/media";
5756
import { dayjsLib, getSetColor } from "~/lib/generals";
5857
import { useUserDetails, useUserPreferences } from "~/lib/hooks";
5958
import { useAddEntityToCollection } from "~/lib/state/media";
60-
import { addExerciseToWorkout, currentWorkoutAtom } from "~/lib/state/workout";
59+
import { addExerciseToWorkout, useCurrentWorkout } from "~/lib/state/workout";
6160
import {
6261
getAuthorizationHeader,
6362
serverGqlService,
@@ -97,7 +96,7 @@ export default function Page() {
9796
const canCurrentUserUpdate =
9897
loaderData.exerciseDetails.source === ExerciseSource.Custom &&
9998
userDetails.id === loaderData.exerciseDetails.createdByUserId;
100-
const [currentWorkout, setCurrentWorkout] = useAtom(currentWorkoutAtom);
99+
const [currentWorkout, setCurrentWorkout] = useCurrentWorkout();
101100
const navigate = useNavigate();
102101
const [_a, setAddEntityToCollectionData] = useAddEntityToCollection();
103102

apps/frontend/app/routes/_dashboard.fitness.exercises.list.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import {
4949
IconFilterOff,
5050
IconPlus,
5151
} from "@tabler/icons-react";
52-
import { useAtom } from "jotai";
5352
import { z } from "zod";
5453
import { zx } from "zodix";
5554
import { DebouncedSearchInput } from "~/components/common";
@@ -59,7 +58,7 @@ import {
5958
useSearchParam,
6059
useUserCollections,
6160
} from "~/lib/hooks";
62-
import { addExerciseToWorkout, currentWorkoutAtom } from "~/lib/state/workout";
61+
import { addExerciseToWorkout, useCurrentWorkout } from "~/lib/state/workout";
6362
import {
6463
getAuthorizationHeader,
6564
serverGqlService,
@@ -144,7 +143,7 @@ export default function Page() {
144143
{ open: openFiltersModal, close: closeFiltersModal },
145144
] = useDisclosure(false);
146145

147-
const [currentWorkout, setCurrentWorkout] = useAtom(currentWorkoutAtom);
146+
const [currentWorkout, setCurrentWorkout] = useCurrentWorkout();
148147

149148
const isFilterChanged = Object.keys(defaultFiltersValue)
150149
.filter((k) => k !== "page" && k !== "query" && k !== "selectionEnabled")

0 commit comments

Comments
 (0)