Skip to content

Commit

Permalink
Merge pull request #1817 from ResearchHub/hotfix-load
Browse files Browse the repository at this point in the history
Fix incorrect broken references/loading in author pages
  • Loading branch information
yattias authored Aug 21, 2024
2 parents 7eed53b + cdb8250 commit 6e56988
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 14 deletions.
35 changes: 30 additions & 5 deletions components/Author/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,36 @@ export const removePublicationFromAuthorProfile = ({
.then(Helpers.parseJSON);
};

export const fetchProfileData = async ({ authorId }: { authorId: string }) => {
export const fetchProfileData = async ({
authorId,
fetchOverview = false,
fetchAchievements = false,
fetchSummary = false,
}: {
authorId: string,
fetchOverview?: boolean,
fetchAchievements?: boolean,
fetchSummary?: boolean,
}) => {
const promises:Array<Promise<any>> = [];

const profilePromise = fetchAuthorProfile({ authorId });
// const overviewPromise = fetchAuthorOverview({ authorId });
const summaryPromise = fetchAuthorSummary({ authorId });
const achievementPromise = fetchAuthorAchievements({ authorId });
promises.push(profilePromise);

if (fetchOverview) {
const overviewPromise = fetchAuthorOverview({ authorId });
promises.push(overviewPromise);
}

if (fetchSummary) {
const summaryPromise = fetchAuthorSummary({ authorId });
promises.push(summaryPromise);
}

if (fetchAchievements) {
const achievementPromise = fetchAuthorAchievements({ authorId });
promises.push(achievementPromise);
}

return Promise.all([profilePromise, /*overviewPromise, */ summaryPromise, achievementPromise]);
return Promise.all(promises);
}
7 changes: 5 additions & 2 deletions pages/author/[authorId]/bounties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,15 @@ const styles = StyleSheet.create({


export const getStaticProps: GetStaticProps = async (ctx) => {
const [profile, overview, summary, achievements] = await fetchProfileData({ authorId: ctx!.params!.authorId as string });
const [profile, summary, achievements] = await fetchProfileData({
authorId: ctx!.params!.authorId as string,
fetchSummary: true,
fetchAchievements: true,
});

return {
props: {
profile,
overview,
summary,
achievements,
},
Expand Down
7 changes: 5 additions & 2 deletions pages/author/[authorId]/comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,15 @@ const styles = StyleSheet.create({
});

export const getStaticProps: GetStaticProps = async (ctx) => {
const [profile, overview, summary, achievements] = await fetchProfileData({ authorId: ctx!.params!.authorId as string });
const [profile, summary, achievements] = await fetchProfileData({
authorId: ctx!.params!.authorId as string,
fetchSummary: true,
fetchAchievements: true,
});

return {
props: {
profile,
overview,
summary,
achievements,
},
Expand Down
7 changes: 6 additions & 1 deletion pages/author/[authorId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,12 @@ const styles = StyleSheet.create({
});

export const getStaticProps: GetStaticProps = async (ctx) => {
const [profile, /*overview,*/ summary, achievements] = await fetchProfileData({ authorId: ctx!.params!.authorId as string });
const [profile, summary, achievements] = await fetchProfileData({
authorId: ctx!.params!.authorId as string,
fetchOverview: false,
fetchSummary: true,
fetchAchievements: true,
});

return {
props: {
Expand Down
8 changes: 6 additions & 2 deletions pages/author/[authorId]/publications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,19 @@ const styles = StyleSheet.create({
});

export const getStaticProps: GetStaticProps = async (ctx) => {
const [profile, overview, summary, achievements] = await fetchProfileData({ authorId: ctx!.params!.authorId as string });
const [profile, summary, achievements] = await fetchProfileData({
authorId: ctx!.params!.authorId as string,
fetchSummary: true,
fetchAchievements: true,
});
const publicationsResponse = await fetchAuthorPublications({ authorId: ctx!.params!.authorId as string })

return {
props: {
profile,
publicationsResponse,
summary,
achievements,
publicationsResponse,
},
revalidate: 86000,
};
Expand Down
7 changes: 5 additions & 2 deletions pages/author/[authorId]/reviews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ const styles = StyleSheet.create({
});

export const getStaticProps: GetStaticProps = async (ctx) => {
const [profile, overview, summary, achievements] = await fetchProfileData({ authorId: ctx!.params!.authorId as string });
const [profile, summary, achievements] = await fetchProfileData({
authorId: ctx!.params!.authorId as string,
fetchSummary: true,
fetchAchievements: true,
});

return {
props: {
profile,
overview,
summary,
achievements,
},
Expand Down

0 comments on commit 6e56988

Please sign in to comment.