-
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.
555 - Server-side query prefetching (SEO, no loadings) (#557)
* simplify/unify `apiAxios` * refactor: simplify sharing `getServerSideProps` between seminar subpages * #555 PoC - prefetch Posts on server * #555 - prefetch flat pages on server * #555 - prefetch competitions on server * #555 - prefetch menu and footer queries * #555 - commonQueries on all sites, rework reset-password params * #555 - queryClient `staleTime` - don't refetch on client immediately * fix `myprofile` call and use new `apiOptions`
- Loading branch information
1 parent
4a2b433
commit 38cef03
Showing
49 changed files
with
473 additions
and
210 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {ILogo} from '@/components/PageLayout/Footer/Logo' | ||
import {IPost} from '@/components/Posts/Post' | ||
import {FlatPage} from '@/types/api/base' | ||
import {MenuItemShort} from '@/types/api/cms' | ||
import {Competition, Event} from '@/types/api/competition' | ||
import {Profile} from '@/types/api/personal' | ||
import {SeminarId} from '@/utils/useSeminarInfo' | ||
|
||
import {apiAxios} from './apiAxios' | ||
|
||
type OurCompetition = Omit<Competition, 'history_events'> & {history_events: Event[]} | ||
|
||
export const apiOptions = { | ||
cms: { | ||
flatPage: { | ||
byUrl: (pageUrl: string) => ({ | ||
queryKey: ['cms', 'flat-page', 'by-url', pageUrl], | ||
queryFn: () => apiAxios.get<FlatPage>(`/cms/flat-page/by-url/${pageUrl}`).then((res) => res.data), | ||
}), | ||
}, | ||
logo: () => ({ | ||
queryKey: ['cms', 'logo'], | ||
queryFn: () => apiAxios.get<ILogo[]>('/cms/logo').then((res) => res.data), | ||
}), | ||
menuItem: { | ||
onSite: (seminarId: SeminarId, type: 'menu' | 'footer') => ({ | ||
queryKey: ['cms', 'menu-item', 'on-site', seminarId, type], | ||
queryFn: () => | ||
apiAxios.get<MenuItemShort[]>(`/cms/menu-item/on-site/${seminarId}?type=${type}`).then((res) => res.data), | ||
}), | ||
}, | ||
post: { | ||
visible: (seminarId: SeminarId) => ({ | ||
queryKey: ['cms', 'post', 'visible', seminarId], | ||
queryFn: () => apiAxios.get<IPost[]>(`/cms/post/visible?sites=${seminarId}`).then((res) => res.data), | ||
}), | ||
}, | ||
}, | ||
competition: { | ||
competition: { | ||
slug: (slug: string) => ({ | ||
queryKey: ['competition', 'competition', 'slug', slug], | ||
queryFn: () => apiAxios.get<OurCompetition>(`/competition/competition/slug/${slug}`).then((res) => res.data), | ||
}), | ||
}, | ||
}, | ||
personal: { | ||
profiles: { | ||
myprofile: () => ({ | ||
queryKey: ['personal', 'profiles', 'myprofile'], | ||
queryFn: () => apiAxios.get<Profile>('/personal/profiles/myprofile').then((res) => res.data), | ||
}), | ||
}, | ||
}, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {QueryClient} from '@tanstack/react-query' | ||
|
||
import {getSeminarInfoFromPathname} from '@/utils/useSeminarInfo' | ||
|
||
import {apiOptions} from './api' | ||
|
||
export const commonQueries = (queryClient: QueryClient, resolvedUrl: string) => { | ||
const {seminarId} = getSeminarInfoFromPathname(resolvedUrl) | ||
|
||
return [ | ||
queryClient.prefetchQuery(apiOptions.cms.menuItem.onSite(seminarId, 'menu')), | ||
queryClient.prefetchQuery(apiOptions.cms.menuItem.onSite(seminarId, 'footer')), | ||
queryClient.prefetchQuery(apiOptions.cms.logo()), | ||
] | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import StromStaticPage, {seminarBasedGetServerSideProps} from '../strom/[page]' | ||
import StromStaticPage, {getServerSideProps} from '../strom/[page]' | ||
|
||
export default StromStaticPage | ||
|
||
export const getServerSideProps = seminarBasedGetServerSideProps('malynar') | ||
export {getServerSideProps} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import {NextPage} from 'next' | ||
|
||
import Page from '../../../strom/admin/opravit-ulohu/[[...params]]' | ||
import Page, {getServerSideProps} from '../../../strom/admin/opravit-ulohu/[[...params]]' | ||
|
||
const ProblemAdministration: NextPage = () => { | ||
return <Page /> | ||
} | ||
|
||
export default ProblemAdministration | ||
|
||
export {getServerSideProps} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import {NextPage} from 'next' | ||
|
||
import Page from '../../../strom/admin/opravovanie/[[...params]]' | ||
import Page, {getServerSideProps} from '../../../strom/admin/opravovanie/[[...params]]' | ||
|
||
const SemesterAdmnistration: NextPage = () => { | ||
return <Page /> | ||
} | ||
|
||
export default SemesterAdmnistration | ||
|
||
export {getServerSideProps} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import StaticPage, {competitionBasedGetServerSideProps} from '../../strom/akcie/[[...params]]' | ||
import StaticPage, {getServerSideProps} from '../../strom/akcie/[[...params]]' | ||
|
||
export default StaticPage | ||
|
||
export const getServerSideProps = competitionBasedGetServerSideProps('malynar') | ||
export {getServerSideProps} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import {NextPage} from 'next' | ||
|
||
import Page from '../../strom/archiv/[[...params]]' | ||
import Page, {getServerSideProps} from '../../strom/archiv/[[...params]]' | ||
|
||
const Archiv: NextPage = () => { | ||
return <Page /> | ||
} | ||
|
||
export default Archiv | ||
|
||
export {getServerSideProps} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import {NextPage} from 'next' | ||
|
||
import Page from '../strom/index' | ||
import Page, {getServerSideProps} from '../strom/index' | ||
|
||
const Malynar: NextPage = () => { | ||
const Home: NextPage = () => { | ||
return <Page /> | ||
} | ||
|
||
export default Malynar | ||
export default Home | ||
|
||
export {getServerSideProps} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import {NextPage} from 'next' | ||
|
||
import Page from '../../strom/profil/index' | ||
import Page, {getServerSideProps} from '../../strom/profil/index' | ||
|
||
const Profile: NextPage = () => { | ||
return <Page /> | ||
} | ||
|
||
export default Profile | ||
|
||
export {getServerSideProps} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import {NextPage} from 'next' | ||
|
||
import Page from '../../strom/profil/uprava' | ||
import Page, {getServerSideProps} from '../../strom/profil/uprava' | ||
|
||
const Profil: NextPage = () => { | ||
return <Page /> | ||
} | ||
|
||
export default Profil | ||
|
||
export {getServerSideProps} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import {NextPage} from 'next' | ||
|
||
import Page from '../strom/registracia' | ||
import Page, {getServerSideProps} from '../strom/registracia' | ||
|
||
const Register: NextPage = () => { | ||
return <Page /> | ||
} | ||
|
||
export default Register | ||
|
||
export {getServerSideProps} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import PasswordReset from '../../strom/reset-password/[...resetToken]' | ||
import PasswordReset, {getServerSideProps} from '../../strom/reset-password/[...resetToken]' | ||
|
||
export default PasswordReset | ||
|
||
export {getServerSideProps} from '../../strom/reset-password/[...resetToken]' | ||
export {getServerSideProps} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import {NextPage} from 'next' | ||
|
||
import Page from '../../strom/verify-email/[verificationKey]' | ||
import Page, {getServerSideProps} from '../../strom/verify-email/[verificationKey]' | ||
|
||
const Verify: NextPage = () => { | ||
return <Page /> | ||
} | ||
|
||
export default Verify | ||
|
||
export {getServerSideProps} |
Oops, something went wrong.