Skip to content

Commit

Permalink
fix: app sdk routing
Browse files Browse the repository at this point in the history
  • Loading branch information
marcolink committed Oct 8, 2024
1 parent 0d75f14 commit f1d37db
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
28 changes: 14 additions & 14 deletions examples/remix/app/hooks/useAppSdkRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ export const useAppSdkRouter = () => {
return;
}

const LocationRoutes = {
[AppSDK.locations.LOCATION_APP_CONFIG]: 'app-config',
[AppSDK.locations.LOCATION_ENTRY_FIELD]: 'field',
[AppSDK.locations.LOCATION_ENTRY_EDITOR]: 'entry-editor',
[AppSDK.locations.LOCATION_DIALOG]: 'dialog',
[AppSDK.locations.LOCATION_ENTRY_SIDEBAR]: 'sidebar',
[AppSDK.locations.LOCATION_PAGE]: 'page',
[AppSDK.locations.LOCATION_HOME]: 'home',
};
const Locations = [
AppSDK.locations.LOCATION_APP_CONFIG,
AppSDK.locations.LOCATION_ENTRY_FIELD,
AppSDK.locations.LOCATION_ENTRY_EDITOR,
AppSDK.locations.LOCATION_DIALOG,
AppSDK.locations.LOCATION_ENTRY_SIDEBAR,
AppSDK.locations.LOCATION_PAGE,
AppSDK.locations.LOCATION_HOME,
] as const;

const path = Object.keys(LocationRoutes).find((key) => sdk?.location.is(key));
const requestedLocation = Locations.find((key) => sdk?.location.is(key));

if (!path) {
console.error('Unknown app location');
if (!requestedLocation) {
console.error(`Unknown app location`);
return;
}

if (location.pathname === `/${path}`) {
if (location.pathname === `/${requestedLocation}`) {
return;
}

const params = new URLSearchParams(sdk?.ids);
return navigate(`/${path}?${params.toString()}`);
return navigate(`/${requestedLocation}?${params.toString()}`);
}, [sdk]);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Card } from '@contentful/f36-card';
import { Heading } from '@contentful/f36-typography';

export default function Field() {
export default function EntryField() {
return (
<Card>
<Heading>Field Location</Heading>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { useContentfulAutoResizer } from '~/hooks/useContentfulAutoResizer';
import { Heading } from '@contentful/f36-typography';
import { Card } from '@contentful/f36-card';

export default function Sidebar() {
export default function EntrySidebar() {
useContentfulAutoResizer();

return (
<Card>
<Heading>Sidebar Location</Heading>
<Heading>Entry Sidebar Location</Heading>
</Card>
);
}
12 changes: 12 additions & 0 deletions examples/remix/app/routes/home.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Card } from '@contentful/f36-card';
import { Heading, Subheading } from '@contentful/f36-typography';
import { useInBrowserSdk } from '~/hooks/useInBrowserSdk';
import { useWithContentfulUsers } from '~/hooks/useWithContentfulUsers';

export default function Home() {
return (
<Card>
<Heading>Home Location</Heading>
</Card>
);
}

0 comments on commit f1d37db

Please sign in to comment.