Skip to content

Commit

Permalink
fix(frontend): allow adding exercises to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Nov 1, 2024
1 parent 9987e68 commit b844713
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions apps/frontend/app/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ export const useComplexJsonUpdate = () => {
return { reset, appendPref, toUpdatePreferences };
};

export const useIsWorkoutActive = () => {
export const useIsFitnessActionActive = () => {
const [currentWorkout] = useCurrentWorkout();
const action = currentWorkout?.currentActionOrCompleted;
return (
action !== undefined &&
action !== true &&
[FitnessAction.LogWorkout, FitnessAction.UpdateWorkout].includes(action)
[FitnessAction.LogWorkout, FitnessAction.CreateTemplate].includes(action)
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import {
} from "~/lib/generals";
import {
useComplexJsonUpdate,
useIsWorkoutActive,
useIsFitnessActionActive,
useUserDetails,
useUserPreferences,
useUserUnitSystem,
Expand Down Expand Up @@ -171,7 +171,7 @@ export default function Page() {
loaderData.userExerciseDetails.details?.exerciseNumTimesInteracted || 0;
const [currentWorkout, setCurrentWorkout] = useCurrentWorkout();
const navigate = useNavigate();
const isWorkoutActive = useIsWorkoutActive();
const isFitnessActionActive = useIsFitnessActionActive();
const [_a, setAddEntityToCollectionData] = useAddEntityToCollection();
const [timeSpanForCharts, setTimeSpanForCharts] = useLocalStorage(
"ExerciseChartTimeSpan",
Expand Down Expand Up @@ -635,7 +635,7 @@ export default function Page() {
) : null}
</Tabs>
</Stack>
{currentWorkout && isWorkoutActive ? (
{currentWorkout && isFitnessActionActive ? (
<Affix position={{ bottom: rem(40), right: rem(30) }}>
<ActionIcon
color="blue"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { DebouncedSearchInput, FiltersModal } from "~/components/common";
import { dayjsLib, pageQueryParam } from "~/lib/generals";
import {
useAppSearchParam,
useIsWorkoutActive,
useIsFitnessActionActive,
useUserCollections,
useUserPreferences,
} from "~/lib/hooks";
Expand Down Expand Up @@ -138,7 +138,7 @@ export default function Page() {
const navigate = useNavigate();
const userPreferences = useUserPreferences();
const [currentWorkout, setCurrentWorkout] = useCurrentWorkout();
const isWorkoutActive = useIsWorkoutActive();
const isFitnessActionActive = useIsFitnessActionActive();
const [_, { setP }] = useAppSearchParam(loaderData.cookieName);
const [selectedExercises, setSelectedExercises] = useListState<{
name: string;
Expand All @@ -158,7 +158,7 @@ export default function Page() {

const allowAddingExerciseToWorkout =
currentWorkout &&
isWorkoutActive &&
isFitnessActionActive &&
!isNumber(currentWorkout.replacingExerciseIdx);

return (
Expand Down
6 changes: 3 additions & 3 deletions apps/frontend/app/routes/_dashboard.settings.preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import {
useComplexJsonUpdate,
useConfirmSubmit,
useDashboardLayoutData,
useIsWorkoutActive,
useIsFitnessActionActive,
useUserPreferences,
} from "~/lib/hooks";
import {
Expand Down Expand Up @@ -130,7 +130,7 @@ export default function Page() {
const loaderData = useLoaderData<typeof loader>();
const userPreferences = useUserPreferences();
const submit = useConfirmSubmit();
const isWorkoutActive = useIsWorkoutActive();
const isFitnessActionActive = useIsFitnessActionActive();
const [watchProviders, setWatchProviders] = useState(
userPreferences.general.watchProviders.map((wp) => ({
...wp,
Expand All @@ -153,7 +153,7 @@ export default function Page() {
<Affix
position={{
bottom: rem(45),
right: rem(isWorkoutActive ? 100 : 40),
right: rem(isFitnessActionActive ? 100 : 40),
}}
>
<Form
Expand Down
6 changes: 3 additions & 3 deletions apps/frontend/app/routes/_dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ import {
useConfirmSubmit,
useCoreDetails,
useGetWatchProviders,
useIsWorkoutActive,
useIsFitnessActionActive,
useMetadataDetails,
useUserCollections,
useUserDetails,
Expand Down Expand Up @@ -346,7 +346,7 @@ export default function Layout() {
const userDetails = useUserDetails();
const [parent] = useAutoAnimate();
const submit = useConfirmSubmit();
const isWorkoutActive = useIsWorkoutActive();
const isFitnessActionActive = useIsFitnessActionActive();
const [openedLinkGroups, setOpenedLinkGroups] = useLocalStorage<
| {
media: boolean;
Expand Down Expand Up @@ -400,7 +400,7 @@ export default function Layout() {

return (
<>
{isWorkoutActive &&
{isFitnessActionActive &&
!Object.values(FitnessAction)
.map((action) => $path("/fitness/:action", { action }))
.includes(location.pathname) ? (
Expand Down

0 comments on commit b844713

Please sign in to comment.