Skip to content

Commit

Permalink
Fix sort
Browse files Browse the repository at this point in the history
Embarassing mistake, i know
  • Loading branch information
cheeaun committed Nov 1, 2024
1 parent 6e898fd commit cec8cbf
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 40 deletions.
64 changes: 32 additions & 32 deletions src/locales/en.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions src/pages/status.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit cec8cbf

Please sign in to comment.