-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upgrade to nextjs 14 and react 18 (#430)
- Loading branch information
Showing
47 changed files
with
940 additions
and
806 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
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
'use client'; | ||
|
||
import createCache from '@emotion/cache'; | ||
import { CacheProvider } from '@emotion/react'; | ||
import { useServerInsertedHTML } from 'next/navigation'; | ||
|
||
import { ReactNode, useState } from 'react'; | ||
|
||
import CssBaseline from '@mui/material/CssBaseline'; | ||
import { ThemeProvider } from '@mui/material/styles'; | ||
|
||
import { theme } from '../src/config/theme'; | ||
|
||
type Props = { | ||
options: any; | ||
children: ReactNode; | ||
}; | ||
|
||
// This implementation is from emotion-js | ||
// https://github.com/emotion-js/emotion/issues/2928#issuecomment-1319747902 | ||
// eslint-disable-next-line react/function-component-definition | ||
export default function ThemeRegistry(props: Props) { | ||
const { options, children } = props; | ||
|
||
// Remove the server-side injected CSS. | ||
// useEffect(() => { | ||
// const jssStyles = document.querySelector('#jss-server-side'); | ||
// if (jssStyles && jssStyles.parentElement) { | ||
// jssStyles.parentElement.removeChild(jssStyles); | ||
// } | ||
// }, []); | ||
|
||
const [{ cache, flush }] = useState(() => { | ||
const newCache = createCache(options); | ||
newCache.compat = true; | ||
const prevInsert = newCache.insert; | ||
let inserted: string[] = []; | ||
newCache.insert = (...args) => { | ||
const serialized = args[1]; | ||
if (newCache.inserted[serialized.name] === undefined) { | ||
inserted.push(serialized.name); | ||
} | ||
return prevInsert(...args); | ||
}; | ||
const newFlush = () => { | ||
const prevInserted = inserted; | ||
inserted = []; | ||
return prevInserted; | ||
}; | ||
return { cache: newCache, flush: newFlush }; | ||
}); | ||
|
||
useServerInsertedHTML(() => { | ||
const names = flush(); | ||
if (names.length === 0) { | ||
return null; | ||
} | ||
let styles = ''; | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const name of names) { | ||
styles += cache.inserted[name]; | ||
} | ||
return ( | ||
<style | ||
key={cache.key} | ||
data-emotion={`${cache.key} ${names.join(' ')}`} | ||
dangerouslySetInnerHTML={{ | ||
__html: styles, | ||
}} | ||
/> | ||
); | ||
}); | ||
|
||
return ( | ||
<CacheProvider value={cache}> | ||
<ThemeProvider theme={theme}> | ||
<CssBaseline /> | ||
{children} | ||
</ThemeProvider> | ||
</CacheProvider> | ||
); | ||
} |
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,51 @@ | ||
import Head from 'next/head'; | ||
|
||
import { dehydrate } from 'react-query/core'; | ||
|
||
import Hydrate from '../../src/components/HydrateClient'; | ||
import Wrapper from '../../src/components/common/Wrapper'; | ||
import AllCollections from '../../src/components/pages/AllCollections'; | ||
import { APP_AUTHOR } from '../../src/config/constants'; | ||
import getQueryClient from '../../src/config/get-query-client'; | ||
import LIBRARY from '../../src/langs/constants'; | ||
import en from '../../src/langs/en.json'; | ||
import { buildSeo } from '../seo'; | ||
|
||
export async function generateMetadata() { | ||
// todo: get lang from location and crawler | ||
// question: how to get language from | ||
// @ts-ignore | ||
const t = (s: string): string => en[s]; | ||
|
||
return buildSeo({ | ||
title: t(LIBRARY.GRAASP_LIBRARY), | ||
description: t(LIBRARY.GRAASP_LIBRARY_DESCRIPTION), | ||
author: APP_AUTHOR, | ||
}); | ||
} | ||
|
||
const Page = async () => { | ||
const queryClient = getQueryClient(); | ||
// await queryClient.prefetchQuery(['items', 'collections', 'all'], () => | ||
// Api.getAllPublishedItems({}, { API_HOST: GRAASP_API_HOST, axios }), | ||
// ); | ||
const dehydratedState = dehydrate(queryClient); | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>Graasp Library</title> | ||
<meta | ||
name="viewport" | ||
content="minimum-scale=1, initial-scale=1, width=device-width" | ||
/> | ||
</Head> | ||
<Hydrate state={dehydratedState}> | ||
<Wrapper dehydratedState={dehydratedState}> | ||
<AllCollections /> | ||
</Wrapper> | ||
</Hydrate> | ||
</> | ||
); | ||
}; | ||
export default Page; |
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,20 @@ | ||
export const dynamic = 'force-dynamic'; // defaults to force-static | ||
|
||
export async function GET() { | ||
return new Response( | ||
JSON.stringify({ | ||
// eslint-disable-next-line no-underscore-dangle | ||
// @ts-ignore | ||
coverage: global.__coverage__ || null, | ||
}), | ||
{ | ||
status: 200, | ||
headers: { | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Methods': 'GET', | ||
'Access-Control-Allow-Headers': 'Content-Type, Authorization', | ||
'Content-Type': 'application/json', | ||
}, | ||
}, | ||
); | ||
} |
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,13 @@ | ||
export const dynamic = 'force-dynamic'; // defaults to force-static | ||
|
||
export async function GET() { | ||
return new Response(JSON.stringify({ status: 'ok' }), { | ||
status: 200, | ||
headers: { | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Methods': 'GET', | ||
'Access-Control-Allow-Headers': 'Content-Type, Authorization', | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
} |
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,74 @@ | ||
// import { useRouter } from 'next/navigation'; | ||
// import { useEffect } from 'react'; | ||
// import ReactGA from 'react-ga4'; | ||
// import { hasAcceptedCookies } from '@graasp/sdk'; | ||
// import { ENV, UrlSearch } from '../src/config/constants'; | ||
// import createEmotionCache from '../src/config/createEmotionCache'; | ||
// import { GA_MEASUREMENT_ID, NODE_ENV } from '../src/config/env'; | ||
// Client-side cache, shared for the whole session of the user in the browser. | ||
// const clientSideEmotionCache = createEmotionCache(); | ||
// import { Api, DATA_KEYS, configureQueryClient } from '@graasp/query-client'; | ||
import Head from 'next/head'; | ||
|
||
import { dehydrate } from 'react-query/core'; | ||
|
||
import Hydrate from '../../../src/components/HydrateClient'; | ||
import Collection from '../../../src/components/collection/Collection'; | ||
import Wrapper from '../../../src/components/common/Wrapper'; | ||
import { APP_AUTHOR } from '../../../src/config/constants'; | ||
import getQueryClient from '../../../src/config/get-query-client'; | ||
import LIBRARY from '../../../src/langs/constants'; | ||
import en from '../../../src/langs/en.json'; | ||
import { buildSeo } from '../../seo'; | ||
|
||
export async function generateMetadata() { | ||
// TODO: get id from params | ||
|
||
// const name = collection?.name || ''; | ||
// const parsedDescription = collection?.description || ''; | ||
// const author = collection?.creator?.name || ''; | ||
// // todo: handle image | ||
// const imageUrl = DEFAULT_ITEM_IMAGE_PATH; | ||
|
||
// todo: get lang from location and crawler | ||
// question: how to get language from | ||
// @ts-ignore | ||
const t = (s: string): string => en[s]; | ||
|
||
return buildSeo({ | ||
title: t(LIBRARY.GRAASP_LIBRARY), | ||
description: t(LIBRARY.GRAASP_LIBRARY_DESCRIPTION), | ||
author: APP_AUTHOR, // todo: use item creator? | ||
}); | ||
} | ||
|
||
const Page = async ({ params: { id } }: { params: { id: string } }) => { | ||
const queryClient = getQueryClient(); | ||
const dehydratedState = dehydrate(queryClient); | ||
|
||
// if (id) { | ||
// // prefetch data in query client | ||
|
||
// await queryClient.prefetchQuery(DATA_KEYS.buildItemKey(id), () => | ||
// Api.getItem(id, { ...QUERY_CLIENT_OPTIONS, axios }), | ||
// ); | ||
// } | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>Graasp Library</title> | ||
<meta | ||
name="viewport" | ||
content="minimum-scale=1, initial-scale=1, width=device-width" | ||
/> | ||
</Head> | ||
<Hydrate state={dehydratedState}> | ||
<Wrapper dehydratedState={dehydratedState}> | ||
<Collection id={id} /> | ||
</Wrapper> | ||
</Hydrate> | ||
</> | ||
); | ||
}; | ||
export default Page; |
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,19 @@ | ||
import 'react-toastify/dist/ReactToastify.css'; | ||
|
||
import ThemeRegistry from './ThemeRegistry'; | ||
import Providers from './providers'; | ||
|
||
const RootLayout = ({ children }: { children: React.ReactNode }) => { | ||
return ( | ||
// TODO: change lang | ||
<html lang="en"> | ||
<body> | ||
<Providers> | ||
<ThemeRegistry options={{ key: 'mui' }}>{children}</ThemeRegistry> | ||
</Providers> | ||
</body> | ||
</html> | ||
); | ||
}; | ||
|
||
export default RootLayout; |
Oops, something went wrong.