Skip to content
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

fix(Lessons): sélection d'une date non fonctionnel #322

Closed
wants to merge 3 commits into from
Closed
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
7 changes: 4 additions & 3 deletions src/views/account/Lessons/Lessons.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useEffect, useRef, useState } from "react";
import { FlatList, View, Dimensions, ViewToken } from "react-native";
import { Button, StyleSheet } from "react-native";
import { StyleSheet } from "react-native";
import type { Screen } from "@/router/helpers/types";
import { useCurrentAccount } from "@/stores/account";
import { useTimetableStore } from "@/stores/timetable";
Expand Down Expand Up @@ -49,14 +49,14 @@ const Lessons: Screen<"Lessons"> = ({ route, navigation }) => {
const today = new Date();
today.setHours(0, 0, 0, 0);

const [pickerDate, setPickerDate] = React.useState(new Date(today));
const [pickerDate, setPickerDate] = useState(new Date(today));

const getWeekFromDate = (date: Date) => {
const epochWeekNumber = dateToEpochWeekNumber(date);
return epochWeekNumber;
};

const [updatedWeeks, setUpdatedWeeks] = React.useState(new Set<number>());
const [updatedWeeks, setUpdatedWeeks] = useState(new Set<number>());

useEffect(() => {
void (async () => {
Expand Down Expand Up @@ -124,6 +124,7 @@ const Lessons: Screen<"Lessons"> = ({ route, navigation }) => {
return Array.from({ length: 100 }, (_, i) => {
const date = new Date(today);
date.setDate(today.getDate() - 50 + i);
date.setHours(0, 0, 0, 0);
return date;
});
});
Expand Down
51 changes: 23 additions & 28 deletions src/views/account/Lessons/LessonsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ import { useTheme } from "@react-navigation/native";
import React from "react";
import { Dimensions, Modal, Platform, Pressable, Text, TouchableOpacity, View } from "react-native";

import { Calendar, X } from "lucide-react-native";
import { X } from "lucide-react-native";

import Reanimated, {
Easing,
FadeInDown,
FadeOutDown,
LinearTransition,
ZoomIn,
ZoomOut
} from "react-native-reanimated";

import RNDateTimePicker from "@react-native-community/datetimepicker";
Expand All @@ -25,9 +22,6 @@ interface HeaderCalendarProps {
}

const HeaderCalendar: React.FC<HeaderCalendarProps> = () => {
const dims = Dimensions.get("window");
const tablet = dims.width > 600;

return (
<Reanimated.View
style={[{
Expand Down Expand Up @@ -67,24 +61,25 @@ const LessonsDateModal: React.FC<LessonsDateModalProps> = ({
const insets = useSafeAreaInsets();

if (Platform.OS === "android") {
return (showDatePicker &&
<RNDateTimePicker
style={{
marginHorizontal: 8,
marginTop: -5,
marginBottom: 10,
}}
value={new Date(currentDate)}
display={"calendar"}
mode="date"
onChange={(event, selectedDate) => {
onDateSelect(selectedDate);
setShowDatePicker(false);
}}
onError={() => {
setShowDatePicker(false);
}}
/>
return (
showDatePicker &&
<RNDateTimePicker
style={{
marginHorizontal: 8,
marginTop: -5,
marginBottom: 10,
}}
value={new Date(currentDate)}
display="calendar"
mode="date"
onChange={(_event, selectedDate) => {
setShowDatePicker(false);
onDateSelect(selectedDate);
}}
onError={() => {
setShowDatePicker(false);
}}
/>
);
}

Expand Down Expand Up @@ -178,16 +173,16 @@ const LessonsDateModal: React.FC<LessonsDateModalProps> = ({
marginBottom: 10,
}}
value={new Date(currentDate)}
display={"inline"}
display="inline"
mode="date"
locale="fr-FR"
accentColor={colors.primary}
onChange={(event, selectedDate) => {
onChange={(_event, selectedDate) => {
setShowDatePicker(false);
const newSelectedDate = selectedDate || currentDate;
// set hours to 0
newSelectedDate.setHours(0, 0, 0, 0);
onDateSelect(newSelectedDate);
// setShowDatePicker(false);
}}
/>
</Reanimated.View>
Expand Down
Loading