-
-
Notifications
You must be signed in to change notification settings - Fork 131
fix: fine tuning ad fixes #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { GetStaticPaths, GetStaticProps, NextComponentType, NextPageContext } from "next"; | ||
import { Form } from "../../../components/{{{lc}}}/Form"; | ||
import { {{{ucf}}} } from "../../../types/{{{ucf}}}"; | ||
import { fetch } from "../../../utils/dataAccess"; | ||
import Head from "next/head"; | ||
import DefaultErrorPage from "next/error"; | ||
import { Form } from "../../../components/{{{lc}}}/Form"; | ||
import { {{{ucf}}} } from "../../../types/{{{ucf}}}"; | ||
import { fetch, getPaths } from "../../../utils/dataAccess"; | ||
|
||
interface Props { | ||
{{{lc}}}: {{{ucf}}}; | ||
|
@@ -27,43 +27,19 @@ const Page: NextComponentType<NextPageContext, Props, Props> = ({ {{{lc}}} }) => | |
}; | ||
|
||
export const getStaticProps: GetStaticProps = async ({ params }) => { | ||
const response = await fetch(`/{{{name}}}/${params.id}`); | ||
|
||
return { | ||
props: { | ||
{{{lc}}}: await fetch(`/{{{name}}}/${params.id}`), | ||
{{{lc}}}: response.data, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it better to pass the full response (including headers etc)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated after the use of react query |
||
}, | ||
revalidate: 1, | ||
}; | ||
} | ||
|
||
export const getStaticPaths: GetStaticPaths = async () => { | ||
try { | ||
const response = await fetch("/{{{name}}}"); | ||
} catch (e) { | ||
console.error(e); | ||
|
||
return { | ||
paths: [], | ||
fallback: true, | ||
}; | ||
} | ||
|
||
const view = response.data['{{{hydraPrefix}}}view']; | ||
const paths = response.data["{{{hydraPrefix}}}member"].map(({{{lc}}}) => `${ {{~lc}}['@id'] }/edit`); | ||
|
||
if (view) { | ||
try { | ||
const { | ||
'{{{hydraPrefix}}}last': last | ||
} = view; | ||
for (let page = 2; page <= parseInt(last.replace(/^\/{{{name}}}\?page=(\d+)/, '$1')); page++) { | ||
paths.concat( | ||
await fetch(`/{{{name}}}?page=${page}`).data["{{{hydraPrefix}}}member"].map(({{{lc}}}) => `${ {{~lc}}['@id'] }/edit`) | ||
); | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
const response = await fetch("/{{{name}}}"); | ||
const paths = await getPaths(response, "{{{name}}}", true); | ||
|
||
return { | ||
paths, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
import { GetStaticPaths, GetStaticProps, NextComponentType, NextPageContext } from "next"; | ||
import { Show } from "../../../components/{{{lc}}}/Show"; | ||
import { {{{ucf}}} } from "../../../types/{{{ucf}}}"; | ||
import { fetch } from "../../../utils/dataAccess"; | ||
import Head from "next/head"; | ||
import DefaultErrorPage from "next/error"; | ||
import { Show } from "../../../components/{{{lc}}}/Show"; | ||
import { {{{ucf}}} } from "../../../types/{{{ucf}}}"; | ||
import { fetch, getPaths } from "../../../utils/dataAccess"; | ||
import { useMercure } from "../../../utils/mercure"; | ||
|
||
interface Props { | ||
{{{lc}}}: {{{ucf}}}; | ||
hubURL: null | string; | ||
text: string; | ||
}; | ||
|
||
const Page: NextComponentType<NextPageContext, Props, Props> = (props) => { | ||
const {{{lc}}} = props.hubURL === null ? props.{{{lc}}} : useMercure(props.{{{lc}}}, props.hubURL); | ||
const Page: NextComponentType<NextPageContext, Props, Props> = ({ {{{lc}}}, hubURL, text }) => { | ||
const {{{lc}}}Data = useMercure({{{lc}}}, hubURL); | ||
|
||
if (!{{{lc}}}) { | ||
if (!{{{lc}}}Data) { | ||
return <DefaultErrorPage statusCode={404} />; | ||
} | ||
|
||
|
@@ -25,7 +26,7 @@ const Page: NextComponentType<NextPageContext, Props, Props> = (props) => { | |
<title>{`Show {{{ucf}}} ${ {{~lc}}['@id'] }`}</title> | ||
</Head> | ||
</div> | ||
<Show {{{lc}}}={ {{{lc}}} } text={ props.text } /> | ||
<Show {{{lc}}}={ {{{lc}}}Data } text={text} /> | ||
</div> | ||
); | ||
}; | ||
|
@@ -44,34 +45,8 @@ export const getStaticProps: GetStaticProps = async ({ params }) => { | |
} | ||
|
||
export const getStaticPaths: GetStaticPaths = async () => { | ||
try { | ||
const response = await fetch("/{{{name}}}"); | ||
} catch (e) { | ||
console.error(e); | ||
|
||
return { | ||
paths: [], | ||
fallback: true, | ||
}; | ||
} | ||
|
||
const view = response.data['{{{hydraPrefix}}}view']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. response declared in try block but used outside |
||
const paths = response.data["{{{hydraPrefix}}}member"].map(({{{lc}}}) => `${ {{~lc}}['@id'] }`); | ||
|
||
if (view) { | ||
try { | ||
const { | ||
'{{{hydraPrefix}}}last': last | ||
} = view; | ||
for (let page = 2; page <= parseInt(last.replace(/^\/{{{name}}}\?page=(\d+)/, '$1')); page++) { | ||
paths.concat( | ||
await fetch(`/{{{name}}}?page=${page}`).data["{{{hydraPrefix}}}member"].map(({{{lc}}}) => `${ {{~lc}}['@id'] }`) | ||
); | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
const response = await fetch("/{{{name}}}"); | ||
const paths = await getPaths(response, "{{{name}}}", false); | ||
|
||
return { | ||
paths, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import has from "lodash/has" | ||
|
||
export const isItem = <T>(data: any): data is T => has(data, "@id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReferenceLinks not used on Show.tsx I just cleaned the code