-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c60c4e3
commit ce1972e
Showing
8 changed files
with
123 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 28 additions & 3 deletions
31
src/pages/common/components/FeedCard/components/LinkedItemMark/LinkedItemMark.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/pages/common/components/FeedCard/components/LinkedItemMark/hooks/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./useCommonPaths"; |
49 changes: 49 additions & 0 deletions
49
src/pages/common/components/FeedCard/components/LinkedItemMark/hooks/useCommonPaths.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { CommonService } from "@/services"; | ||
import { useIsMounted, useLoadingState } from "@/shared/hooks"; | ||
import { LoadingState } from "@/shared/interfaces"; | ||
import { Common } from "@/shared/models"; | ||
|
||
type Data = Common[][]; | ||
|
||
interface Return extends LoadingState<Data> { | ||
fetchCommonPaths: (commonIdsForPaths: string[]) => void; | ||
} | ||
|
||
export const useCommonPaths = (): Return => { | ||
const isMounted = useIsMounted(); | ||
const [state, setState] = useLoadingState<Data>([]); | ||
|
||
const fetchCommonPaths = async (commonIdsForPaths: string[]) => { | ||
setState({ | ||
loading: true, | ||
fetched: false, | ||
data: [], | ||
}); | ||
|
||
let commons: Data = []; | ||
|
||
try { | ||
commons = await Promise.all( | ||
commonIdsForPaths.map((commonId) => | ||
CommonService.getCommonAndParents(commonId), | ||
), | ||
); | ||
commons = commons.filter((path) => path.length > 0); | ||
} catch (err) { | ||
commons = []; | ||
} finally { | ||
if (isMounted()) { | ||
setState({ | ||
loading: false, | ||
fetched: true, | ||
data: commons, | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
return { | ||
...state, | ||
fetchCommonPaths, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters