Skip to content

Commit f1984a9

Browse files
committed
Add empty state
1 parent 5dc6785 commit f1984a9

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

liftlog-react/app/(tabs)/history/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import CardList from '@/components/presentation/card-list';
2+
import EmptyInfo from '@/components/presentation/empty-info';
23
import FullHeightScrollView from '@/components/presentation/full-height-scroll-view';
34
import HistoryCalendarCard from '@/components/presentation/history-calendar-card';
5+
import LimitedHtml from '@/components/presentation/limited-html';
46
import SessionSummary from '@/components/presentation/session-summary';
57
import SessionSummaryTitle from '@/components/presentation/session-summary-title';
68
import SplitCardControl from '@/components/presentation/split-card-control';
@@ -10,6 +12,7 @@ import {
1012
selectSessions,
1113
selectSessionsInMonth,
1214
} from '@/store/stored-sessions';
15+
import { formatDate } from '@/utils/format-date';
1316
import { YearMonth } from '@js-joda/core';
1417
import { useTranslate } from '@tolgee/react';
1518
import { Stack } from 'expo-router';
@@ -54,6 +57,15 @@ export default function History() {
5457
}
5558
/>
5659
)}
60+
emptyTemplate={
61+
<EmptyInfo>
62+
<LimitedHtml
63+
value={t('NoSessionsInMonth{Month}', {
64+
0: formatDate(currentYearMonth.atDay(1), { month: 'long' }),
65+
})}
66+
/>
67+
</EmptyInfo>
68+
}
5769
/>
5870
</FullHeightScrollView>
5971
</>

liftlog-react/components/presentation/card-list.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface CardListProps<T> extends ViewProps {
1212
cardStyle?: CardProps['style'];
1313
cardType: 'elevated' | 'outlined' | 'contained';
1414
keySelector?: (item: T) => Key;
15+
emptyTemplate?: ReactNode;
1516
}
1617

1718
export default function CardList<T>(props: CardListProps<T>) {
@@ -24,6 +25,7 @@ export default function CardList<T>(props: CardListProps<T>) {
2425
cardStyle,
2526
cardType,
2627
keySelector,
28+
emptyTemplate,
2729
...rest
2830
} = props;
2931
return (
@@ -33,10 +35,12 @@ export default function CardList<T>(props: CardListProps<T>) {
3335
{
3436
gap: spacing[2],
3537
padding: spacing[2],
38+
flex: 1,
3639
},
3740
rest['style'],
3841
]}
3942
>
43+
{!!items.length || emptyTemplate}
4044
{items.map((item, i) => (
4145
<Card
4246
key={keySelector?.(item) ?? i}

liftlog-react/components/presentation/history-calendar-card.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { SurfaceText } from '@/components/presentation/surface-text';
22
import { spacing, useAppTheme } from '@/hooks/useAppTheme';
33
import { Session } from '@/models/session-models';
44
import { useAppSelector } from '@/store';
5+
import { formatDate } from '@/utils/format-date';
56
import { LocalDate, Year, YearMonth } from '@js-joda/core';
67
import Enumerable from 'linq';
78
import { View } from 'react-native';
@@ -250,14 +251,6 @@ function HistoryCalendarDay(props: {
250251
);
251252
}
252253

253-
function formatDate(date: LocalDate, opts: Intl.DateTimeFormatOptions) {
254-
return new Date(
255-
date.year(),
256-
date.month().ordinal(),
257-
date.dayOfMonth(),
258-
).toLocaleString('default', opts);
259-
}
260-
261254
function getDateOnDay(dayOfWeek: number) {
262255
// Super gross and hacky, but then we get i18n formatting for free
263256
const constantSundayDay = LocalDate.of(2025, 5, 4);

liftlog-react/utils/format-date.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { LocalDate } from '@js-joda/core';
2+
3+
export function formatDate(date: LocalDate, opts: Intl.DateTimeFormatOptions) {
4+
return new Date(
5+
date.year(),
6+
date.month().ordinal(),
7+
date.dayOfMonth(),
8+
).toLocaleString('default', opts);
9+
}

0 commit comments

Comments
 (0)