generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Whether internal or external, and specify the source in the callback along with the new value. Add query spy component to all pages for browsers where changes in the URL are not easily visible (eg: on mobile).
- Loading branch information
Showing
9 changed files
with
99 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { QuerySpy } from '../../../components/query-spy' | ||
|
||
export default function E2EPageLayout({ | ||
children | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<> | ||
<QuerySpy /> | ||
{children} | ||
</> | ||
) | ||
} |
2 changes: 2 additions & 0 deletions
2
src/layouts/demo-page.tsx → src/components/demo-page-layout.tsx
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,49 @@ | ||
'use client' | ||
|
||
import { useSearchParams } from 'next/navigation' | ||
import React from 'react' | ||
import { subscribeToQueryUpdates } from '../../dist' | ||
|
||
export const QuerySpy: React.FC = () => { | ||
const initialSearchParams = useSearchParams() | ||
const [search, setSearch] = React.useState<URLSearchParams>(() => { | ||
if (typeof location !== 'object') { | ||
// SSR | ||
const out = new URLSearchParams() | ||
if (!initialSearchParams) { | ||
return out | ||
} | ||
for (const [key, value] of initialSearchParams) { | ||
out.set(key, value) | ||
} | ||
return out | ||
} else { | ||
return new URLSearchParams(location.search) | ||
} | ||
}) | ||
|
||
React.useLayoutEffect( | ||
() => subscribeToQueryUpdates(({ search }) => setSearch(search)), | ||
[] | ||
) | ||
const qs = search.toString() | ||
|
||
return ( | ||
<pre | ||
aria-label="Querystring spy" | ||
aria-description="For browsers where the query is hard to see (eg: on mobile)" | ||
style={{ | ||
padding: '4px 6px', | ||
border: 'solid 1px gray', | ||
borderRadius: '4px', | ||
overflow: 'auto' | ||
}} | ||
> | ||
{qs ? ( | ||
'?' + qs | ||
) : ( | ||
<span style={{ fontStyle: 'italic' }}>{'<empty query>'}</span> | ||
)} | ||
</pre> | ||
) | ||
} |
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