-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from tinloof/tin-2231-country-selector
[WIP] Implement country selector
- Loading branch information
Showing
71 changed files
with
417 additions
and
167 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 was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
8 changes: 4 additions & 4 deletions
8
.../products/[handle]/_parts/breadcrumbs.tsx → .../products/[handle]/_parts/breadcrumbs.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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,52 @@ | ||
import type {PageProps} from "@/types"; | ||
import type {PropsWithChildren} from "react"; | ||
|
||
import {CountryCodeProvider} from "@/components/context/country-code-context"; | ||
import {ExitPreview} from "@/components/exit-preview"; | ||
import {TailwindIndicator} from "@/components/tailwind-indicator"; | ||
import cache from "next/cache"; | ||
import {draftMode} from "next/headers"; | ||
import VisualEditing from "next-sanity/visual-editing/client-component"; | ||
|
||
type LayoutProps = PropsWithChildren< | ||
Omit<PageProps<"countryCode">, "searchParams"> | ||
>; | ||
|
||
export default function Layout({children, params}: LayoutProps) { | ||
const shouldEnableDraftModeToggle = | ||
process.env.NODE_ENV === "development" && draftMode().isEnabled; | ||
return ( | ||
<CountryCodeProvider countryCode={params.countryCode}> | ||
<body className="relative flex min-h-screen min-w-min-screen flex-col overflow-x-clip"> | ||
{children} | ||
{draftMode().isEnabled && ( | ||
<VisualEditing | ||
refresh={async (payload) => { | ||
"use server"; | ||
if (!draftMode().isEnabled) { | ||
console.debug( | ||
"Skipped manual refresh because draft mode is not enabled", | ||
); | ||
return; | ||
} | ||
if (payload.source === "mutation") { | ||
if (payload.document.slug?.current) { | ||
const tag = `${payload.document._type}:${payload.document.slug.current}`; | ||
console.log("Revalidate slug", tag); | ||
await cache.revalidateTag(tag); | ||
} | ||
console.log("Revalidate tag", payload.document._type); | ||
return cache.revalidateTag(payload.document._type); | ||
} | ||
await cache.revalidatePath("/", "layout"); | ||
}} | ||
/> | ||
)} | ||
<TailwindIndicator /> | ||
{shouldEnableDraftModeToggle && ( | ||
<ExitPreview enable={draftMode().isEnabled} /> | ||
)} | ||
</body> | ||
</CountryCodeProvider> | ||
); | ||
} |
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,32 @@ | ||
"use client"; | ||
import type {PropsWithChildren} from "react"; | ||
|
||
import {createContext, useContext} from "react"; | ||
|
||
type CountryCodeContextType = { | ||
countryCode: string; | ||
}; | ||
|
||
type CountryCodeProviderProps = PropsWithChildren<CountryCodeContextType>; | ||
|
||
export const CountryCodeContext = createContext< | ||
CountryCodeContextType | undefined | ||
>(undefined); | ||
|
||
export function CountryCodeProvider({ | ||
children, | ||
countryCode, | ||
}: CountryCodeProviderProps) { | ||
return ( | ||
<CountryCodeContext.Provider value={{countryCode}}> | ||
{children} | ||
</CountryCodeContext.Provider> | ||
); | ||
} | ||
export function useCountryCode() { | ||
const context = useContext(CountryCodeContext); | ||
if (context === undefined) { | ||
throw new Error("useCountryCode must be used within a CountryCodeProvider"); | ||
} | ||
return context.countryCode; | ||
} |
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
Oops, something went wrong.