From e05e30dca0268b7f59d042bfc918370307f233d8 Mon Sep 17 00:00:00 2001 From: JyhuKo Date: Wed, 18 Dec 2024 01:21:16 +0100 Subject: [PATCH 01/13] Update Item.tsx --- src/views/account/Homeworks/Atoms/Item.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/views/account/Homeworks/Atoms/Item.tsx b/src/views/account/Homeworks/Atoms/Item.tsx index 1192b5f8c..a2e9ec3f1 100644 --- a/src/views/account/Homeworks/Atoms/Item.tsx +++ b/src/views/account/Homeworks/Atoms/Item.tsx @@ -73,8 +73,18 @@ const HomeworkItem = ({ homework, navigation, onDonePressHandler, index, total } const date = new Date(timestamp); const today = new Date(); + // heure par defaut a 00:00:00:00 + today.setHours(0, 0, 0, 0); + date.setHours(0, 0, 0, 0); + const difference = Math.ceil((date.getTime() - today.getTime()) / (1000 * 60 * 60 * 24)); - return difference === 0 ? "Aujourd'hui" : difference === 1 ? "Demain" : difference === 2 ? "Après-demain" : `Dans ${difference} jours`; + return difference === 0 + ? "Aujourd'hui" + : difference === 1 + ? "Demain" + : difference === 2 + ? "Après-demain" + : `Dans ${difference} jours`; }; const renderCategoryOrReturnType = () => { From f78d8d1a93dc28945d80914c3e430fffc070bc1a Mon Sep 17 00:00:00 2001 From: JyhuKo Date: Wed, 18 Dec 2024 01:21:50 +0100 Subject: [PATCH 02/13] Update Document.tsx --- src/views/account/Homeworks/Document.tsx | 31 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/views/account/Homeworks/Document.tsx b/src/views/account/Homeworks/Document.tsx index e6014404f..64ce9f20d 100644 --- a/src/views/account/Homeworks/Document.tsx +++ b/src/views/account/Homeworks/Document.tsx @@ -16,11 +16,6 @@ import { } from "react-native"; import { Homework, HomeworkReturnType } from "@/services/shared/Homework"; import { getSubjectData } from "@/services/shared/Subject"; - -import { formatDistance } from "date-fns"; -import { fr } from "date-fns/locale"; -import { FileText, Link, Paperclip, CircleAlert, FileIcon } from "lucide-react-native"; - import * as WebBrowser from "expo-web-browser"; import { useTheme } from "@react-navigation/native"; import HTMLView from "react-native-htmlview"; @@ -31,8 +26,8 @@ import { PapillonModernHeader } from "@/components/Global/PapillonModernHeader"; import { useCurrentAccount } from "@/stores/account"; import { AccountService } from "@/stores/account/types"; import getAndOpenFile from "@/utils/files/getAndOpenFile"; -import LinkFavicon, { getURLDomain } from "@/components/Global/LinkFavicon"; import { AutoFileIcon } from "@/components/Global/FileIcon"; +import { FileText, Link, Paperclip, CircleAlert, FileIcon } from "lucide-react-native"; const HomeworksDocument: Screen<"HomeworksDocument"> = ({ route }) => { const theme = useTheme(); @@ -81,6 +76,25 @@ const HomeworksDocument: Screen<"HomeworksDocument"> = ({ route }) => { fetchSubjectData(); }, [homework.subject]); + + const timestampToString = (timestamp: number) => { + const date = new Date(timestamp); + const today = new Date(); + + today.setHours(0, 0, 0, 0); + date.setHours(0, 0, 0, 0); + + const difference = Math.ceil((date.getTime() - today.getTime()) / (1000 * 60 * 60 * 24)); + + return difference === 0 + ? "Aujourd'hui" + : difference === 1 + ? "Demain" + : difference === 2 + ? "Après-demain" + : `Dans ${difference} jours`; + }; + return ( @@ -106,10 +120,7 @@ const HomeworksDocument: Screen<"HomeworksDocument"> = ({ route }) => { {subjectData.pretty} - {formatDistance(new Date(homework.due), new Date(), { - addSuffix: true, - locale: fr, - })} + {timestampToString(new Date(homework.due).getTime())} From c994bd7f94eaf810b1e763cc94b6da020c0fe4e5 Mon Sep 17 00:00:00 2001 From: JyhuKo Date: Wed, 18 Dec 2024 01:22:16 +0100 Subject: [PATCH 03/13] Update AttendanceElement.tsx --- src/views/account/Home/Elements/AttendanceElement.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/account/Home/Elements/AttendanceElement.tsx b/src/views/account/Home/Elements/AttendanceElement.tsx index 559d1cdad..62fd38f12 100644 --- a/src/views/account/Home/Elements/AttendanceElement.tsx +++ b/src/views/account/Home/Elements/AttendanceElement.tsx @@ -94,7 +94,7 @@ const AttendanceElement: React.FC = ({ onImportance }) = return ( <> - )} From 729951a775a6e7d2d92231af6125395ecade0b63 Mon Sep 17 00:00:00 2001 From: JyhuKo Date: Wed, 18 Dec 2024 10:09:43 +0100 Subject: [PATCH 04/13] Update Item.tsx --- src/views/account/Homeworks/Atoms/Item.tsx | 34 ++++++++++++---------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/views/account/Homeworks/Atoms/Item.tsx b/src/views/account/Homeworks/Atoms/Item.tsx index a2e9ec3f1..06194772a 100644 --- a/src/views/account/Homeworks/Atoms/Item.tsx +++ b/src/views/account/Homeworks/Atoms/Item.tsx @@ -27,6 +27,24 @@ interface HomeworkItemProps { navigation: NativeStackNavigationProp } +export const timestampToString = (timestamp: number) => { + const date = new Date(timestamp); + const today = new Date(); + + today.setHours(0, 0, 0, 0); + date.setHours(0, 0, 0, 0); + + const difference = Math.ceil((date.getTime() - today.getTime()) / (1000 * 60 * 60 * 24)); + + return difference === 0 + ? "Aujourd'hui" + : difference === 1 + ? "Demain" + : difference === 2 + ? "Après-demain" + : `Dans ${difference} jours`; +}; + const HomeworkItem = ({ homework, navigation, onDonePressHandler, index, total }: HomeworkItemProps) => { const theme = useTheme(); const [subjectData, setSubjectData] = useState(getSubjectData(homework.subject)); @@ -69,23 +87,7 @@ const HomeworkItem = ({ homework, navigation, onDonePressHandler, index, total } setMainLoaded(true); }, [homework.done]); - const timestampToString = (timestamp: number) => { - const date = new Date(timestamp); - const today = new Date(); - - // heure par defaut a 00:00:00:00 - today.setHours(0, 0, 0, 0); - date.setHours(0, 0, 0, 0); - const difference = Math.ceil((date.getTime() - today.getTime()) / (1000 * 60 * 60 * 24)); - return difference === 0 - ? "Aujourd'hui" - : difference === 1 - ? "Demain" - : difference === 2 - ? "Après-demain" - : `Dans ${difference} jours`; - }; const renderCategoryOrReturnType = () => { if (category) { From 3d9f8226bf77655f4903118b5ef6cf7bd0bd84fa Mon Sep 17 00:00:00 2001 From: JyhuKo Date: Wed, 18 Dec 2024 10:09:56 +0100 Subject: [PATCH 05/13] Update Document.tsx --- src/views/account/Homeworks/Document.tsx | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/views/account/Homeworks/Document.tsx b/src/views/account/Homeworks/Document.tsx index 64ce9f20d..d30950a26 100644 --- a/src/views/account/Homeworks/Document.tsx +++ b/src/views/account/Homeworks/Document.tsx @@ -28,6 +28,7 @@ import { AccountService } from "@/stores/account/types"; import getAndOpenFile from "@/utils/files/getAndOpenFile"; import { AutoFileIcon } from "@/components/Global/FileIcon"; import { FileText, Link, Paperclip, CircleAlert, FileIcon } from "lucide-react-native"; +import { timestampToString } from "@/views/account/Homeworks/Atoms/Item"; const HomeworksDocument: Screen<"HomeworksDocument"> = ({ route }) => { const theme = useTheme(); @@ -77,24 +78,6 @@ const HomeworksDocument: Screen<"HomeworksDocument"> = ({ route }) => { }, [homework.subject]); - const timestampToString = (timestamp: number) => { - const date = new Date(timestamp); - const today = new Date(); - - today.setHours(0, 0, 0, 0); - date.setHours(0, 0, 0, 0); - - const difference = Math.ceil((date.getTime() - today.getTime()) / (1000 * 60 * 60 * 24)); - - return difference === 0 - ? "Aujourd'hui" - : difference === 1 - ? "Demain" - : difference === 2 - ? "Après-demain" - : `Dans ${difference} jours`; - }; - return ( From 0439b5f3dc20695c51bed364e9ae487167eda5a5 Mon Sep 17 00:00:00 2001 From: JyhuKo Date: Wed, 18 Dec 2024 11:39:02 +0100 Subject: [PATCH 06/13] Create DateHelper.ts --- src/utils/format/DateHelper.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/utils/format/DateHelper.ts diff --git a/src/utils/format/DateHelper.ts b/src/utils/format/DateHelper.ts new file mode 100644 index 000000000..31a4befb1 --- /dev/null +++ b/src/utils/format/DateHelper.ts @@ -0,0 +1,17 @@ +export const timestampToString = (timestamp: number) => { + const date = new Date(timestamp); + const today = new Date(); + + today.setHours(0, 0, 0, 0); + date.setHours(0, 0, 0, 0); + + const difference = Math.ceil((date.getTime() - today.getTime()) / (1000 * 60 * 60 * 24)); + + return difference === 0 + ? "Aujourd'hui" + : difference === 1 + ? "Demain" + : difference === 2 + ? "Après-demain" + : `Dans ${difference} jours`; +}; From f9b655808c85248271e50f9055ef148187180ccf Mon Sep 17 00:00:00 2001 From: JyhuKo Date: Wed, 18 Dec 2024 11:40:32 +0100 Subject: [PATCH 07/13] Update Document.tsx --- src/views/account/Homeworks/Document.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/account/Homeworks/Document.tsx b/src/views/account/Homeworks/Document.tsx index d30950a26..766af736a 100644 --- a/src/views/account/Homeworks/Document.tsx +++ b/src/views/account/Homeworks/Document.tsx @@ -28,7 +28,7 @@ import { AccountService } from "@/stores/account/types"; import getAndOpenFile from "@/utils/files/getAndOpenFile"; import { AutoFileIcon } from "@/components/Global/FileIcon"; import { FileText, Link, Paperclip, CircleAlert, FileIcon } from "lucide-react-native"; -import { timestampToString } from "@/views/account/Homeworks/Atoms/Item"; +import { timestampToString } from "@/utils/format/dateHelpers"; const HomeworksDocument: Screen<"HomeworksDocument"> = ({ route }) => { const theme = useTheme(); From c0408d5272e0dae8366842180a06ec3d2a5ab89c Mon Sep 17 00:00:00 2001 From: JyhuKo Date: Wed, 18 Dec 2024 11:42:35 +0100 Subject: [PATCH 08/13] Update Item.tsx --- src/views/account/Homeworks/Atoms/Item.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/views/account/Homeworks/Atoms/Item.tsx b/src/views/account/Homeworks/Atoms/Item.tsx index 06194772a..f14fa1d77 100644 --- a/src/views/account/Homeworks/Atoms/Item.tsx +++ b/src/views/account/Homeworks/Atoms/Item.tsx @@ -17,6 +17,7 @@ import { LinearGradient } from "expo-linear-gradient"; import { useCurrentAccount } from "@/stores/account"; import LinkFavicon, { getURLDomain } from "@/components/Global/LinkFavicon"; import { AutoFileIcon } from "@/components/Global/FileIcon"; +import { timestampToString } from "@/utils/format/dateHelpers"; interface HomeworkItemProps { key: number | string From 0aeeb88b4ebf3f6f18889bbcc8a7f2665607325d Mon Sep 17 00:00:00 2001 From: JyhuKo Date: Wed, 18 Dec 2024 11:46:50 +0100 Subject: [PATCH 09/13] Update Document.tsx --- src/views/account/Homeworks/Document.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/account/Homeworks/Document.tsx b/src/views/account/Homeworks/Document.tsx index 766af736a..cb58ce18c 100644 --- a/src/views/account/Homeworks/Document.tsx +++ b/src/views/account/Homeworks/Document.tsx @@ -28,7 +28,7 @@ import { AccountService } from "@/stores/account/types"; import getAndOpenFile from "@/utils/files/getAndOpenFile"; import { AutoFileIcon } from "@/components/Global/FileIcon"; import { FileText, Link, Paperclip, CircleAlert, FileIcon } from "lucide-react-native"; -import { timestampToString } from "@/utils/format/dateHelpers"; +import { timestampToString } from "@/utils/format/dateHelper"; const HomeworksDocument: Screen<"HomeworksDocument"> = ({ route }) => { const theme = useTheme(); From 88e8817e59336c9a59a772e94defe48bb7c564e4 Mon Sep 17 00:00:00 2001 From: JyhuKo Date: Wed, 18 Dec 2024 11:47:04 +0100 Subject: [PATCH 10/13] Update Item.tsx --- src/views/account/Homeworks/Atoms/Item.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/account/Homeworks/Atoms/Item.tsx b/src/views/account/Homeworks/Atoms/Item.tsx index f14fa1d77..f5604875f 100644 --- a/src/views/account/Homeworks/Atoms/Item.tsx +++ b/src/views/account/Homeworks/Atoms/Item.tsx @@ -17,7 +17,7 @@ import { LinearGradient } from "expo-linear-gradient"; import { useCurrentAccount } from "@/stores/account"; import LinkFavicon, { getURLDomain } from "@/components/Global/LinkFavicon"; import { AutoFileIcon } from "@/components/Global/FileIcon"; -import { timestampToString } from "@/utils/format/dateHelpers"; +import { timestampToString } from "@/utils/format/dateHelper"; interface HomeworkItemProps { key: number | string From e7b9ee54380a482b4ecb05009b08b159c19cdc11 Mon Sep 17 00:00:00 2001 From: JyhuKo Date: Wed, 18 Dec 2024 11:48:12 +0100 Subject: [PATCH 11/13] Update Item.tsx --- src/views/account/Homeworks/Atoms/Item.tsx | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/views/account/Homeworks/Atoms/Item.tsx b/src/views/account/Homeworks/Atoms/Item.tsx index f5604875f..e23f29c60 100644 --- a/src/views/account/Homeworks/Atoms/Item.tsx +++ b/src/views/account/Homeworks/Atoms/Item.tsx @@ -28,23 +28,6 @@ interface HomeworkItemProps { navigation: NativeStackNavigationProp } -export const timestampToString = (timestamp: number) => { - const date = new Date(timestamp); - const today = new Date(); - - today.setHours(0, 0, 0, 0); - date.setHours(0, 0, 0, 0); - - const difference = Math.ceil((date.getTime() - today.getTime()) / (1000 * 60 * 60 * 24)); - - return difference === 0 - ? "Aujourd'hui" - : difference === 1 - ? "Demain" - : difference === 2 - ? "Après-demain" - : `Dans ${difference} jours`; -}; const HomeworkItem = ({ homework, navigation, onDonePressHandler, index, total }: HomeworkItemProps) => { const theme = useTheme(); From f7ccaadd3b7097a4341a5765f02a293a799624a8 Mon Sep 17 00:00:00 2001 From: JyhuKo Date: Wed, 18 Dec 2024 11:58:04 +0100 Subject: [PATCH 12/13] Update Document.tsx --- src/views/account/Homeworks/Document.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/views/account/Homeworks/Document.tsx b/src/views/account/Homeworks/Document.tsx index cb58ce18c..10d05dfa3 100644 --- a/src/views/account/Homeworks/Document.tsx +++ b/src/views/account/Homeworks/Document.tsx @@ -1,3 +1,4 @@ + import { NativeItem, NativeList, @@ -28,7 +29,8 @@ import { AccountService } from "@/stores/account/types"; import getAndOpenFile from "@/utils/files/getAndOpenFile"; import { AutoFileIcon } from "@/components/Global/FileIcon"; import { FileText, Link, Paperclip, CircleAlert, FileIcon } from "lucide-react-native"; -import { timestampToString } from "@/utils/format/dateHelper"; +import LinkFavicon, { getURLDomain } from "@/components/Global/LinkFavicon"; +import { timestampToString } from "@/utils/format/DateHelper"; const HomeworksDocument: Screen<"HomeworksDocument"> = ({ route }) => { const theme = useTheme(); From cb4dd218873e6f3df949dfdd6f56afae0c60c30c Mon Sep 17 00:00:00 2001 From: JyhuKo Date: Wed, 18 Dec 2024 11:58:19 +0100 Subject: [PATCH 13/13] Update Item.tsx --- src/views/account/Homeworks/Atoms/Item.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/views/account/Homeworks/Atoms/Item.tsx b/src/views/account/Homeworks/Atoms/Item.tsx index e23f29c60..a7e0a2d43 100644 --- a/src/views/account/Homeworks/Atoms/Item.tsx +++ b/src/views/account/Homeworks/Atoms/Item.tsx @@ -17,7 +17,8 @@ import { LinearGradient } from "expo-linear-gradient"; import { useCurrentAccount } from "@/stores/account"; import LinkFavicon, { getURLDomain } from "@/components/Global/LinkFavicon"; import { AutoFileIcon } from "@/components/Global/FileIcon"; -import { timestampToString } from "@/utils/format/dateHelper"; +import { timestampToString } from "@/utils/format/DateHelper"; + interface HomeworkItemProps { key: number | string