fix: project ordering messing up in projects page (#1122)

This commit is contained in:
Dakshesh Jain 2023-05-25 12:38:15 +05:30 committed by GitHub
parent 74329a49cc
commit 7e5b26ea82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -8,10 +8,12 @@ export const groupBy = (array: any[], key: string) => {
}; };
export const orderArrayBy = ( export const orderArrayBy = (
array: any[], orgArray: any[],
key: string, key: string,
ordering: "ascending" | "descending" = "ascending" ordering: "ascending" | "descending" = "ascending"
) => { ) => {
const array = [...orgArray];
if (!array || !Array.isArray(array) || array.length === 0) return []; if (!array || !Array.isArray(array) || array.length === 0) return [];
if (key[0] === "-") { if (key[0] === "-") {

View File

@ -19,9 +19,9 @@ const useProjects = () => {
workspaceSlug ? () => projectService.getProjects(workspaceSlug as string) : null 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}`)) ?.sort((a, b) => Date.parse(`${a.updated_at}`) - Date.parse(`${b.updated_at}`))
.filter((_item, index) => index < 3); ?.slice(0, 3);
return { return {
projects: orderArrayBy(projects ?? [], "is_favorite", "descending") || [], projects: orderArrayBy(projects ?? [], "is_favorite", "descending") || [],