From cfbc6da1b12c01d9a92aa04569dd6bf2e3e74a7d Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 26 Sep 2023 09:51:04 +0300 Subject: [PATCH] remove getRootCommon duplication --- src/pages/commonFeed/hooks/useCommonData/index.ts | 13 +------------ .../hooks/useCases/useFullCommonData/index.ts | 5 ++++- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/pages/commonFeed/hooks/useCommonData/index.ts b/src/pages/commonFeed/hooks/useCommonData/index.ts index 1d43d9ef2d..0192d87fd6 100644 --- a/src/pages/commonFeed/hooks/useCommonData/index.ts +++ b/src/pages/commonFeed/hooks/useCommonData/index.ts @@ -5,8 +5,8 @@ import { CommonService, GovernanceService, } from "@/services"; +import { getRootCommon } from "@/shared/hooks/useCases/useFullCommonData"; import { useCommonSubscription } from "@/shared/hooks/useCases/useFullCommonData/useCommonSubscription"; -import { Common } from "@/shared/models"; import { State, CombinedState } from "./types"; import { useGovernanceSubscription } from "./useGovernanceSubscription"; @@ -20,17 +20,6 @@ interface Return extends CombinedState { resetCommonData: () => void; } -const getRootCommon = async ( - parentCommon?: Common | null, - rootCommonId?: string, -): Promise => { - if (parentCommon && parentCommon.id === rootCommonId) { - return parentCommon; - } - - return rootCommonId ? CommonService.getCommonById(rootCommonId) : null; -}; - export const useCommonData = (userId?: string): Return => { const [state, setState] = useState({ loading: false, diff --git a/src/shared/hooks/useCases/useFullCommonData/index.ts b/src/shared/hooks/useCases/useFullCommonData/index.ts index 51cf684699..f518175eff 100644 --- a/src/shared/hooks/useCases/useFullCommonData/index.ts +++ b/src/shared/hooks/useCases/useFullCommonData/index.ts @@ -15,10 +15,13 @@ interface Return extends CombinedState { resetCommonData: () => void; } -const getRootCommon = async ( +export const getRootCommon = async ( parentCommon?: Common | null, rootCommonId?: string, ): Promise => { + if (!rootCommonId) { + return null; + } if (parentCommon && parentCommon.id === rootCommonId) { return parentCommon; }