Skip to content

Commit

Permalink
Show correct day names on dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandgeider committed Jan 18, 2025
1 parent d0e7c6a commit e5f28e2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
19 changes: 12 additions & 7 deletions src/components/Dashboard/RoutineCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@mui/material';
import { LoadingPlaceholder } from "components/Core/LoadingWidget/LoadingWidget";
import { EmptyCard } from "components/Dashboard/EmptyCard";
import { getDayName } from "components/WorkoutRoutines/models/Day";
import { Routine } from "components/WorkoutRoutines/models/Routine";
import { RoutineDayData } from "components/WorkoutRoutines/models/RoutineDayData";
import { useActiveRoutineQuery } from "components/WorkoutRoutines/queries";
Expand Down Expand Up @@ -50,7 +51,8 @@ const RoutineCardContent = (props: { routine: Routine }) => {
{/* Note: not 500 like the other cards, but a bit more since we don't have an action icon... */}
<CardContent sx={{ height: "510px", overflow: "auto" }}>
<List>
{props.routine.dayDataCurrentIteration.map((day, index) => <DayListItem dayData={day} key={index} />)}
{props.routine.dayDataCurrentIteration.map((day, index) =>
<DayListItem dayData={day} key={index} />)}
</List>
</CardContent>

Expand All @@ -65,26 +67,29 @@ const RoutineCardContent = (props: { routine: Routine }) => {

const DayListItem = (props: { dayData: RoutineDayData }) => {
const [expandView, setExpandView] = useState(false);
const [t] = useTranslation();

const { t } = useTranslation();

const handleToggleExpand = () => setExpandView(!expandView);

return (<>
<ListItemButton onClick={handleToggleExpand} selected={expandView} disabled={props.dayData.day?.isRest}>
<ListItemButton
onClick={handleToggleExpand}
selected={expandView}
disabled={props.dayData.day === null || props.dayData.day?.isRest}
>
<ListItemIcon>
{expandView ? <ExpandLessIcon /> : <ExpandMoreIcon />}
</ListItemIcon>
<ListItemText
primary={props.dayData.day?.getDisplayName()}
primary={getDayName(props.dayData.day)}
/>
</ListItemButton>

<Collapse in={expandView} timeout="auto" unmountOnExit>
{props.dayData.slots.map((slotData, index) => (<div key={index}>
{slotData.setConfigs.map((setting, index) =>
{slotData.setConfigs.map((setConfigData, index) =>
<SetConfigDataDetails
setConfigData={setting}
setConfigData={setConfigData}
key={index}
rowHeight={'70px'}
showExercise={true}
Expand Down
2 changes: 1 addition & 1 deletion src/components/WorkoutRoutines/Detail/RoutineDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const RoutineDetail = () => {
}

{routine!.dayDataCurrentIteration.filter((dayData) => dayData.day !== null).map((dayData, index) =>
<DayDetailsCard routineId={routineId} dayData={dayData} key={`dayDetails-${index}`} />
<DayDetailsCard routineId={routineId} dayData={dayData} key={index} />
)}
</Stack>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ export const RoutineTable = (props: { routine: Routine, showLogs?: boolean }) =>
</React.Fragment>;
})}
</React.Fragment>;

})}
</>;
}
Expand Down
8 changes: 6 additions & 2 deletions src/components/WorkoutRoutines/Detail/TemplateDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ export const TemplateDetail = () => {
>{t('routines.copyAndUseTemplate')}</Button>

{routine!.dayDataCurrentIteration.filter((dayData) => dayData.day !== null).map((dayData, index) =>
<DayDetailsCard dayData={dayData} routineId={routineId} readOnly={true}
key={`dayDetails-${index}`} />
<DayDetailsCard
dayData={dayData}
routineId={routineId}
readOnly={true}
key={`dayDetails-${index}`}
/>
)}
</Stack>
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/WorkoutRoutines/models/Day.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export class Day {

}

export const getDayName = (day: Day | null): string => day === null || day.isRest ? i18n.t('routines.restDay') : day.getDisplayName();


export class DayAdapter implements Adapter<Day> {
fromJson = (item: any): Day => new Day({
Expand Down
7 changes: 4 additions & 3 deletions src/components/WorkoutRoutines/widgets/RoutineDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { RenderLoadingQuery } from "components/Core/Widgets/RenderLoadingQuery";
import { ExerciseImageAvatar } from "components/Exercises/Detail/ExerciseImageAvatar";
import { Language } from "components/Exercises/models/language";
import { useLanguageQuery } from "components/Exercises/queries";
import { getDayName } from "components/WorkoutRoutines/models/Day";
import { RoutineDayData } from "components/WorkoutRoutines/models/RoutineDayData";
import { SetConfigData } from "components/WorkoutRoutines/models/SetConfigData";
import { SlotData } from "components/WorkoutRoutines/models/SlotData";
Expand Down Expand Up @@ -146,7 +147,7 @@ function SlotDataList(props: {
}

export const DayDetailsCard = (props: { dayData: RoutineDayData, routineId: number, readOnly?: boolean }) => {
const readOnly = props.readOnly ?? false;
const readOnly = (props.readOnly ?? false) || props.dayData.day === null || props.dayData.day.isRest;

const theme = useTheme();

Expand All @@ -168,7 +169,7 @@ export const DayDetailsCard = (props: { dayData: RoutineDayData, routineId: numb
<Card sx={{ minWidth: 275 }}>
<CardHeader
sx={{ bgcolor: theme.palette.grey.A200 }}
action={props.dayData.day!.isRest || readOnly
action={props.dayData.day === null || props.dayData.day.isRest || readOnly
? null
: <Tooltip title={t('routines.addWeightLog')}>
<IconButton
Expand All @@ -179,7 +180,7 @@ export const DayDetailsCard = (props: { dayData: RoutineDayData, routineId: numb
<Addchart />
</IconButton>
</Tooltip>}
title={props.dayData.day!.getDisplayName()}
title={getDayName(props.dayData.day)}
subheader={props.dayData.day?.description}
/>
<Menu
Expand Down

0 comments on commit e5f28e2

Please sign in to comment.