Skip to content

Commit

Permalink
close #379
Browse files Browse the repository at this point in the history
  • Loading branch information
nandorojo committed Apr 27, 2023
1 parent 92deb38 commit 10080fe
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/image/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ describe('resolveSourceFromImgAttributes', () => {
sizes: `(max-width: 600px) 480px, 800px`,
src: 'elva-fairy.jpg',
}).uri
).toThrow()
).not.toThrow()
})
})
32 changes: 0 additions & 32 deletions src/image/image.types.test.ts

This file was deleted.

25 changes: 25 additions & 0 deletions src/router/parse-next-path.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { parseNextPath } from './parse-next-path'

describe('parseNextPath', () => {
it('should handle arrays', () => {
expect(
parseNextPath({
pathname: '/',
query: {
ids: [1, 2],
},
})
).toEqual('/?ids=1&ids=2')
})

it('supports dynamic routes', () => {
expect(
parseNextPath({
pathname: '/[id]',
query: {
id: 1,
},
})
).toEqual('/1')
})
})
13 changes: 11 additions & 2 deletions src/router/parse-next-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const parseNextPath = (from: Parameters<NextRouter['push']>[0]) => {
// but I can't see why you would use this with RN + Next.js
if (typeof from == 'object' && from.query && typeof from.query == 'object') {
const query = { ...from.query }
// replace dynamic routes
// and [...param] syntax
for (const key in query) {
if (path.includes(`[${key}]`)) {
path = path.replace(`[${key}]`, `${query[key] ?? ''}`)
Expand All @@ -21,11 +23,18 @@ const parseNextPath = (from: Parameters<NextRouter['push']>[0]) => {
}
}
}

if (Object.keys(query).length) {
// add query param separator
path += '?'
for (const key in query) {
if (query[key] != null) {
path += `${key}=${query[key]}&`
const value = query[key]
if (Array.isArray(value)) {
value.forEach((item) => {
path += `${key}=${item}&`
})
} else if (value != null) {
path += `${key}=${value}&`
}
}
if (path.endsWith('&') || path.endsWith('?')) {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"jsx": "react-jsx"
},
"include": ["./src"],
"exclude": ["**/__mocks__/*", "**/__tests__/*"],
"exclude": ["**/__mocks__/*", "**/__tests__/*", "**.*.test.ts"],
"ts-node": {
// these options are overrides used only by ts-node
"compilerOptions": {
Expand Down

2 comments on commit 10080fe

@vercel
Copy link

@vercel vercel bot commented on 10080fe Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

solito-s9oj – ./example-monorepos/with-tailwind/apps/next

solito-s9oj.vercel.app
solito-s9oj-beat-gig.vercel.app
solito-s9oj-git-master-beat-gig.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 10080fe Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

solito-app – ./example-monorepos/blank/apps/next

solito-app-fernandorojo.vercel.app
solito-app-git-master-fernandorojo.vercel.app
solito-app.vercel.app
example.solito.dev

Please sign in to comment.