Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions app/src/app/(tabs)/(session)/session/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useAppSelector, useAppSelectorWithArg } from '@/store';
import {
finishCurrentWorkout,
selectCurrentSession,
setCurrentSession,
} from '@/store/current-session';
import { useTranslate } from '@tolgee/react';
import { Stack, useRouter } from 'expo-router';
Expand All @@ -16,46 +17,38 @@ import { useDispatch } from 'react-redux';
export default function Index() {
const dispatch = useDispatch();
const session = useAppSelectorWithArg(selectCurrentSession, 'workoutSession');
const showPostWorkoutSummary = useAppSelector(
(x) => x.settings.showPostWorkoutSummary,
);
const keepAwake = useAppSelector(
(x) => x.settings.keepScreenAwakeDuringWorkout,
);
const { dismissTo, push } = useRouter();
const { dismissTo, push, replace } = useRouter();
const { t } = useTranslate();
const [confirmOpen, setConfirmOpen] = useState(false);
const [postWorkoutSessionId, setPostWorkoutSessionId] = useState<
string | undefined
>(undefined);

const save = (force = false) => {
const finishedSessionId = session?.id;
if (session) {
if (!force && !session.isComplete) {
setConfirmOpen(true);
return;
}
setConfirmOpen(false);
}
if (showPostWorkoutSummary) {
setPostWorkoutSessionId(finishedSessionId);
if (finishedSessionId) {
push(
`/session/post-workout?sessionId=${encodeURIComponent(finishedSessionId)}&source=finished`,
);
return;
}
} else {
dispatch(setCurrentSession({ target: 'historySession', session }));
dispatch(finishCurrentWorkout('workoutSession'));
dismissTo('/');
replace({
pathname: '/(tabs)/history/progress',
params: {
sessionId: session.id,
source: 'finish',
},
} as never);
return;
}
dismissTo('/');
};
useEffect(() => {
if (!session && !postWorkoutSessionId) {
if (!session) {
dismissTo('/');
}
}, [session, dismissTo, postWorkoutSessionId]);
}, [session, dismissTo]);
const showBodyweight = useAppSelector((x) => x.settings.showBodyweight);

return (
Expand All @@ -77,7 +70,7 @@ export default function Index() {
return;
}
push(
`/session/post-workout?sessionId=${encodeURIComponent(session.id)}&source=live`,
`/session/post-workout?sessionId=${encodeURIComponent(session.id)}&source=live` as never,
);
}}
saveAndClose={() => save()}
Expand Down
96 changes: 1 addition & 95 deletions app/src/app/(tabs)/(session)/session/post-workout.tsx
Original file line number Diff line number Diff line change
@@ -1,95 +1 @@
import FullHeightScrollView from '@/components/layout/full-height-scroll-view';
import FloatingBottomContainer from '@/components/presentation/foundation/floating-bottom-container';
import { SessionComparisonTable } from '@/components/presentation/workout/session-comparison-table';
import { spacing } from '@/hooks/useAppTheme';
import { useAppSelectorWithArg } from '@/store';
import {
finishCurrentWorkout,
selectCurrentSession,
} from '@/store/current-session';
import {
selectPreviousComparableSession,
selectSession,
} from '@/store/stored-sessions';
import { useTranslate } from '@tolgee/react';
import { Stack, useLocalSearchParams, useRouter } from 'expo-router';
import { useEffect } from 'react';
import { View } from 'react-native';
import { FAB } from 'react-native-paper';
import { useDispatch } from 'react-redux';

