From cec8cbff0a860f6523e38d8a586151c263925ba0 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Fri, 1 Nov 2024 18:13:01 +0800 Subject: [PATCH] Fix sort Embarassing mistake, i know --- src/locales/en.po | 64 ++++++++++++++++++++++---------------------- src/pages/status.jsx | 21 +++++++++------ 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/locales/en.po b/src/locales/en.po index b4e59e06..8cc962aa 100644 --- a/src/locales/en.po +++ b/src/locales/en.po @@ -118,7 +118,7 @@ msgstr "" #: src/pages/hashtag.jsx:199 #: src/pages/list.jsx:157 #: src/pages/public.jsx:114 -#: src/pages/status.jsx:1207 +#: src/pages/status.jsx:1212 #: src/pages/trending.jsx:471 msgid "More" msgstr "" @@ -185,8 +185,8 @@ msgstr "" #: src/pages/catchup.jsx:71 #: src/pages/catchup.jsx:1445 #: src/pages/catchup.jsx:2056 -#: src/pages/status.jsx:930 -#: src/pages/status.jsx:1552 +#: src/pages/status.jsx:935 +#: src/pages/status.jsx:1557 msgid "Replies" msgstr "" @@ -427,7 +427,7 @@ msgstr "" #: src/pages/notifications.jsx:868 #: src/pages/notifications.jsx:1082 #: src/pages/settings.jsx:76 -#: src/pages/status.jsx:1294 +#: src/pages/status.jsx:1299 msgid "Close" msgstr "" @@ -967,7 +967,7 @@ msgstr "" #: src/pages/list.jsx:293 #: src/pages/notifications.jsx:848 #: src/pages/search.jsx:529 -#: src/pages/status.jsx:1327 +#: src/pages/status.jsx:1332 msgid "Show more…" msgstr "" @@ -1366,7 +1366,7 @@ msgstr "" #: src/components/nav-menu.jsx:363 #: src/pages/login.jsx:189 -#: src/pages/status.jsx:830 +#: src/pages/status.jsx:835 #: src/pages/welcome.jsx:64 msgid "Log in" msgstr "" @@ -1556,8 +1556,8 @@ msgstr "" #: src/components/poll.jsx:205 #: src/components/poll.jsx:207 -#: src/pages/status.jsx:1196 -#: src/pages/status.jsx:1219 +#: src/pages/status.jsx:1201 +#: src/pages/status.jsx:1224 msgid "Refresh" msgstr "" @@ -2325,8 +2325,8 @@ msgstr "" #: src/components/timeline.jsx:554 #: src/pages/home.jsx:213 #: src/pages/notifications.jsx:824 -#: src/pages/status.jsx:983 -#: src/pages/status.jsx:1356 +#: src/pages/status.jsx:988 +#: src/pages/status.jsx:1361 msgid "Try again" msgstr "" @@ -3574,85 +3574,85 @@ msgid "NOTE: Push notifications only work for <0>one account." msgstr "" #. js-lingui-explicit-id -#: src/pages/status.jsx:592 -#: src/pages/status.jsx:1126 +#: src/pages/status.jsx:597 +#: src/pages/status.jsx:1131 msgid "post.title" msgstr "Post" -#: src/pages/status.jsx:817 +#: src/pages/status.jsx:822 msgid "You're not logged in. Interactions (reply, boost, etc) are not possible." msgstr "" -#: src/pages/status.jsx:837 +#: src/pages/status.jsx:842 msgid "This post is from another instance (<0>{instance}). Interactions (reply, boost, etc) are not possible." msgstr "" -#: src/pages/status.jsx:865 +#: src/pages/status.jsx:870 msgid "Error: {e}" msgstr "" -#: src/pages/status.jsx:872 +#: src/pages/status.jsx:877 msgid "Switch to my instance to enable interactions" msgstr "" -#: src/pages/status.jsx:974 +#: src/pages/status.jsx:979 msgid "Unable to load replies." msgstr "" -#: src/pages/status.jsx:1086 +#: src/pages/status.jsx:1091 msgid "Back" msgstr "" -#: src/pages/status.jsx:1117 +#: src/pages/status.jsx:1122 msgid "Go to main post" msgstr "" -#: src/pages/status.jsx:1140 +#: src/pages/status.jsx:1145 msgid "{0} posts above ‒ Go to top" msgstr "" -#: src/pages/status.jsx:1183 -#: src/pages/status.jsx:1246 +#: src/pages/status.jsx:1188 +#: src/pages/status.jsx:1251 msgid "Switch to Side Peek view" msgstr "" -#: src/pages/status.jsx:1247 +#: src/pages/status.jsx:1252 msgid "Switch to Full view" msgstr "" -#: src/pages/status.jsx:1265 +#: src/pages/status.jsx:1270 msgid "Show all sensitive content" msgstr "" -#: src/pages/status.jsx:1270 +#: src/pages/status.jsx:1275 msgid "Experimental" msgstr "" -#: src/pages/status.jsx:1279 +#: src/pages/status.jsx:1284 msgid "Unable to switch" msgstr "" -#: src/pages/status.jsx:1286 +#: src/pages/status.jsx:1291 msgid "Switch to post's instance ({0})" msgstr "" -#: src/pages/status.jsx:1289 +#: src/pages/status.jsx:1294 msgid "Switch to post's instance" msgstr "" -#: src/pages/status.jsx:1347 +#: src/pages/status.jsx:1352 msgid "Unable to load post" msgstr "" -#: src/pages/status.jsx:1482 +#: src/pages/status.jsx:1487 msgid "{0, plural, one {# reply} other {<0>{1} replies}}" msgstr "" -#: src/pages/status.jsx:1500 +#: src/pages/status.jsx:1505 msgid "{totalComments, plural, one {# comment} other {<0>{0} comments}}" msgstr "" -#: src/pages/status.jsx:1522 +#: src/pages/status.jsx:1527 msgid "View post with its replies" msgstr "" diff --git a/src/pages/status.jsx b/src/pages/status.jsx index 917cacfa..f34c100b 100644 --- a/src/pages/status.jsx +++ b/src/pages/status.jsx @@ -208,6 +208,11 @@ function StatusParent(props) { ); } +// oldest first +function createdAtSort(a, b) { + return new Date(b.created_at) - new Date(a.created_at); +} + function StatusThread({ id, closeLink = '/', instance: propInstance }) { const [searchParams, setSearchParams] = useSearchParams(); const mediaParam = searchParams.get('media'); @@ -321,9 +326,8 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) { const context = await contextFetch; const { ancestors, descendants } = context; - // Sort oldest first - ancestors.sort((a, b) => a.createdAt - b.createdAt); - // descendants.sort((a, b) => a.createdAt - b.createdAt); + ancestors.sort(createdAtSort); + descendants.sort(createdAtSort); totalDescendants.current = descendants?.length || 0; @@ -388,13 +392,14 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) { } }); + // sort hero author to top nestedDescendants.sort((a, b) => { - // sort hero author to top const heroAccountID = heroStatus.account.id; - if (a.account.id === heroAccountID) return -1; - if (b.account.id === heroAccountID) return 1; - // sort by createdAt (oldest first) - return a.createdAt - b.createdAt; + if (a.account.id === heroAccountID && b.account.id !== heroAccountID) + return -1; + if (b.account.id === heroAccountID && a.account.id !== heroAccountID) + return 1; + return 0; }); console.log({ ancestors, descendants, nestedDescendants });