Skip to content

Commit

Permalink
fix: project ordering messing up in projects page (#1122)
Browse files Browse the repository at this point in the history
  • Loading branch information
dakshesh14 committed May 25, 2023
1 parent 74329a4 commit 7e5b26e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion apps/app/helpers/array.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ export const groupBy = (array: any[], key: string) => {
};

export const orderArrayBy = (
array: any[],
orgArray: any[],
key: string,
ordering: "ascending" | "descending" = "ascending"
) => {
const array = [...orgArray];

if (!array || !Array.isArray(array) || array.length === 0) return [];

if (key[0] === "-") {
Expand Down
4 changes: 2 additions & 2 deletions apps/app/hooks/use-projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const useProjects = () => {
workspaceSlug ? () => projectService.getProjects(workspaceSlug as string) : null
);

const recentProjects = projects
const recentProjects = [...(projects ?? [])]
?.sort((a, b) => Date.parse(`${a.updated_at}`) - Date.parse(`${b.updated_at}`))
.filter((_item, index) => index < 3);
?.slice(0, 3);

return {
projects: orderArrayBy(projects ?? [], "is_favorite", "descending") || [],
Expand Down

0 comments on commit 7e5b26e

Please sign in to comment.