-
-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[providers] Improve and group providers (#6069)
Co-authored-by: Piero Nicolli <[email protected]> Co-authored-by: Steve Piercy <[email protected]>
- Loading branch information
1 parent
04402e5
commit 5660ae4
Showing
55 changed files
with
2,446 additions
and
976 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
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 |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import config from '@plone/registry'; | ||
import { slate } from '@plone/blocks'; | ||
import { blocksConfig } from '@plone/blocks'; | ||
|
||
const settings = { | ||
apiPath: process.env.NEXT_PUBLIC_VERCEL_URL | ||
? // Vercel does not prepend the schema to the NEXT_PUBLIC_VERCEL_URL automatic env var | ||
`https://${process.env.NEXT_PUBLIC_VERCEL_URL}` | ||
: 'http://localhost:3000', | ||
slate, | ||
}; | ||
|
||
const config = { | ||
settings, | ||
}; | ||
// @ts-expect-error Improve typings | ||
config.set('settings', settings); | ||
|
||
// @ts-expect-error Improve typings | ||
config.set('blocks', { blocksConfig }); | ||
|
||
export default config; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import ploneClient from '@plone/client'; | ||
import config from '@plone/registry'; | ||
|
||
const cli = ploneClient.initialize({ | ||
apiPath: config.settings.apiPath, | ||
}); | ||
|
||
export { cli as ploneClient }; |
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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import config from '@plone/registry'; | ||
import { blocksConfig, slate } from '@plone/blocks'; | ||
|
||
const settings = { | ||
apiPath: 'http://localhost:8080/Plone', | ||
slate, | ||
}; | ||
|
||
const config = { | ||
settings, | ||
}; | ||
// @ts-expect-error We need to fix typing | ||
config.set('settings', settings); | ||
|
||
// @ts-expect-error We need to fix typing | ||
config.set('blocks', { blocksConfig }); | ||
|
||
export default config; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { | ||
json, | ||
type LoaderFunctionArgs, | ||
type MetaFunction, | ||
} from '@remix-run/node'; | ||
import { | ||
dehydrate, | ||
QueryClient, | ||
HydrationBoundary, | ||
useQuery, | ||
} from '@tanstack/react-query'; | ||
import { flattenToAppURL } from '../utils'; | ||
import { useLoaderData, useLocation } from '@remix-run/react'; | ||
import { usePloneClient } from '@plone/providers'; | ||
import { Breadcrumbs, RenderBlocks } from '@plone/components'; | ||
import config from '@plone/registry'; | ||
import { ploneClient } from '../client'; | ||
|
||
export const meta: MetaFunction = () => { | ||
return [ | ||
{ title: 'Plone on Remix' }, | ||
{ name: 'description', content: 'Welcome to Plone on Remix!' }, | ||
]; | ||
}; | ||
|
||
const expand = ['breadcrumbs', 'navigation']; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export const loader = async ({ params, request }: LoaderFunctionArgs) => { | ||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
// With SSR, we usually want to set some default staleTime | ||
// above 0 to avoid refetching immediately on the client | ||
staleTime: 60 * 1000, | ||
}, | ||
}, | ||
}); | ||
|
||
const { getContentQuery } = ploneClient; | ||
|
||
await queryClient.prefetchQuery( | ||
getContentQuery({ path: flattenToAppURL(request.url), expand }), | ||
); | ||
|
||
return json({ dehydratedState: dehydrate(queryClient) }); | ||
}; | ||
|
||
function Page() { | ||
const { getContentQuery } = usePloneClient(); | ||
const pathname = useLocation().pathname; | ||
const { data } = useQuery(getContentQuery({ path: pathname, expand })); | ||
|
||
if (!data) return null; | ||
return ( | ||
<> | ||
<Breadcrumbs | ||
items={data['@components'].breadcrumbs.items || []} | ||
root={data['@components'].breadcrumbs.root} | ||
includeRoot | ||
/> | ||
<RenderBlocks | ||
content={data} | ||
blocksConfig={config.blocks.blocksConfig} | ||
pathname="/" | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export default function Index() { | ||
const { dehydratedState } = useLoaderData<typeof loader>(); | ||
|
||
return ( | ||
<HydrationBoundary state={dehydratedState}> | ||
<Page /> | ||
</HydrationBoundary> | ||
); | ||
} |
Oops, something went wrong.