-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
feat: update next generator #369
base: main
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ export default class NextGenerator extends BaseGenerator { | |
this.routeAddedtoServer = false; | ||
this.registerTemplates(`next/`, [ | ||
// components | ||
"components/common/Layout.tsx", | ||
"components/common/Wrapper.tsx", | ||
"components/common/Pagination.tsx", | ||
"components/common/ReferenceLinks.tsx", | ||
"components/foo/List.tsx", | ||
|
@@ -25,12 +25,12 @@ export default class NextGenerator extends BaseGenerator { | |
"types/item.ts", | ||
|
||
// pages | ||
"pages/foos/[id]/index.tsx", | ||
"pages/foos/[id]/edit.tsx", | ||
"pages/foos/page/[page].tsx", | ||
"pages/foos/index.tsx", | ||
"pages/foos/create.tsx", | ||
"pages/_app.tsx", | ||
"app/foos/[id]/page.tsx", | ||
"app/foos/[id]/edit/page.tsx", | ||
"app/foos/page/[page]/page.tsx", | ||
"app/foos/page.tsx", | ||
"app/foos/create/page.tsx", | ||
"app/layout.tsx", | ||
|
||
// utils | ||
"utils/dataAccess.ts", | ||
|
@@ -81,9 +81,12 @@ export default class NextGenerator extends BaseGenerator { | |
|
||
// Copy with patterned name | ||
this.createDir(`${dir}/components/${context.lc}`); | ||
this.createDir(`${dir}/pages/${context.lc}s`); | ||
this.createDir(`${dir}/pages/${context.lc}s/[id]`); | ||
this.createDir(`${dir}/pages/${context.lc}s/page`); | ||
this.createDir(`${dir}/app/${context.lc}s`); | ||
this.createDir(`${dir}/app/${context.lc}s/[id]`); | ||
this.createDir(`${dir}/app/${context.lc}s/create`); | ||
this.createDir(`${dir}/app/${context.lc}s/[id]/edit`); | ||
this.createDir(`${dir}/app/${context.lc}s/page`); | ||
this.createDir(`${dir}/app/${context.lc}s/page/[page]`); | ||
[ | ||
// components | ||
"components/%s/List.tsx", | ||
|
@@ -92,11 +95,11 @@ export default class NextGenerator extends BaseGenerator { | |
"components/%s/Form.tsx", | ||
|
||
// pages | ||
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. we can change this to app |
||
"pages/%ss/[id]/index.tsx", | ||
"pages/%ss/[id]/edit.tsx", | ||
"pages/%ss/page/[page].tsx", | ||
"pages/%ss/index.tsx", | ||
"pages/%ss/create.tsx", | ||
"app/%ss/[id]/page.tsx", | ||
"app/%ss/[id]/edit/page.tsx", | ||
"app/%ss/page/[page]/page.tsx", | ||
"app/%ss/page.tsx", | ||
"app/%ss/create/page.tsx", | ||
].forEach((pattern) => | ||
this.createFileFromPattern(pattern, dir, [context.lc], context) | ||
); | ||
|
@@ -107,7 +110,7 @@ export default class NextGenerator extends BaseGenerator { | |
// copy with regular name | ||
[ | ||
// components | ||
"components/common/Layout.tsx", | ||
"components/common/Wrapper.tsx", | ||
"components/common/Pagination.tsx", | ||
"components/common/ReferenceLinks.tsx", | ||
|
||
|
@@ -116,7 +119,7 @@ export default class NextGenerator extends BaseGenerator { | |
"types/item.ts", | ||
|
||
// pages | ||
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. we can change this to app |
||
"pages/_app.tsx", | ||
"app/layout.tsx", | ||
|
||
// utils | ||
"utils/dataAccess.ts", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"use client"; | ||
|
||
import type { Metadata } from "next"; | ||
import { useQuery } from "react-query"; | ||
|
||
import { Form } from "../../../../components/{{{lc}}}/Form"; | ||
import { {{{ucf}}} } from "../../../../types/{{{ucf}}}"; | ||
import { customFetch, FetchResponse } from "../../../../utils/dataAccess"; | ||
|
||
|
||
const get{{{ucf}}} = async (id: string|string[]|undefined) => id ? await customFetch<{{{ucf}}}>(`/{{{name}}}/${id}`) : Promise.resolve(undefined); | ||
|
||
type Props = { | ||
params: { id: string }; | ||
}; | ||
|
||
export default function Page({ params }: Props) { | ||
const { id } = params; | ||
|
||
const { data: { data: {{lc}} } = {} } = useQuery<FetchResponse<{{{ucf}}}> | undefined>(['{{{lc}}}', id], () => get{{{ucf}}}(id)); | ||
|
||
if (!{{{lc}}}) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div> | ||
<title>{`Edit {{{ucf}}} ${ {{{lc}}}["@id"]}`}</title> | ||
<Form {{{lc}}}={ {{{lc}}} } /> | ||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"use client"; | ||
|
||
import { useQuery } from "react-query"; | ||
|
||
import { Show } from "../../../components/{{{lc}}}/Show"; | ||
import { {{{ucf}}} } from "../../../types/{{{ucf}}}"; | ||
import { customFetch, FetchResponse } from "../../../utils/dataAccess"; | ||
import { useMercure } from "../../../utils/mercure"; | ||
|
||
const get{{{ucf}}} = async (id: string|string[]|undefined) => id ? await customFetch<{{{ucf}}}>(`/{{{name}}}/${id}`) : Promise.resolve(undefined); | ||
|
||
type Props = { | ||
params: { id: string }; | ||
}; | ||
|
||
export default function Page({ params }: Props) { | ||
const { id } = params; | ||
|
||
|
||
const { data: { data: {{lc}}, hubURL } = { hubURL: null, text: '' } } = | ||
useQuery<FetchResponse<{{{ucf}}}> | undefined>(['{{{lc}}}', id], () => get{{{ucf}}}(id)); | ||
const {{{lc}}}Data = useMercure({{lc}}, hubURL); | ||
|
||
if (!{{{lc}}}Data) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div> | ||
<title>{`Show {{{ucf}}} ${ {{{lc}}}Data["@id"]}`}</title> | ||
<Show {{{lc}}}={ {{{lc}}}Data } /> | ||
</div> | ||
); | ||
}; |
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. This file is not necessary. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { NextComponentType, NextPageContext } from "next"; | ||
import Head from "next/head"; | ||
|
||
import { Form } from "../../components/{{{lc}}}/Form"; | ||
|
||
const Page: NextComponentType<NextPageContext> = () => ( | ||
<div> | ||
<div> | ||
<Head> | ||
<title>Create {{{ucf}}}</title> | ||
</Head> | ||
</div> | ||
<Form /> | ||
</div> | ||
); | ||
|
||
export default Page; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { Metadata } from "next"; | ||
import { Form } from "../../../components/{{{lc}}}/Form"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Create {{{ucf}}}", | ||
}; | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
<Form /> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { Metadata } from "next"; | ||
import PageList from "../../components/{{{lc}}}/PageList"; | ||
|
||
export const metadata: Metadata = { | ||
title: "{{{ucf}}} List", | ||
}; | ||
|
||
export default PageList; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import PageList from "../../../../components/{{{lc}}}/PageList"; | ||
|
||
export default PageList; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from "react"; | ||
import type { Metadata } from "next"; | ||
import Wrapper from "../components/common/Wrapper"; | ||
import "../styles/style.css"; | ||
|
||
export const metadata: Metadata = { | ||
title: "API Platform Create Client", | ||
description: | ||
"Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.", | ||
}; | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body> | ||
<Wrapper>{children}</Wrapper> | ||
</body> | ||
</html> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"use client"; | ||
|
||
import { ReactNode, useState } from "react"; | ||
import { QueryClient, QueryClientProvider } from "react-query"; | ||
|
||
const Wrapper = ({ children }: { children: ReactNode }) => { | ||
const [queryClient] = useState(() => new QueryClient()); | ||
|
||
return ( | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
); | ||
}; | ||
|
||
export default Wrapper; |
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.
we can change this to app