-
Notifications
You must be signed in to change notification settings - Fork 15
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
refactor: use routes constant for all internal paths #1071
Changes from 10 commits
3f81871
cbe2118
71d931c
f645f2b
06e1487
86b0fa6
63f3b3b
ac2466d
c71c29e
f7db9e8
04b40fc
297438b
a023027
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,7 +1,9 @@ | ||
const relayConfig = require('./relay.config'); | ||
const { withSentryConfig } = require('@sentry/nextjs'); | ||
const withRoutes = require('nextjs-routes/config')(); | ||
|
||
const moduleExports = { | ||
/** @type {import('next').NextConfig} */ | ||
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 gives us a new autocomplete for the config |
||
const nextConfig = { | ||
typescript: { | ||
// Save time in Vercel builds by avoiding a type check. | ||
// This is fine since we do a type check in Github Actions. | ||
|
@@ -61,4 +63,6 @@ const sentryWebpackPluginOptions = { | |
// https://github.com/getsentry/sentry-webpack-plugin#options. | ||
}; | ||
|
||
module.exports = withSentryConfig(moduleExports, sentryWebpackPluginOptions); | ||
const plugins = [withRoutes, (config) => withSentryConfig(config, sentryWebpackPluginOptions)]; | ||
|
||
module.exports = () => plugins.reduce((config, plugin) => plugin(config), nextConfig); | ||
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. Followed the thread here - cyrilwanner/next-compose-plugins#59 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
// This file will be automatically regenerated when your Next.js server is running. | ||
/* eslint-disable */ | ||
|
||
// prettier-ignore | ||
declare module "nextjs-routes" { | ||
export type Route = | ||
| { pathname: "/[username]/[collectionId]/[tokenId]"; query: Query<{ "username": string; "collectionId": string; "tokenId": string }> } | ||
| { pathname: "/[username]/[collectionId]"; query: Query<{ "username": string; "collectionId": string }> } | ||
| { pathname: "/[username]"; query: Query<{ "username": string }> } | ||
| { pathname: "/_/components"; query?: Query | undefined } | ||
| { pathname: "/_/reset"; query?: Query | undefined } | ||
| { pathname: "/announcements"; query?: Query | undefined } | ||
| { pathname: "/auth"; query?: Query | undefined } | ||
| { pathname: "/community/[contractAddress]"; query: Query<{ "contractAddress": string }> } | ||
| { pathname: "/community/poap/[contractAddress]"; query: Query<{ "contractAddress": string }> } | ||
| { pathname: "/community/tez/[contractAddress]"; query: Query<{ "contractAddress": string }> } | ||
| { pathname: "/edit"; query?: Query | undefined } | ||
| { pathname: "/gallery/[galleryId]/collection/[collectionId]/edit"; query: Query<{ "galleryId": string; "collectionId": string }> } | ||
| { pathname: "/gallery/[galleryId]/collection/create"; query: Query<{ "galleryId": string }> } | ||
| { pathname: "/gallery/[galleryId]/edit"; query: Query<{ "galleryId": string }> } | ||
| { pathname: "/home"; query?: Query | undefined } | ||
| { pathname: "/"; query?: Query | undefined } | ||
| { pathname: "/maintenance"; query?: Query | undefined } | ||
| { pathname: "/members"; query?: Query | undefined } | ||
| { pathname: "/members/poster"; query?: Query | undefined } | ||
| { pathname: "/membership/general"; query?: Query | undefined } | ||
| { pathname: "/membership/gold"; query?: Query | undefined } | ||
| { pathname: "/membership/silver"; query?: Query | undefined } | ||
| { pathname: "/nuke"; query?: Query | undefined } | ||
| { pathname: "/onboarding/add-user-info"; query?: Query | undefined } | ||
| { pathname: "/onboarding/congratulations"; query?: Query | undefined } | ||
| { pathname: "/onboarding/create"; query?: Query | undefined } | ||
| { pathname: "/onboarding/edit-collection"; query?: Query | undefined } | ||
| { pathname: "/onboarding/organize-collection"; query?: Query | undefined } | ||
| { pathname: "/onboarding/organize-gallery"; query?: Query | undefined } | ||
| { pathname: "/onboarding/welcome"; query?: Query | undefined } | ||
| { pathname: "/opengraph/collection/[collectionId]"; query: Query<{ "collectionId": string }> } | ||
| { pathname: "/opengraph/nft/[tokenId]"; query: Query<{ "tokenId": string }> } | ||
| { pathname: "/opengraph/user/[username]"; query: Query<{ "username": string }> } | ||
| { pathname: "/privacy"; query?: Query | undefined } | ||
| { pathname: "/shop"; query?: Query | undefined } | ||
| { pathname: "/terms"; query?: Query | undefined }; | ||
|
||
type Query<Params = {}> = Params & { [key: string]: string | string[] | undefined }; | ||
|
||
type QueryForPathname = { | ||
[K in Route as K["pathname"]]: Exclude<K["query"], undefined>; | ||
}; | ||
|
||
export type RoutedQuery<P extends Route["pathname"]> = QueryForPathname[P]; | ||
|
||
export type Locale = undefined; | ||
|
||
/** | ||
* A typesafe utility function for generating paths in your application. | ||
* | ||
* route({ pathname: '/foos/[foo]', query: { foo: 'bar' }}) will produce '/foos/bar'. | ||
*/ | ||
export declare function route(r: Route): string; | ||
} | ||
|
||
// prettier-ignore | ||
declare module "next/link" { | ||
import type { Route } from "nextjs-routes"; | ||
import type { LinkProps as NextLinkProps } from "next/dist/client/link"; | ||
import type { PropsWithChildren, MouseEventHandler } from "react"; | ||
export * from "next/dist/client/link"; | ||
|
||
type RouteOrQuery = Route | { query?: { [key: string]: string | string[] | undefined } }; | ||
|
||
export interface LinkProps extends Omit<NextLinkProps, "href" | "locale"> { | ||
href: RouteOrQuery; | ||
locale?: false; | ||
} | ||
|
||
declare function Link( | ||
props: PropsWithChildren<LinkProps> | ||
): DetailedReactHTMLElement< | ||
{ | ||
onMouseEnter?: MouseEventHandler<Element> | undefined; | ||
onClick: MouseEventHandler; | ||
href?: string | undefined; | ||
ref?: any; | ||
}, | ||
HTMLElement | ||
>; | ||
|
||
export default Link; | ||
} | ||
|
||
// prettier-ignore | ||
declare module "next/router" { | ||
import type { Locale, Route, RoutedQuery } from "nextjs-routes"; | ||
import type { NextRouter as Router } from "next/dist/client/router"; | ||
export * from "next/dist/client/router"; | ||
export { default } from "next/dist/client/router"; | ||
|
||
type NextTransitionOptions = NonNullable<Parameters<Router["push"]>[2]>; | ||
|
||
interface TransitionOptions extends Omit<NextTransitionOptions, 'locale'> { | ||
locale?: false; | ||
}; | ||
|
||
type RouteOrQuery = | ||
| Route | ||
| { query: { [key: string]: string | string[] | undefined } }; | ||
|
||
export interface NextRouter<P extends Route["pathname"] = Route["pathname"]> | ||
extends Omit< | ||
Router, | ||
"push" | "replace" | "locale" | "locales" | "defaultLocale" | "domainLocales" | ||
> { | ||
defaultLocale?: undefined; | ||
domainLocales?: undefined; | ||
locale?: Locale; | ||
locales?: undefined; | ||
pathname: P; | ||
push( | ||
url: RouteOrQuery, | ||
as?: string, | ||
options?: TransitionOptions | ||
): Promise<boolean>; | ||
query: RoutedQuery<P>; | ||
replace( | ||
url: RouteOrQuery, | ||
as?: string, | ||
options?: TransitionOptions | ||
): Promise<boolean>; | ||
route: P; | ||
} | ||
|
||
export function useRouter<P extends Route["pathname"]>(): NextRouter<P>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,28 +55,28 @@ export default function DesignPage() { | |
<Section> | ||
<TitleM>ButtonLink</TitleM> | ||
<Examples> | ||
<ButtonLink href="#">primary</ButtonLink> | ||
<ButtonLink href="#" pending> | ||
<ButtonLink href={{ pathname: '/' }}>primary</ButtonLink> | ||
<ButtonLink href={{ pathname: '/' }} pending> | ||
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. @tbezman Would that work? or do we need a workaround here? 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. No problem here |
||
primary | ||
</ButtonLink> | ||
<ButtonLink disabled href="#"> | ||
<ButtonLink disabled href={{ pathname: '/' }}> | ||
primary | ||
</ButtonLink> | ||
<ButtonLink disabled href="#" pending> | ||
<ButtonLink disabled href={{ pathname: '/' }} pending> | ||
primary | ||
</ButtonLink> | ||
</Examples> | ||
<Examples> | ||
<ButtonLink href="#" variant="secondary"> | ||
<ButtonLink href={{ pathname: '/' }} variant="secondary"> | ||
secondary | ||
</ButtonLink> | ||
<ButtonLink href="#" variant="secondary" pending> | ||
<ButtonLink href={{ pathname: '/' }} variant="secondary" pending> | ||
secondary | ||
</ButtonLink> | ||
<ButtonLink disabled href="#" variant="secondary"> | ||
<ButtonLink disabled href={{ pathname: '/' }} variant="secondary"> | ||
secondary | ||
</ButtonLink> | ||
<ButtonLink disabled href="#" variant="secondary" pending> | ||
<ButtonLink disabled href={{ pathname: '/' }} variant="secondary" pending> | ||
secondary | ||
</ButtonLink> | ||
</Examples> | ||
|
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.
This gives a nice autocomplete for next config options
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.
YESSSSSS