From 41c1ceeeff5eb74c0a4e5bc028e13c66089f58ac Mon Sep 17 00:00:00 2001
From: Lim Chee Aun <cheeaun@gmail.com>
Date: Thu, 31 Oct 2024 22:31:15 +0800
Subject: [PATCH] Fix wrong sort

Why is this so complicated
---
 src/locales/en.po    | 64 ++++++++++++++++++++++----------------------
 src/pages/status.jsx | 11 +++++++-
 2 files changed, 42 insertions(+), 33 deletions(-)

diff --git a/src/locales/en.po b/src/locales/en.po
index 4b563894..a9fb7070 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:1198
+#: src/pages/status.jsx:1207
 #: 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:921
-#: src/pages/status.jsx:1543
+#: src/pages/status.jsx:930
+#: src/pages/status.jsx:1552
 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:1285
+#: src/pages/status.jsx:1294
 msgid "Close"
 msgstr ""
 
@@ -967,7 +967,7 @@ msgstr ""
 #: src/pages/list.jsx:293
 #: src/pages/notifications.jsx:848
 #: src/pages/search.jsx:454
-#: src/pages/status.jsx:1318
+#: src/pages/status.jsx:1327
 msgid "Show more…"
 msgstr ""
 
@@ -1358,7 +1358,7 @@ msgstr ""
 
 #: src/components/nav-menu.jsx:363
 #: src/pages/login.jsx:189
-#: src/pages/status.jsx:821
+#: src/pages/status.jsx:830
 #: src/pages/welcome.jsx:64
 msgid "Log in"
 msgstr ""
@@ -1548,8 +1548,8 @@ msgstr ""
 
 #: src/components/poll.jsx:205
 #: src/components/poll.jsx:207
-#: src/pages/status.jsx:1187
-#: src/pages/status.jsx:1210
+#: src/pages/status.jsx:1196
+#: src/pages/status.jsx:1219
 msgid "Refresh"
 msgstr ""
 
@@ -2317,8 +2317,8 @@ msgstr ""
 #: src/components/timeline.jsx:554
 #: src/pages/home.jsx:213
 #: src/pages/notifications.jsx:824
-#: src/pages/status.jsx:974
-#: src/pages/status.jsx:1347
+#: src/pages/status.jsx:983
+#: src/pages/status.jsx:1356
 msgid "Try again"
 msgstr ""
 
@@ -3566,85 +3566,85 @@ msgid "NOTE: Push notifications only work for <0>one account</0>."
 msgstr ""
 
 #. js-lingui-explicit-id
-#: src/pages/status.jsx:583
-#: src/pages/status.jsx:1117
+#: src/pages/status.jsx:592
+#: src/pages/status.jsx:1126
 msgid "post.title"
 msgstr "Post"
 
-#: src/pages/status.jsx:808
+#: src/pages/status.jsx:817
 msgid "You're not logged in. Interactions (reply, boost, etc) are not possible."
 msgstr ""
 
-#: src/pages/status.jsx:828
+#: src/pages/status.jsx:837
 msgid "This post is from another instance (<0>{instance}</0>). Interactions (reply, boost, etc) are not possible."
 msgstr ""
 
-#: src/pages/status.jsx:856
+#: src/pages/status.jsx:865
 msgid "Error: {e}"
 msgstr ""
 
-#: src/pages/status.jsx:863
+#: src/pages/status.jsx:872
 msgid "Switch to my instance to enable interactions"
 msgstr ""
 
-#: src/pages/status.jsx:965
+#: src/pages/status.jsx:974
 msgid "Unable to load replies."
 msgstr ""
 
-#: src/pages/status.jsx:1077
+#: src/pages/status.jsx:1086
 msgid "Back"
 msgstr ""
 
-#: src/pages/status.jsx:1108
+#: src/pages/status.jsx:1117
 msgid "Go to main post"
 msgstr ""
 
-#: src/pages/status.jsx:1131
+#: src/pages/status.jsx:1140
 msgid "{0} posts above ‒ Go to top"
 msgstr ""
 
-#: src/pages/status.jsx:1174
-#: src/pages/status.jsx:1237
+#: src/pages/status.jsx:1183
+#: src/pages/status.jsx:1246
 msgid "Switch to Side Peek view"
 msgstr ""
 
-#: src/pages/status.jsx:1238
+#: src/pages/status.jsx:1247
 msgid "Switch to Full view"
 msgstr ""
 
-#: src/pages/status.jsx:1256
+#: src/pages/status.jsx:1265
 msgid "Show all sensitive content"
 msgstr ""
 
-#: src/pages/status.jsx:1261
+#: src/pages/status.jsx:1270
 msgid "Experimental"
 msgstr ""
 
-#: src/pages/status.jsx:1270
+#: src/pages/status.jsx:1279
 msgid "Unable to switch"
 msgstr ""
 
-#: src/pages/status.jsx:1277
+#: src/pages/status.jsx:1286
 msgid "Switch to post's instance ({0})"
 msgstr ""
 
-#: src/pages/status.jsx:1280
+#: src/pages/status.jsx:1289
 msgid "Switch to post's instance"
 msgstr ""
 
-#: src/pages/status.jsx:1338
+#: src/pages/status.jsx:1347
 msgid "Unable to load post"
 msgstr ""
 
-#: src/pages/status.jsx:1473
+#: src/pages/status.jsx:1482
 msgid "{0, plural, one {# reply} other {<0>{1}</0> replies}}"
 msgstr ""
 
-#: src/pages/status.jsx:1491
+#: src/pages/status.jsx:1500
 msgid "{totalComments, plural, one {# comment} other {<0>{0}</0> comments}}"
 msgstr ""
 
-#: src/pages/status.jsx:1513
+#: src/pages/status.jsx:1522
 msgid "View post with its replies"
 msgstr ""
 
diff --git a/src/pages/status.jsx b/src/pages/status.jsx
index a26a5f2e..917cacfa 100644
--- a/src/pages/status.jsx
+++ b/src/pages/status.jsx
@@ -323,7 +323,7 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) {
 
         // Sort oldest first
         ancestors.sort((a, b) => a.createdAt - b.createdAt);
-        descendants.sort((a, b) => a.createdAt - b.createdAt);
+        // descendants.sort((a, b) => a.createdAt - b.createdAt);
 
         totalDescendants.current = descendants?.length || 0;
 
@@ -388,6 +388,15 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) {
           }
         });
 
+        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;
+        });
+
         console.log({ ancestors, descendants, nestedDescendants });
         if (missingStatuses.size) {
           console.error('Missing statuses', [...missingStatuses]);