Skip to content

Commit 94ab04e

Browse files
committed
fix: remove double challenge request
1 parent b4700da commit 94ab04e

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/pages/communities/[slug]/challenges/[challenge_id]/submissions/[submission_id].tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,32 @@ import { GetServerSideProps } from "next";
1111
import { fetchCurrentCommunity } from "@/store/services/community.service";
1212
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
1313
import { wrapper } from "@/store";
14-
import { Challenge } from "@/types/course";
1514
import { initChallengeNavigationMenu } from "@/store/feature/communities/navigation.slice";
1615
import useNavigation from "@/hooks/useNavigation";
17-
import { fetchChallenge } from "@/store/services/communities/challenges";
1816
import { useRouter } from "next/router";
1917
import Loader from "@/components/ui/Loader";
2018
import Section from "@/components/ui/Section";
19+
import { useSelector } from "@/hooks/useTypedSelector";
2120

2221
export default function SubmissionPage() {
2322
const dispatch = useDispatch();
2423
const { t } = useTranslation();
2524
const navigation = useNavigation();
2625
const router = useRouter();
27-
const { slug, locale, submission_id, challenge_id } = router.query;
26+
const { slug, locale, submission_id } = router.query;
2827
const [loading, setLoading] = useState(true);
29-
const [challenge, setChallenge] = useState<Challenge | null>(null);
28+
const { current } = useSelector((state) => state.submissions);
3029

3130
const initPage = useCallback(async () => {
3231
const fetchCurrentCommunityPayload = {
3332
slug: slug as string,
3433
locale: locale as string,
3534
};
3635
setLoading(true);
37-
const [, , { data }] = await Promise.all([
38-
dispatch(fetchCurrentCommunity(fetchCurrentCommunityPayload)),
39-
dispatch(findSubmssionById({ id: submission_id as string })),
40-
dispatch(fetchChallenge({ id: challenge_id as string, relations: ["rubric", "courses", "learning-modules"] })) as unknown as any,
41-
]);
42-
setChallenge(data);
36+
await Promise.all([dispatch(fetchCurrentCommunity(fetchCurrentCommunityPayload)), dispatch(findSubmssionById({ id: submission_id as string }))]);
4337
dispatch(initChallengeNavigationMenu(navigation.community));
4438
setLoading(false);
45-
}, [challenge_id, slug, submission_id]);
39+
}, [slug, submission_id]);
4640

4741
useEffect(() => {
4842
initPage();
@@ -59,7 +53,7 @@ export default function SubmissionPage() {
5953
return (
6054
<Wrapper paths={headerPaths}>
6155
<div className="flex flex-col py-4 space-y-8">
62-
<Header title={challenge?.name} subtitle={t("communities.submission.title")} />
56+
<Header title={current?.challenge?.name} subtitle={t("communities.submission.title")} />
6357
<SubmissionView />
6458
</div>
6559
</Wrapper>

0 commit comments

Comments
 (0)