-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: Setup boilerplate for the home screen #14 #35
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,72 @@ | ||
import { Button } from "react-native-paper"; | ||
import { useRouter } from "expo-router"; | ||
import { FlatList, StyleSheet } from "react-native"; | ||
import { FAB } from "react-native-paper"; | ||
|
||
import { actions, ActionKey } from "@/common/actions"; | ||
import { useI18n } from "@/common/i18n"; | ||
import { useIdentity, RedirectIfNoProfile } from "@/common/identity"; | ||
import { MonoText } from "@/components/StyledText"; | ||
import { DashboardGadget } from "@/components/DashboardGadget"; | ||
import { Header } from "@/components/Header"; | ||
import { View } from "@/components/Themed"; | ||
|
||
const mockDashboardGadgets: ActionKey[] = [ | ||
"logOut", | ||
"profileList", | ||
"profileList", | ||
"logOut", | ||
"logOut", | ||
"profileList", | ||
]; | ||
|
||
const Page = () => { | ||
const { t } = useI18n(); | ||
const identity = useIdentity(); | ||
const router = useRouter(); | ||
|
||
if (!identity.hasProfile) { | ||
return <RedirectIfNoProfile identity={identity} />; | ||
} | ||
|
||
const ctx = { identity, router }; | ||
|
||
return ( | ||
<View> | ||
{/* TODO: This shouldn't be here */} | ||
<MonoText>{JSON.stringify(identity.profile, null, 2)}</MonoText> | ||
<Button onPress={() => identity.logOut()}>LOG OUT</Button> | ||
<View style={styles.container}> | ||
<Header | ||
left={{ icon: "menu", onPress: () => router.push("/menu") }} | ||
title={t("dashboard.pageTitle")} | ||
/> | ||
<FlatList | ||
data={mockDashboardGadgets} | ||
numColumns={2} | ||
renderItem={({ item }) => ( | ||
<DashboardGadget action={actions[item]} ctx={ctx} /> | ||
)} | ||
style={styles.list} | ||
/> | ||
<FAB | ||
icon="alarm-light" | ||
style={styles.fab} | ||
onPress={() => { | ||
/* TODO */ | ||
}} | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
}, | ||
list: { | ||
padding: 8, | ||
}, | ||
fab: { | ||
position: "absolute", | ||
bottom: 32, | ||
right: 32, | ||
backgroundColor: "#991b1b", | ||
}, | ||
}); | ||
|
||
export default Page; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { Link, Stack } from "expo-router"; | ||
import { Link } from "expo-router"; | ||
import { StyleSheet, View } from "react-native"; | ||
import { ActivityIndicator, Button, Text } from "react-native-paper"; | ||
|
||
import { BASE_URL, useApi } from "@/common/api"; | ||
import { useI18n } from "@/common/i18n"; | ||
import { useIdentity, RedirectIfLoggedIn } from "@/common/identity"; | ||
import { Header } from "@/components/Header"; | ||
import { MonoText } from "@/components/StyledText"; | ||
|
||
const HEALTHZ_PATH = "/api/v1/healthz"; | ||
|
||
export const Landing = ({ debug = false }: { debug?: boolean }) => { | ||
const { data, isLoading, error, mutate } = useApi({ | ||
url: "/api/v1/healthz", | ||
url: HEALTHZ_PATH, | ||
}); | ||
const { t } = useI18n(); | ||
const identity = useIdentity(); | ||
|
@@ -34,7 +37,7 @@ export const Landing = ({ debug = false }: { debug?: boolean }) => { | |
{debug ? ( | ||
<> | ||
<MonoText style={styles.debug}> | ||
{new URL("/healthz", BASE_URL).toString()} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was broken after the API change 😨 |
||
{new URL(HEALTHZ_PATH, BASE_URL).toString()} | ||
{"\n"} | ||
{JSON.stringify(data)} | ||
{"\n"} | ||
|
@@ -72,7 +75,7 @@ const Page = () => { | |
const { t } = useI18n(); | ||
return ( | ||
<View style={styles.container}> | ||
<Stack.Screen options={{ title: t("landing.pageTitle") }} /> | ||
<Header title={t("landing.pageTitle")} /> | ||
<Landing debug={__DEV__} /> | ||
</View> | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useRouter } from "expo-router"; | ||
import { ScrollView, StyleSheet } from "react-native"; | ||
import { Banner, List, MD3Theme, useTheme, Text } from "react-native-paper"; | ||
|
||
import { actions } from "@/common/actions"; | ||
import { useI18n } from "@/common/i18n"; | ||
import { | ||
useIdentity, | ||
RedirectIfNoProfile, | ||
isCaretaker, | ||
} from "@/common/identity"; | ||
import { Header } from "@/components/Header"; | ||
import { MenuItem } from "@/components/MenuItem"; | ||
import { View } from "@/components/Themed"; | ||
|
||
const Page = () => { | ||
const { t } = useI18n(); | ||
const router = useRouter(); | ||
const identity = useIdentity(); | ||
const theme = useTheme(); | ||
const styles = makeStyles(theme); | ||
|
||
if (!identity.hasProfile) { | ||
return <RedirectIfNoProfile identity={identity} />; | ||
} | ||
|
||
const ctx = { identity, router }; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Header left="back" title={t("menu.pageTitle")} /> | ||
{isCaretaker(identity.profile) ? ( | ||
<Banner visible style={styles.banner}> | ||
<Text style={styles.bannerText}> | ||
{t("menu.caretakerBanner", { alias: identity.profile.seniorAlias })} | ||
</Text> | ||
</Banner> | ||
) : null} | ||
<ScrollView> | ||
<List.Section> | ||
<List.Subheader>{t("menu.account")}</List.Subheader> | ||
<MenuItem action={actions.profileList} ctx={ctx} /> | ||
<MenuItem action={actions.logOut} ctx={ctx} /> | ||
</List.Section> | ||
</ScrollView> | ||
</View> | ||
); | ||
}; | ||
|
||
const makeStyles = (theme: MD3Theme) => | ||
StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
}, | ||
banner: { | ||
backgroundColor: theme.colors.primary, | ||
paddingBottom: 8, | ||
}, | ||
bannerText: { | ||
color: theme.colors.onPrimary, | ||
}, | ||
}); | ||
|
||
export default Page; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { actions, type ActionKey } from "./list"; | ||
export type { Action, ActionContext } from "./types"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { Action } from "./types"; | ||
|
||
export const actions = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: #36 |
||
profileList: { | ||
displayName: (t) => t("actions.profileList"), | ||
icon: "account-switch", | ||
handler: ({ router }) => router.push("/profile/list"), | ||
}, | ||
logOut: { | ||
displayName: (t) => t("actions.logOut"), | ||
icon: "account-arrow-right", | ||
handler: ({ identity }) => identity.logOut(), | ||
}, | ||
} satisfies Record<string, Action>; | ||
|
||
export type ActionKey = keyof typeof actions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { useRouter } from "expo-router"; | ||
import type { ComponentProps } from "react"; | ||
import type { IconButton } from "react-native-paper"; | ||
|
||
import type { Translator } from "../i18n"; | ||
import type { IdentityProfileKnown } from "../identity/types"; | ||
|
||
type IconSource = ComponentProps<typeof IconButton>["icon"]; | ||
type Router = ReturnType<typeof useRouter>; | ||
|
||
export type ActionContext = { | ||
identity: IdentityProfileKnown; | ||
router: Router; | ||
}; | ||
|
||
export type Action = { | ||
displayName: (t: Translator) => string; | ||
icon: IconSource; | ||
handler: (ctx: ActionContext) => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Placeholder - this will be downloaded from the backend.