diff --git a/src/utils/format/format_date_complets.ts b/src/utils/format/format_date_complets.ts index ec8d4180..624d99d1 100644 --- a/src/utils/format/format_date_complets.ts +++ b/src/utils/format/format_date_complets.ts @@ -6,18 +6,18 @@ function formatDate (date: string): string { const diffMonths = Math.floor(diffDays / 30); if (diffDays < 1) { - return "il y a quelques minutes"; - } else if (diffDays === 1) { - return "il y a 1 jour"; + return "Aujourd'hui"; } else if (diffDays < 30) { - return `il y a ${diffDays} jours`; + return `Il y a ${diffDays} jour${diffDays !== 1 ? "s" : ""}`; } else if (diffMonths === 1) { - return "il y a 1 mois"; - } else if (diffMonths < 12) { - return `il y a ${diffMonths} mois`; + return "Il y a 1 mois"; } else { - return date; + return `Le ${messageDate.getDay().toString().padStart(2, "0")}/${( + messageDate.getMonth() + 1 + ) + .toString() + .padStart(2, "0")}/${messageDate.getFullYear()}`; } } -export default formatDate; \ No newline at end of file +export default formatDate; diff --git a/src/views/account/News/News.tsx b/src/views/account/News/News.tsx index 8742786a..437bf905 100644 --- a/src/views/account/News/News.tsx +++ b/src/views/account/News/News.tsx @@ -26,7 +26,7 @@ const NewsScreen: Screen<"News"> = ({ route, navigation }) => { const account = useCurrentAccount((store) => store.account!); const informations = useNewsStore((store) => store.informations); - const [isLoading, setIsLoading] = useState(false); + const [isLoading, setIsLoading] = useState(true); const [importantMessages, setImportantMessages] = useState([]); const [sortedMessages, setSortedMessages] = useState([]); @@ -36,26 +36,33 @@ const NewsScreen: Screen<"News"> = ({ route, navigation }) => { }); }, [navigation, route.params, theme.colors.text]); - const fetchData = useCallback(async (hidden: boolean = false) => { - if (!hidden) setIsLoading(true); - await updateNewsInCache(account); - setIsLoading(false); + const fetchData = useCallback((_hidden: boolean = false) => { + setIsLoading(true); + setTimeout(async () => { + await updateNewsInCache(account); + setIsLoading(false); + }, 100); }, [account]); useEffect(() => { - navigation.addListener("focus", () => fetchData(true)); - fetchData(); - }, [account.instance]); + if (sortedMessages.length === 0) { + navigation.addListener("focus", () => fetchData(true)); + fetchData(); + } + }, [sortedMessages, account.instance]); useEffect(() => { if (informations) { if (account.personalization?.magicEnabled) { const { importantMessages, normalMessages } = categorizeMessages(informations); - setImportantMessages(importantMessages.map(message => ({ ...message, date: message.date.toString() }))); - setSortedMessages(normalMessages.map(message => ({ ...message, date: message.date.toString() })).sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())); + const element1 = importantMessages.map(message => ({ ...message, date: message.date.toString() })); + const element2 = normalMessages.map(message => ({ ...message, date: message.date.toString() })).sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()); + setImportantMessages(element1); + setSortedMessages(element2); } else { + const element3 = informations.map(info => ({ ...info, date: info.date.toString(), title: info.title || "" })).sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()); setImportantMessages([]); - setSortedMessages(informations.map(info => ({ ...info, date: info.date.toString(), title: info.title || "" })).sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())); + setSortedMessages(element3); } } }, [informations, account.personalization?.magicEnabled]); @@ -93,58 +100,64 @@ const NewsScreen: Screen<"News"> = ({ route, navigation }) => { } > - {importantMessages.length > 0 && ( - - + {!isLoading && ( + !hasNews ? : ( + <> + { + importantMessages.length > 0 && ( + + + } + trailing={} + /> + + + + `important-${index}`} + /> + + + + ) } - trailing={} - /> - - - - `important-${index}`} - /> - - - - )} - {sortedMessages.length > 0 && ( - - - `sorted-${index}`} - /> - - + {sortedMessages.length > 0 && ( + + + `sorted-${index}`} + /> + + + )} + + ) )} - - {!isLoading && !hasNews && } ); };