Skip to content

Commit

Permalink
remove getRootCommon duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymikhadyuk committed Sep 26, 2023
1 parent 4033e3d commit cfbc6da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
13 changes: 1 addition & 12 deletions src/pages/commonFeed/hooks/useCommonData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -20,17 +20,6 @@ interface Return extends CombinedState {
resetCommonData: () => void;
}

const getRootCommon = async (
parentCommon?: Common | null,
rootCommonId?: string,
): Promise<Common | null> => {
if (parentCommon && parentCommon.id === rootCommonId) {
return parentCommon;
}

return rootCommonId ? CommonService.getCommonById(rootCommonId) : null;
};

export const useCommonData = (userId?: string): Return => {
const [state, setState] = useState<State>({
loading: false,
Expand Down
5 changes: 4 additions & 1 deletion src/shared/hooks/useCases/useFullCommonData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ interface Return extends CombinedState {
resetCommonData: () => void;
}

const getRootCommon = async (
export const getRootCommon = async (
parentCommon?: Common | null,
rootCommonId?: string,
): Promise<Common | null> => {
if (!rootCommonId) {
return null;
}
if (parentCommon && parentCommon.id === rootCommonId) {
return parentCommon;
}
Expand Down

0 comments on commit cfbc6da

Please sign in to comment.