From 9bf77fa97a3fce53e06dc878d9e66c5ded3107fe Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Thu, 18 Apr 2024 17:15:51 +0800 Subject: [PATCH 1/6] Mentions also need fixNotifications It's also from notifications API --- src/pages/mentions.jsx | 3 +++ src/utils/group-notifications.jsx | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/mentions.jsx b/src/pages/mentions.jsx index d9bfe40..be81668 100644 --- a/src/pages/mentions.jsx +++ b/src/pages/mentions.jsx @@ -4,6 +4,7 @@ import { useSearchParams } from 'react-router-dom'; import Link from '../components/link'; import Timeline from '../components/timeline'; import { api } from '../utils/api'; +import { fixNotifications } from '../utils/group-notifications'; import { saveStatus } from '../utils/states'; import useTitle from '../utils/useTitle'; @@ -30,6 +31,8 @@ function Mentions({ columnMode, ...props }) { const results = await mentionsIterator.current.next(); let { value } = results; if (value?.length) { + value = fixNotifications(value); + if (firstLoad) { latestItem.current = value[0].id; console.log('First load', latestItem.current); diff --git a/src/utils/group-notifications.jsx b/src/utils/group-notifications.jsx index 630f2d4..31e1b1c 100644 --- a/src/utils/group-notifications.jsx +++ b/src/utils/group-notifications.jsx @@ -9,7 +9,7 @@ const notificationTypeKeys = { poll: ['status'], update: ['status'], }; -function fixNotifications(notifications) { +export function fixNotifications(notifications) { return notifications.filter((notification) => { const { type, id, createdAt } = notification; if (!type) { From 5a448c8049c53e0c6ec8fd84ca751ddbdd74076f Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Thu, 18 Apr 2024 23:10:26 +0800 Subject: [PATCH 2/6] Fix infinite reloading Comment these out because this used to fix an old bug with instances not loaded properly --- src/utils/store-utils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/store-utils.js b/src/utils/store-utils.js index 46054ed..042b2fa 100644 --- a/src/utils/store-utils.js +++ b/src/utils/store-utils.js @@ -107,10 +107,10 @@ export function getCurrentInstance() { return (currentInstance = instances[instance]); } catch (e) { console.error(e); - alert(`Failed to load instance configuration. Please try again.\n\n${e}`); + // alert(`Failed to load instance configuration. Please try again.\n\n${e}`); // Temporary fix for corrupted data - store.local.del('instances'); - location.reload(); + // store.local.del('instances'); + // location.reload(); return {}; } } From 6ccefaebe1f472b2cf2194d9ee259e36a64c0a23 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Thu, 18 Apr 2024 23:11:18 +0800 Subject: [PATCH 3/6] Handle invalid date Ugly solution for now, but it's already ugly --- src/components/relative-time.jsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/relative-time.jsx b/src/components/relative-time.jsx index 3958c71..6801c5d 100644 --- a/src/components/relative-time.jsx +++ b/src/components/relative-time.jsx @@ -21,6 +21,7 @@ export default function RelativeTime({ datetime, format }) { const [renderCount, rerender] = useReducer((x) => x + 1, 0); const date = useMemo(() => dayjs(datetime), [datetime]); const [dateStr, dt, title] = useMemo(() => { + if (!date.isValid()) return ['' + datetime, '', '']; let str; if (format === 'micro') { // If date <= 1 day ago or day is within this year @@ -37,6 +38,7 @@ export default function RelativeTime({ datetime, format }) { }, [date, format, renderCount]); useEffect(() => { + if (!date.isValid()) return; let timeout; let raf; function rafRerender() { From 9235d2c8002a6b24552b0eba33fa4666438962bd Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Thu, 18 Apr 2024 23:12:29 +0800 Subject: [PATCH 4/6] Hide poll button if maxOptions <= 1 It's not a poll if there's only 1 option --- src/components/compose.jsx | 40 +++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/components/compose.jsx b/src/components/compose.jsx index 4508c0a..76a9c61 100644 --- a/src/components/compose.jsx +++ b/src/components/compose.jsx @@ -1219,22 +1219,30 @@ function Compose({ /> {' '} - {' '} + {/* If maxOptions is not defined or defined and is greater than 1, show poll button */} + {maxOptions == null || + (maxOptions > 1 && ( + <> + {' '} + + ))}