export default function PostWorkoutPage() {
const { sessionId, source } = useLocalSearchParams<{
sessionId?: string;
source?: 'finished' | 'live' | 'history';
}>();
const storedSession = useAppSelectorWithArg(selectSession, sessionId ?? '');
const currentWorkoutSession = useAppSelectorWithArg(
selectCurrentSession,
'workoutSession',
);
const session =
storedSession ??
(currentWorkoutSession?.id === sessionId
? currentWorkoutSession
: undefined);
const openedAfterFinishingWorkout = source === 'finished';
const showFinishButton = openedAfterFinishingWorkout;
const showBackButton = !openedAfterFinishingWorkout;
const previousComparableSession = useAppSelectorWithArg(
selectPreviousComparableSession,
session,
);
const { dismissTo } = useRouter();
const dispatch = useDispatch();
const { t } = useTranslate();

useEffect(() => {
if (!sessionId || !session) {
dismissTo('/session');
}
}, [dismissTo, session, sessionId]);

if (!sessionId || !session) {
return null;
}

const floatingBottomContainer = showFinishButton ? (
<FloatingBottomContainer
fab={
<FAB
onPress={() => {
dispatch(finishCurrentWorkout('workoutSession'));
dismissTo('/');
}}
icon={'check'}
label={t('generic.finish.button')}
/>
}
/>
) : undefined;

return (
<FullHeightScrollView
floatingChildren={floatingBottomContainer}
scrollStyle={{ paddingHorizontal: spacing.pageHorizontalMargin }}
>
<Stack.Screen
options={{
presentation: 'modal',
title: t('workout.post_workout.title'),
gestureEnabled: showBackButton,
headerBackVisible: showBackButton,
headerLeft: showFinishButton ? () => null : undefined!,
}}
/>
<View style={{ marginVertical: spacing[4] }}>
<SessionComparisonTable
mode="full"
previousSession={previousComparableSession}
session={session}
/>
</View>
</FullHeightScrollView>
);
}
export { default } from '@/components/smart/post-workout-page';
29 changes: 29 additions & 0 deletions app/src/app/(tabs)/history/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ export default function History() {
selectCurrentSession,
'workoutSession',
);
const openWorkoutStats = (session: Session) => {
push(
`/history/post-workout?sessionId=${encodeURIComponent(session.id)}&source=history` as never,
);
};
const openProgress = (session: Session) => {
dispatch(setCurrentSession({ target: 'historySession', session }));
push({
pathname: '/(tabs)/history/progress',
params: {
sessionId: session.id,
},
} as never);
};
const onSelectSession = (session: Session) => {
dispatch(setCurrentSession({ target: 'historySession', session }));
push('/history/edit');
Expand Down Expand Up @@ -150,6 +164,13 @@ export default function History() {
)}
renderItemActions={(session) => (
<CardActions style={{ marginTop: spacing[2] }}>
<Tooltip title={t('workout.post_workout.title')}>
<IconButton
icon={'analytics'}
mode="contained"
onPress={() => openWorkoutStats(session)}
/>
</Tooltip>
<Tooltip title={t('workout.share_workout.button')}>
<IconButton
icon={'share'}
Expand All @@ -171,6 +192,14 @@ export default function History() {
onPress={() => deleteWorkout(session)}
/>
</Tooltip>
<Button
onPress={() => openProgress(session)}
icon="analytics"
mode="contained"
testID="history-view-progress"
>
Progress
</Button>
<Button
onPress={() => onSelectSession(session)}
icon="edit"
Expand Down
88 changes: 1 addition & 87 deletions app/src/app/(tabs)/history/post-workout.tsx
Original file line number Diff line number Diff line change
@@ -1,87 +1 @@
import FullHeightScrollView from '@/components/layout/full-height-scroll-view';
import FloatingBottomContainer from '@/components/presentation/foundation/floating-bottom-container';
import { SessionComparisonTable } from '@/components/presentation/workout/session-comparison-table';
import { spacing } from '@/hooks/useAppTheme';
import { useAppSelectorWithArg } from '@/store';
import { selectCurrentSession } from '@/store/current-session';
import {
selectPreviousComparableSession,
selectSession,
} from '@/store/stored-sessions';
import { useTranslate } from '@tolgee/react';
import { Stack, useLocalSearchParams, useRouter } from 'expo-router';
import { useEffect } from 'react';
import { View } from 'react-native';
import { FAB } from 'react-native-paper';

export default function PostWorkoutPage() {
const { sessionId, source } = useLocalSearchParams<{
sessionId?: string;
source?: 'finished' | 'live' | 'history';
}>();
const storedSession = useAppSelectorWithArg(selectSession, sessionId ?? '');
const currentWorkoutSession = useAppSelectorWithArg(
selectCurrentSession,
'workoutSession',
);
const session =
storedSession ??
(currentWorkoutSession?.id === sessionId
? currentWorkoutSession
: undefined);
const openedAfterFinishingWorkout = source === 'finished';
const showFinishButton = openedAfterFinishingWorkout;
const showBackButton = !openedAfterFinishingWorkout;
const previousComparableSession = useAppSelectorWithArg(
selectPreviousComparableSession,
session,
);
const { dismissTo } = useRouter();
const { t } = useTranslate();

useEffect(() => {
if (!sessionId || !session) {
dismissTo('/session');
}
}, [dismissTo, session, sessionId]);

if (!sessionId || !session) {
return null;
}

const floatingBottomContainer = showFinishButton ? (
<FloatingBottomContainer
fab={
<FAB
onPress={() => dismissTo('/(tabs)/(session)')}
icon={'check'}
label={t('generic.finish.button')}
/>
}
/>
) : undefined;

return (
<FullHeightScrollView
floatingChildren={floatingBottomContainer}
scrollStyle={{ paddingHorizontal: spacing.pageHorizontalMargin }}
>
<Stack.Screen
options={{
presentation: 'modal',
title: t('workout.post_workout.title'),
gestureEnabled: showBackButton,
headerBackVisible: showBackButton,
headerLeft: showFinishButton ? () => null : undefined!,
}}
/>
<View style={{ marginVertical: spacing[4] }}>
<SessionComparisonTable
mode="full"
previousSession={previousComparableSession}
session={session}
/>
</View>
</FullHeightScrollView>
);
}
export { default } from '@/components/smart/post-workout-page';
Loading