1- import { APP_VERSION , RELEASE_NOTES } from '@/src/constants/config' ;
2- import { useChoosenTheme } from '@/src/constants/theme' ;
3- import { useApp } from '@/src/context/AppContext' ;
4- import { edtService } from '@/src/services/edt' ;
5- import type { NextEvent } from '@/src/types' ;
6- import { handleURL } from '@/src/utils/api' ;
7- import { haptics } from '@/src/utils/haptics' ;
8- import { NextClassWidgetInstance } from '@/src/widgets/NextClassWidget' ;
9- import BottomSheet , {
10- BottomSheetBackdrop ,
11- BottomSheetBackdropProps ,
12- BottomSheetView ,
13- } from '@gorhom/bottom-sheet' ;
14- import { useRouter } from 'expo-router' ;
15- import React , { useCallback , useEffect , useRef , useState } from 'react' ;
1+ import { useCallback , useEffect , useRef , useState } from 'react' ;
162import { Platform , StyleSheet , View } from 'react-native' ;
3+
174import {
185 ActivityIndicator ,
196 Avatar ,
7+ Badge ,
208 Button ,
219 Card ,
2210 Chip ,
@@ -26,8 +14,26 @@ import {
2614 Tooltip ,
2715 TouchableRipple ,
2816} from 'react-native-paper' ;
17+
18+ import { useRouter } from 'expo-router' ;
19+
20+ import BottomSheet , {
21+ BottomSheetBackdrop ,
22+ BottomSheetBackdropProps ,
23+ BottomSheetView ,
24+ } from '@gorhom/bottom-sheet' ;
2925import { SafeAreaView , useSafeAreaInsets } from 'react-native-safe-area-context' ;
30- import { saveAsync } from '../utils/storage' ;
26+
27+
28+ import { APP_VERSION , RELEASE_NOTES } from '@/src/constants/config' ;
29+ import { useChoosenTheme } from '@/src/constants/theme' ;
30+ import { useApp } from '@/src/context/AppContext' ;
31+ import { edtService } from '@/src/services/edt' ;
32+ import type { NextEvent } from '@/src/types' ;
33+ import { handleURL } from '@/src/utils/api' ;
34+ import { haptics } from '@/src/utils/haptics' ;
35+ import { NextClassWidgetInstance } from '@/src/widgets/NextClassWidget' ;
36+ import { getSecure , saveAsync } from '../utils/storage' ;
3137
3238const WELCOME_MESSAGES = [
3339 'Passe une excellente journée !' ,
@@ -46,19 +52,28 @@ function getRandomWelcomeMessage() {
4652
4753export default function HomeScreen ( ) {
4854 const router = useRouter ( ) ;
49- const { adeid, setCalendar, updateModalShown, setUpdateModalShown } = useApp ( ) ;
55+ const {
56+ adeid, setCalendar, setCalendarOffline,
57+ updateModalShown, setUpdateModalShown,
58+ setOnboarding
59+ } = useApp ( ) ;
5060 const theme = useChoosenTheme ( ) ;
5161 const insets = useSafeAreaInsets ( ) ;
5262
5363 const [ loading , setLoading ] = useState ( false ) ;
5464 const [ selectable , setSelectable ] = useState ( true ) ;
65+
5566 const [ nextEvent , setNextEvent ] = useState < NextEvent > ( {
5667 summary : 'Chargement...' ,
5768 location : 'Chargement...' ,
5869 } ) ;
5970 const [ nextEventLoaded , setNextEventLoaded ] = useState ( false ) ;
71+
6072 const [ infoTitle , setInfoTitle ] = useState ( 'Informations' ) ;
6173 const [ infoSubtitle , setInfoSubtitle ] = useState ( '' ) ;
74+
75+ const isDemo = ! adeid || adeid === 'demo' ;
76+
6277 const [ welcomeMessage ] = useState ( getRandomWelcomeMessage ) ;
6378
6479 const bottomSheetInfoRef = useRef < BottomSheet > ( null ) ;
@@ -78,8 +93,13 @@ export default function HomeScreen() {
7893 ) ;
7994
8095 useEffect ( ( ) => {
96+ setOnboarding ( false ) ;
97+ if ( ! isDemo ) {
8198 getNextEvent ( 'normal' ) ;
8299 if ( Platform . OS === 'ios' ) pushWidgetTimeline ( ) ;
100+ }
101+
102+
83103
84104 // check in app context if update modal has been shown, if not show it and set it to true
85105 if ( ! updateModalShown ) {
@@ -98,6 +118,7 @@ export default function HomeScreen() {
98118 }
99119
100120 async function getNextEvent ( mode : 'normal' | 'force' ) {
121+ if ( isDemo ) return ;
101122 if ( mode === 'force' ) {
102123 setNextEvent ( { summary : 'Chargement...' , location : 'Chargement...' } ) ;
103124 }
@@ -113,11 +134,14 @@ export default function HomeScreen() {
113134 setSelectable ( false ) ;
114135 setLoading ( true ) ;
115136
116- const cal = await edtService . getEDT ( adeid ?? 'demo' ) ;
117- setCalendar ( cal ) ;
137+ const { events, offline } = await edtService . getEDT ( adeid ?? 'demo' ) ;
138+ setCalendar ( events ) ;
139+ setCalendarOffline ( offline ) ;
118140 if ( Platform . OS === 'ios' ) {
119141 try {
120- NextClassWidgetInstance . updateTimeline ( edtService . buildWidgetTimeline ( cal ) ) ;
142+ NextClassWidgetInstance . updateTimeline (
143+ edtService . buildWidgetTimeline ( events )
144+ ) ;
121145 } catch { }
122146 }
123147
@@ -128,7 +152,7 @@ export default function HomeScreen() {
128152
129153 async function pushWidgetTimeline ( ) {
130154 try {
131- const events = await edtService . getEDT ( adeid ?? 'demo' ) ;
155+ const { events } = await edtService . getEDT ( adeid ?? 'demo' ) ;
132156 const timeline = edtService . buildWidgetTimeline ( events ) ;
133157 NextClassWidgetInstance . updateTimeline ( timeline ) ;
134158 } catch {
@@ -180,17 +204,27 @@ export default function HomeScreen() {
180204 { welcomeMessage }
181205 </ Text >
182206
183- < Card style = { { marginBottom : 8 } } disabled = { ! selectable } onPress = { getMyCal } >
184- < Card . Title title = "Prochain Cours" />
207+ < Card
208+ style = { { marginBottom : 8 } }
209+ disabled = { ! selectable }
210+ onPress = { isDemo ? ( ) => router . push ( '/edt-config' ) : getMyCal }
211+ >
212+ < Card . Title title = { isDemo ? 'Emploi du temps' : 'Prochain Cours' } />
185213 < Card . Content >
186214 < Text variant = "titleLarge" numberOfLines = { 1 } >
187- { nextEvent . summary }
215+ { isDemo ? 'Non configuré' : nextEvent . summary }
188216 </ Text >
189217 < Text variant = "bodyMedium" numberOfLines = { 1 } >
190- { nextEvent . location || "Salle non précisée" }
218+ { isDemo ? "Appuyez pour choisir votre emploi du temps" : ( nextEvent . location || "Salle non précisée" ) }
191219 </ Text >
192220 </ Card . Content >
193221 < Card . Actions >
222+ { isDemo && (
223+ < Chip disabled = { ! selectable } onPress = { ( ) => router . push ( '/edt-config' ) } icon = "calendar-edit" >
224+ Configurer l'EDT
225+ </ Chip >
226+ ) }
227+ { ! isDemo && (
194228 < Chip
195229 style = { { marginRight : 4 } }
196230 disabled = { ! selectable }
@@ -199,14 +233,17 @@ export default function HomeScreen() {
199233 >
200234 Rafraîchir
201235 </ Chip >
202- { nextEvent . summary !== 'ADE Indisponible' ? (
236+ ) }
237+ { ! isDemo && (
238+ nextEvent . summary !== 'ADE Indisponible' ? (
203239 < Chip disabled = { ! selectable } onPress = { getMyCal } icon = "calendar" >
204240 Emploi du temps
205241 </ Chip >
206242 ) : (
207243 < Chip disabled = { ! selectable } onPress = { getMyCal } icon = "calendar-alert" >
208244 EDT (Hors-ligne)
209245 </ Chip >
246+ )
210247 ) }
211248 </ Card . Actions >
212249 </ Card >
@@ -292,4 +329,4 @@ export default function HomeScreen() {
292329 </ BottomSheet >
293330 </ View >
294331 ) ;
295- }
332+ }
0 commit comments