From 5f7b7dced32f96ed4cf856ab2fcee7fcb30aca68 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 17 Oct 2023 15:40:49 +0300 Subject: [PATCH 1/7] add `lastActivity` field to `Common` model --- src/shared/models/Common.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/shared/models/Common.tsx b/src/shared/models/Common.tsx index c03ad4ca19..31989caa75 100644 --- a/src/shared/models/Common.tsx +++ b/src/shared/models/Common.tsx @@ -4,6 +4,7 @@ import { Discussion } from "./Discussion"; import { DiscussionMessage } from "./DiscussionMessage"; import { PaymentAmount } from "./Payment"; import { Proposal } from "./Proposals"; +import { Timestamp } from "./Timestamp"; import { User } from "./User"; import { AllowedActions, @@ -119,6 +120,8 @@ export interface Common extends BaseEntity { hasPublicItems: boolean; rootCommonId?: string; + + lastActivity?: Timestamp; } export interface Project extends Common { From 1e5006057027608c87398c52cd00eb17b2f83674 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 17 Oct 2023 15:58:05 +0300 Subject: [PATCH 2/7] sort breadcrumbs items by name --- src/shared/utils/index.tsx | 1 + src/shared/utils/sortProjectsStateItemsByName.ts | 9 +++++++++ src/store/states/multipleSpacesLayout/reducer.ts | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 src/shared/utils/sortProjectsStateItemsByName.ts diff --git a/src/shared/utils/index.tsx b/src/shared/utils/index.tsx index dbf698daac..2b5eb09b4c 100755 --- a/src/shared/utils/index.tsx +++ b/src/shared/utils/index.tsx @@ -29,6 +29,7 @@ export * from "./circles"; export * from "./notifications"; export * from "./getFirebaseToken"; export * from "./sidenav"; +export * from "./sortProjectsStateItemsByName"; export * from "./text"; export * from "./hasPermission"; export * from "./getProjectCircleDefinition"; diff --git a/src/shared/utils/sortProjectsStateItemsByName.ts b/src/shared/utils/sortProjectsStateItemsByName.ts new file mode 100644 index 0000000000..00bb29d76b --- /dev/null +++ b/src/shared/utils/sortProjectsStateItemsByName.ts @@ -0,0 +1,9 @@ +import { ProjectsStateItem } from "@/store/states"; + +export const sortProjectsStateItemsByName = ( + items: ProjectsStateItem[], +): ProjectsStateItem[] => { + return [...items].sort((prevItem, nextItem) => + prevItem.name < nextItem.name ? -1 : 1, + ); +}; diff --git a/src/store/states/multipleSpacesLayout/reducer.ts b/src/store/states/multipleSpacesLayout/reducer.ts index 347ae0914f..76e58b8a13 100644 --- a/src/store/states/multipleSpacesLayout/reducer.ts +++ b/src/store/states/multipleSpacesLayout/reducer.ts @@ -3,6 +3,7 @@ import { WritableDraft } from "immer/dist/types/types-external"; import { cloneDeep } from "lodash"; import { ActionType, createReducer } from "typesafe-actions"; import { InboxItemType } from "@/shared/constants"; +import { sortProjectsStateItemsByName } from "@/shared/utils"; import * as actions from "./actions"; import { MultipleSpacesLayoutState, ProjectsStateItem } from "./types"; @@ -35,6 +36,16 @@ const updateProjectInBreadcrumbs = ( } }; +const sortBreadcrumbsItems = ( + state: WritableDraft, +) => { + if (state.breadcrumbs?.type === InboxItemType.FeedItemFollow) { + state.breadcrumbs.items = sortProjectsStateItemsByName( + state.breadcrumbs.items, + ); + } +}; + export const reducer = createReducer( initialState, ) @@ -44,6 +55,7 @@ export const reducer = createReducer( .handleAction(actions.setBreadcrumbsData, (state, { payload }) => produce(state, (nextState) => { nextState.breadcrumbs = payload && { ...payload }; + sortBreadcrumbsItems(nextState); }), ) .handleAction(actions.moveBreadcrumbsToPrevious, (state) => @@ -70,11 +82,15 @@ export const reducer = createReducer( nextState.breadcrumbs.items = nextState.breadcrumbs.items.concat(payload); } + + sortBreadcrumbsItems(nextState); }), ) .handleAction(actions.updateProjectInBreadcrumbs, (state, { payload }) => produce(state, (nextState) => { updateProjectInBreadcrumbs(nextState, payload); + + sortBreadcrumbsItems(nextState); }), ) .handleAction(actions.setBackUrl, (state, { payload }) => From 458a25a5181db7beb2f2af81f8b59469d773f458 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 17 Oct 2023 16:37:32 +0300 Subject: [PATCH 3/7] revert "sort breadcrumbs items by name" This reverts commit 1e500605 --- src/shared/utils/index.tsx | 1 - src/shared/utils/sortProjectsStateItemsByName.ts | 9 --------- src/store/states/multipleSpacesLayout/reducer.ts | 16 ---------------- 3 files changed, 26 deletions(-) delete mode 100644 src/shared/utils/sortProjectsStateItemsByName.ts diff --git a/src/shared/utils/index.tsx b/src/shared/utils/index.tsx index 2b5eb09b4c..dbf698daac 100755 --- a/src/shared/utils/index.tsx +++ b/src/shared/utils/index.tsx @@ -29,7 +29,6 @@ export * from "./circles"; export * from "./notifications"; export * from "./getFirebaseToken"; export * from "./sidenav"; -export * from "./sortProjectsStateItemsByName"; export * from "./text"; export * from "./hasPermission"; export * from "./getProjectCircleDefinition"; diff --git a/src/shared/utils/sortProjectsStateItemsByName.ts b/src/shared/utils/sortProjectsStateItemsByName.ts deleted file mode 100644 index 00bb29d76b..0000000000 --- a/src/shared/utils/sortProjectsStateItemsByName.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { ProjectsStateItem } from "@/store/states"; - -export const sortProjectsStateItemsByName = ( - items: ProjectsStateItem[], -): ProjectsStateItem[] => { - return [...items].sort((prevItem, nextItem) => - prevItem.name < nextItem.name ? -1 : 1, - ); -}; diff --git a/src/store/states/multipleSpacesLayout/reducer.ts b/src/store/states/multipleSpacesLayout/reducer.ts index 76e58b8a13..347ae0914f 100644 --- a/src/store/states/multipleSpacesLayout/reducer.ts +++ b/src/store/states/multipleSpacesLayout/reducer.ts @@ -3,7 +3,6 @@ import { WritableDraft } from "immer/dist/types/types-external"; import { cloneDeep } from "lodash"; import { ActionType, createReducer } from "typesafe-actions"; import { InboxItemType } from "@/shared/constants"; -import { sortProjectsStateItemsByName } from "@/shared/utils"; import * as actions from "./actions"; import { MultipleSpacesLayoutState, ProjectsStateItem } from "./types"; @@ -36,16 +35,6 @@ const updateProjectInBreadcrumbs = ( } }; -const sortBreadcrumbsItems = ( - state: WritableDraft, -) => { - if (state.breadcrumbs?.type === InboxItemType.FeedItemFollow) { - state.breadcrumbs.items = sortProjectsStateItemsByName( - state.breadcrumbs.items, - ); - } -}; - export const reducer = createReducer( initialState, ) @@ -55,7 +44,6 @@ export const reducer = createReducer( .handleAction(actions.setBreadcrumbsData, (state, { payload }) => produce(state, (nextState) => { nextState.breadcrumbs = payload && { ...payload }; - sortBreadcrumbsItems(nextState); }), ) .handleAction(actions.moveBreadcrumbsToPrevious, (state) => @@ -82,15 +70,11 @@ export const reducer = createReducer( nextState.breadcrumbs.items = nextState.breadcrumbs.items.concat(payload); } - - sortBreadcrumbsItems(nextState); }), ) .handleAction(actions.updateProjectInBreadcrumbs, (state, { payload }) => produce(state, (nextState) => { updateProjectInBreadcrumbs(nextState, payload); - - sortBreadcrumbsItems(nextState); }), ) .handleAction(actions.setBackUrl, (state, { payload }) => From 5a025240c6e072aee4a4f4b4a0b7f357efdd9f2c Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 17 Oct 2023 16:43:39 +0300 Subject: [PATCH 4/7] add breadcrumbs sorting by lastActivity --- .../saga/fetchBreadcrumbsItemsByCommonId.ts | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/store/states/multipleSpacesLayout/saga/fetchBreadcrumbsItemsByCommonId.ts b/src/store/states/multipleSpacesLayout/saga/fetchBreadcrumbsItemsByCommonId.ts index b505658868..187b0b5488 100644 --- a/src/store/states/multipleSpacesLayout/saga/fetchBreadcrumbsItemsByCommonId.ts +++ b/src/store/states/multipleSpacesLayout/saga/fetchBreadcrumbsItemsByCommonId.ts @@ -102,16 +102,28 @@ export function* fetchBreadcrumbsItemsByCommonId( commonId, user?.uid, )) as Awaited>; - const projectsData: ProjectsStateItem[] = projectsInfo.map( - ({ common, hasMembership, hasPermissionToAddProject }) => ({ + const projectsData: ProjectsStateItem[] = [...projectsInfo] + .sort((prevItem, nextItem) => { + if (!nextItem.common.lastActivity) { + return -1; + } + if (!prevItem.common.lastActivity) { + return 1; + } + + return ( + nextItem.common.lastActivity.seconds - + prevItem.common.lastActivity.seconds + ); + }) + .map(({ common, hasMembership, hasPermissionToAddProject }) => ({ commonId: common.id, image: common.image, name: common.name, directParent: common.directParent, hasMembership, hasPermissionToAddProject, - }), - ); + })); const currentBreadcrumbs = (yield select( selectMultipleSpacesLayoutBreadcrumbs, From 8fc2e831c255941cc9de9a58ad6b90f9c5596a65 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 17 Oct 2023 17:18:27 +0300 Subject: [PATCH 5/7] add commons sorting in the navigation dropdown --- .../utils/compareCommonsByLastActivity.ts | 15 +++++++++++++++ src/shared/utils/index.tsx | 1 + .../states/commonLayout/saga/getCommons.ts | 12 +++++++----- .../saga/fetchBreadcrumbsItemsByCommonId.ts | 17 ++++------------- 4 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 src/shared/utils/compareCommonsByLastActivity.ts diff --git a/src/shared/utils/compareCommonsByLastActivity.ts b/src/shared/utils/compareCommonsByLastActivity.ts new file mode 100644 index 0000000000..2f21f85c19 --- /dev/null +++ b/src/shared/utils/compareCommonsByLastActivity.ts @@ -0,0 +1,15 @@ +import { Common } from "@/shared/models"; + +export const compareCommonsByLastActivity = ( + prevCommon: Common, + nextCommon: Common, +): number => { + if (!nextCommon.lastActivity) { + return -1; + } + if (!prevCommon.lastActivity) { + return 1; + } + + return nextCommon.lastActivity.seconds - prevCommon.lastActivity.seconds; +}; diff --git a/src/shared/utils/index.tsx b/src/shared/utils/index.tsx index dbf698daac..74e159b1d9 100755 --- a/src/shared/utils/index.tsx +++ b/src/shared/utils/index.tsx @@ -15,6 +15,7 @@ export * from "./parseLinksForSubmission"; export * from "./proposals"; export * from "./queryParams"; export { default as request } from "./request"; +export * from "./compareCommonsByLastActivity"; export * from "./convertDatesToFirestoreTimestamps"; export * from "./convertLinkToUploadFile"; export * from "./timeAgo"; diff --git a/src/store/states/commonLayout/saga/getCommons.ts b/src/store/states/commonLayout/saga/getCommons.ts index 08d44bd956..46e4efd778 100644 --- a/src/store/states/commonLayout/saga/getCommons.ts +++ b/src/store/states/commonLayout/saga/getCommons.ts @@ -3,7 +3,7 @@ import { selectUser } from "@/pages/Auth/store/selectors"; import { CommonService, GovernanceService, ProjectService } from "@/services"; import { Awaited } from "@/shared/interfaces"; import { User } from "@/shared/models"; -import { isError } from "@/shared/utils"; +import { compareCommonsByLastActivity, isError } from "@/shared/utils"; import { ProjectsStateItem } from "../../projects"; import * as actions from "../actions"; import { getPermissionsDataByAllUserCommonMemberInfo } from "./utils"; @@ -80,8 +80,11 @@ export function* getCommons( commonId, userId, )) as Awaited>; - const projectsData: ProjectsStateItem[] = data.map( - ({ common, hasMembership, hasPermissionToAddProject }) => ({ + const projectsData: ProjectsStateItem[] = [...data] + .sort((prevItem, nextItem) => + compareCommonsByLastActivity(prevItem.common, nextItem.common), + ) + .map(({ common, hasMembership, hasPermissionToAddProject }) => ({ commonId: common.id, image: common.image, name: common.name, @@ -89,8 +92,7 @@ export function* getCommons( hasMembership, hasPermissionToAddProject, notificationsAmount: 0, - }), - ); + })); yield put( actions.getCommons.success({ diff --git a/src/store/states/multipleSpacesLayout/saga/fetchBreadcrumbsItemsByCommonId.ts b/src/store/states/multipleSpacesLayout/saga/fetchBreadcrumbsItemsByCommonId.ts index 187b0b5488..ea01e5e933 100644 --- a/src/store/states/multipleSpacesLayout/saga/fetchBreadcrumbsItemsByCommonId.ts +++ b/src/store/states/multipleSpacesLayout/saga/fetchBreadcrumbsItemsByCommonId.ts @@ -4,6 +4,7 @@ import { CommonService, GovernanceService, ProjectService } from "@/services"; import { InboxItemType } from "@/shared/constants"; import { Awaited } from "@/shared/interfaces"; import { Common, User } from "@/shared/models"; +import { compareCommonsByLastActivity } from "@/shared/utils"; import { getPermissionsDataByAllUserCommonMemberInfo } from "../../commonLayout/saga/utils"; import * as actions from "../actions"; import { selectMultipleSpacesLayoutBreadcrumbs } from "../selectors"; @@ -103,19 +104,9 @@ export function* fetchBreadcrumbsItemsByCommonId( user?.uid, )) as Awaited>; const projectsData: ProjectsStateItem[] = [...projectsInfo] - .sort((prevItem, nextItem) => { - if (!nextItem.common.lastActivity) { - return -1; - } - if (!prevItem.common.lastActivity) { - return 1; - } - - return ( - nextItem.common.lastActivity.seconds - - prevItem.common.lastActivity.seconds - ); - }) + .sort((prevItem, nextItem) => + compareCommonsByLastActivity(prevItem.common, nextItem.common), + ) .map(({ common, hasMembership, hasPermissionToAddProject }) => ({ commonId: common.id, image: common.image, From 2a48891238ecb857c072eacae1a596a6a52ce243 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 17 Oct 2023 17:21:44 +0300 Subject: [PATCH 6/7] add projects sorting in the sidenav --- src/store/states/commonLayout/saga/getProjects.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/store/states/commonLayout/saga/getProjects.ts b/src/store/states/commonLayout/saga/getProjects.ts index 978dfe64bb..1ea036ff11 100644 --- a/src/store/states/commonLayout/saga/getProjects.ts +++ b/src/store/states/commonLayout/saga/getProjects.ts @@ -3,7 +3,7 @@ import { selectUser } from "@/pages/Auth/store/selectors"; import { CommonService, GovernanceService, ProjectService } from "@/services"; import { Awaited } from "@/shared/interfaces"; import { User } from "@/shared/models"; -import { isError } from "@/shared/utils"; +import { compareCommonsByLastActivity, isError } from "@/shared/utils"; import { ProjectsStateItem } from "../../projects"; import * as actions from "../actions"; import { getPermissionsDataByAllUserCommonMemberInfo } from "./utils"; @@ -48,8 +48,11 @@ export function* getProjects( userCommonIds, permissionsData, ); - const projectsData: ProjectsStateItem[] = data.map( - ({ common, hasMembership, hasPermissionToAddProject }) => ({ + const projectsData: ProjectsStateItem[] = data + .sort((prevItem, nextItem) => + compareCommonsByLastActivity(prevItem.common, nextItem.common), + ) + .map(({ common, hasMembership, hasPermissionToAddProject }) => ({ commonId: common.id, image: common.image, name: common.name, @@ -57,8 +60,7 @@ export function* getProjects( hasMembership, hasPermissionToAddProject, notificationsAmount: 0, - }), - ); + })); yield put(actions.getProjects.success(projectsData)); } catch (error) { From 8b8985309622a03c0e311d663d011854e5334e44 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 17 Oct 2023 17:59:42 +0300 Subject: [PATCH 7/7] revert "add projects sorting in the sidenav" This reverts commit 2a488912 --- src/store/states/commonLayout/saga/getProjects.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/store/states/commonLayout/saga/getProjects.ts b/src/store/states/commonLayout/saga/getProjects.ts index 1ea036ff11..978dfe64bb 100644 --- a/src/store/states/commonLayout/saga/getProjects.ts +++ b/src/store/states/commonLayout/saga/getProjects.ts @@ -3,7 +3,7 @@ import { selectUser } from "@/pages/Auth/store/selectors"; import { CommonService, GovernanceService, ProjectService } from "@/services"; import { Awaited } from "@/shared/interfaces"; import { User } from "@/shared/models"; -import { compareCommonsByLastActivity, isError } from "@/shared/utils"; +import { isError } from "@/shared/utils"; import { ProjectsStateItem } from "../../projects"; import * as actions from "../actions"; import { getPermissionsDataByAllUserCommonMemberInfo } from "./utils"; @@ -48,11 +48,8 @@ export function* getProjects( userCommonIds, permissionsData, ); - const projectsData: ProjectsStateItem[] = data - .sort((prevItem, nextItem) => - compareCommonsByLastActivity(prevItem.common, nextItem.common), - ) - .map(({ common, hasMembership, hasPermissionToAddProject }) => ({ + const projectsData: ProjectsStateItem[] = data.map( + ({ common, hasMembership, hasPermissionToAddProject }) => ({ commonId: common.id, image: common.image, name: common.name, @@ -60,7 +57,8 @@ export function* getProjects( hasMembership, hasPermissionToAddProject, notificationsAmount: 0, - })); + }), + ); yield put(actions.getProjects.success(projectsData)); } catch (error) {