1
1
mirror of https://github.com/theoludwig/p61-project.git synced 2024-07-17 07:00:12 +02:00

refactor: app routes handling

This commit is contained in:
Théo LUDWIG 2024-03-23 01:43:27 +01:00
parent ce3b5e7b58
commit 305ad640fa
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B
34 changed files with 30 additions and 166 deletions

View File

@ -1,7 +0,0 @@
import { Slot } from "expo-router"
const Layout: React.FC = () => {
return <Slot />
}
export default Layout

View File

@ -43,9 +43,7 @@ const StackLayout: React.FC = () => {
screenOptions={{ screenOptions={{
headerShown: false, headerShown: false,
}} }}
> />
<Stack.Screen name="(pages)" />
</Stack>
) )
} }

View File

@ -8,7 +8,7 @@ const TabLayout: React.FC = () => {
const { user } = useAuthentication() const { user } = useAuthentication()
if (user == null) { if (user == null) {
return <Redirect href="/(pages)/authentication/login" /> return <Redirect href="/authentication/login" />
} }
return ( return (

View File

@ -8,7 +8,7 @@ const TabLayout: React.FC = () => {
const { user } = useAuthentication() const { user } = useAuthentication()
if (user != null) { if (user != null) {
return <Redirect href="/(pages)/application/habits" /> return <Redirect href="/application/habits/" />
} }
return ( return (

View File

@ -6,10 +6,10 @@ const HomePage: React.FC = () => {
const { user } = useAuthentication() const { user } = useAuthentication()
if (user == null) { if (user == null) {
return <Redirect href="/(pages)/authentication/login" /> return <Redirect href="/authentication/login" />
} }
return <Redirect href="/(pages)/application/habits" /> return <Redirect href="/application/habits/" />
} }
export default HomePage export default HomePage

View File

@ -14,6 +14,9 @@ npm run lint:typescript
# Test # Test
npm run test npm run test
# Test Snapshots Update
npm run test -- --u
``` ```
Une pipeline CI ([`.gitlab-ci.yml`](../.gitlab-ci.yml)) est en place pour vérifier que le code respecte ces bonnes pratiques et que les tests passent. Une pipeline CI ([`.gitlab-ci.yml`](../.gitlab-ci.yml)) est en place pour vérifier que le code respecte ces bonnes pratiques et que les tests passent.

View File

@ -1,10 +1,10 @@
import { AuthenticationUseCase } from "@/domain/use-cases/Authentication" import { AuthenticationUseCase } from "@/domain/use-cases/Authentication"
import { RetrieveHabitsTrackerUseCase } from "../domain/use-cases/RetrieveHabitsTracker" import { RetrieveHabitsTrackerUseCase } from "../domain/use-cases/RetrieveHabitsTracker"
import { HabitsTrackerPresenter } from "../presentation/presenters/HabitsTracker" import { HabitsTrackerPresenter } from "../presentation/presenters/HabitsTracker"
import { AuthenticationSupabaseRepository } from "./repositories/supabase/lib/AuthenticationRepository" import { AuthenticationSupabaseRepository } from "./supabase/repositories/Authentication"
import { GetHabitProgressHistorySupabaseRepository } from "./repositories/supabase/lib/GetHabitProgressHistory" import { GetHabitProgressHistorySupabaseRepository } from "./supabase/repositories/GetHabitProgressHistory"
import { GetHabitsByUserIdSupabaseRepository } from "./repositories/supabase/lib/GetHabitsByUserId" import { GetHabitsByUserIdSupabaseRepository } from "./supabase/repositories/GetHabitsByUserId"
import { supabaseClient } from "./repositories/supabase/supabase" import { supabaseClient } from "./supabase/supabase"
import { AuthenticationPresenter } from "@/presentation/presenters/Authentication" import { AuthenticationPresenter } from "@/presentation/presenters/Authentication"
/** /**

View File

@ -15,7 +15,7 @@
"lint:typescript": "tsc --noEmit", "lint:typescript": "tsc --noEmit",
"lint:staged": "lint-staged", "lint:staged": "lint-staged",
"test": "jest --reporters=default --reporters=jest-junit", "test": "jest --reporters=default --reporters=jest-junit",
"supabase": "supabase --workdir \"./infrastructure/repositories\"", "supabase": "supabase --workdir \"./infrastructure\"",
"postinstall": "husky" "postinstall": "husky"
}, },
"dependencies": { "dependencies": {

View File

@ -1,34 +0,0 @@
import type { StyleProp, ViewStyle } from "react-native"
import { Pressable, StyleSheet, Text } from "react-native"
export interface ButtonCustomProps
extends React.ComponentProps<typeof Pressable> {
children: React.ReactNode
style?: StyleProp<ViewStyle>
}
export const ButtonCustom: React.FC<ButtonCustomProps> = (props) => {
const { children, style, ...rest } = props
return (
<Pressable style={[styles.button, style]} {...rest}>
<Text style={styles.text}>{children}</Text>
</Pressable>
)
}
const styles = StyleSheet.create({
button: {
padding: 10,
borderWidth: 1,
borderColor: "black",
borderRadius: 10,
marginTop: 10,
backgroundColor: "#152B5D",
},
text: {
color: "white",
textAlign: "center",
fontSize: 15,
},
})

View File

@ -1,13 +0,0 @@
import { StyleSheet, Text } from "react-native"
export const MonoText: React.FC<Text["props"]> = (props) => {
const { style, ...rest } = props
return <Text style={[style, styles.text]} {...rest} />
}
const styles = StyleSheet.create({
text: {
fontFamily: "SpaceMono",
},
})

View File

@ -1,12 +0,0 @@
import renderer from "react-test-renderer"
import { ButtonCustom } from "@/presentation/react/components/ButtonCustom"
describe("<ButtonCustom />", () => {
it("renders correctly", () => {
const tree = renderer
.create(<ButtonCustom>Awesome Button!</ButtonCustom>)
.toJSON()
expect(tree).toMatchSnapshot()
})
})

View File

@ -1,10 +0,0 @@
import renderer from "react-test-renderer"
import { MonoText } from "@/presentation/react/components/MonoText"
describe("<MonoText />", () => {
it("renders correctly", () => {
const tree = renderer.create(<MonoText>Awesome text!</MonoText>).toJSON()
expect(tree).toMatchSnapshot()
})
})

View File

@ -0,0 +1,12 @@
import renderer from "react-test-renderer"
import { TabBarIcon } from "@/presentation/react/components/TabBarIcon"
describe("<TabBarIcon />", () => {
it("renders correctly", () => {
const tree = renderer
.create(<TabBarIcon name="info" color="black" />)
.toJSON()
expect(tree).toMatchSnapshot()
})
})

View File

@ -1,60 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<ButtonCustom /> renders correctly 1`] = `
<View
accessibilityState={
{
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessibilityValue={
{
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
collapsable={false}
focusable={true}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
[
{
"backgroundColor": "#152B5D",
"borderColor": "black",
"borderRadius": 10,
"borderWidth": 1,
"marginTop": 10,
"padding": 10,
},
undefined,
]
}
>
<Text
style={
{
"color": "white",
"fontSize": 15,
"textAlign": "center",
}
}
>
Awesome Button!
</Text>
</View>
`;

View File

@ -1,16 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<MonoText /> renders correctly 1`] = `
<Text
style={
[
undefined,
{
"fontFamily": "SpaceMono",
},
]
}
>
Awesome text!
</Text>
`;

View File

@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<TabBarIcon /> renders correctly 1`] = `<Text />`;

View File

@ -5,7 +5,7 @@ import type {
AuthenticationPresenter, AuthenticationPresenter,
AuthenticationPresenterState, AuthenticationPresenterState,
} from "@/presentation/presenters/Authentication" } from "@/presentation/presenters/Authentication"
import { authenticationPresenter } from "@/infrastructure" import { authenticationPresenter } from "@/infrastructure/instances"
export interface AuthenticationContextValue export interface AuthenticationContextValue
extends AuthenticationPresenterState { extends AuthenticationPresenterState {

View File

@ -5,7 +5,7 @@ import type {
HabitsTrackerPresenterState, HabitsTrackerPresenterState,
} from "@/presentation/presenters/HabitsTracker" } from "@/presentation/presenters/HabitsTracker"
import { usePresenterState } from "@/presentation/react/hooks/usePresenterState" import { usePresenterState } from "@/presentation/react/hooks/usePresenterState"
import { habitsTrackerPresenter } from "@/infrastructure" import { habitsTrackerPresenter } from "@/infrastructure/instances"
import { useAuthentication } from "./Authentication" import { useAuthentication } from "./Authentication"
export interface HabitsTrackerContextValue extends HabitsTrackerPresenterState { export interface HabitsTrackerContextValue extends HabitsTrackerPresenterState {