-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
1,387 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Local Netlify folder | ||
.netlify | ||
.cache | ||
.turbo | ||
dist | ||
styles.css | ||
persisted-store |
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 |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
.netlify | ||
.cache | ||
.turbo | ||
public | ||
dist | ||
styles.css | ||
persisted-store |
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 @@ | ||
export * from '@amazeelabs/bridge-waku'; |
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,20 @@ | ||
'use client'; | ||
import React, { PropsWithChildren } from 'react'; | ||
import { ErrorBoundary } from 'react-error-boundary'; | ||
|
||
export function BrokenLinkHandler({ children }: PropsWithChildren) { | ||
return ( | ||
<ErrorBoundary | ||
onError={(error) => { | ||
if ((error as any).statusCode === 404) { | ||
window.location.reload(); | ||
} else { | ||
console.error(error); | ||
} | ||
}} | ||
fallback={<h1>Something went wrong.</h1>} | ||
> | ||
{children} | ||
</ErrorBoundary> | ||
); | ||
} |
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,74 @@ | ||
import { | ||
AnyOperationId, | ||
OperationExecutor, | ||
OperationVariables, | ||
} from '@custom/schema'; | ||
import React, { PropsWithChildren } from 'react'; | ||
|
||
/** | ||
* Create an executor that operates against a Drupal endpoint. | ||
*/ | ||
function drupalExecutor(endpoint: string, forward: boolean = true) { | ||
return async function <OperationId extends AnyOperationId>( | ||
id: OperationId, | ||
variables?: OperationVariables<OperationId>, | ||
) { | ||
const url = new URL(endpoint); | ||
const isMutation = id.includes('Mutation:'); | ||
if (isMutation) { | ||
const { data, errors } = await ( | ||
await fetch(url, { | ||
method: 'POST', | ||
credentials: 'include', | ||
body: JSON.stringify({ | ||
queryId: id, | ||
variables: variables || {}, | ||
}), | ||
headers: forward | ||
? { | ||
'SLB-Forwarded-Proto': window.location.protocol.slice(0, -1), | ||
'SLB-Forwarded-Host': window.location.hostname, | ||
'SLB-Forwarded-Port': window.location.port, | ||
'Content-Type': 'application/json', | ||
} | ||
: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}) | ||
).json(); | ||
if (errors) { | ||
throw errors; | ||
} | ||
return data; | ||
} else { | ||
url.searchParams.set('queryId', id); | ||
url.searchParams.set('variables', JSON.stringify(variables || {})); | ||
const { data, errors } = await ( | ||
await fetch(url, { | ||
credentials: 'include', | ||
headers: forward | ||
? { | ||
'SLB-Forwarded-Proto': window.location.protocol.slice(0, -1), | ||
'SLB-Forwarded-Host': window.location.hostname, | ||
'SLB-Forwarded-Port': window.location.port, | ||
} | ||
: {}, | ||
}) | ||
).json(); | ||
if (errors) { | ||
throw errors; | ||
} | ||
return data; | ||
} | ||
}; | ||
} | ||
|
||
export function DrupalExecutor({ children }: PropsWithChildren) { | ||
return ( | ||
<OperationExecutor | ||
executor={drupalExecutor('http://localhost:8888/graphql', false)} | ||
> | ||
{children} | ||
</OperationExecutor> | ||
); | ||
} |
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,91 @@ | ||
import '@custom/ui/styles.css'; | ||
|
||
import { | ||
AnyOperationId, | ||
ListPagesQuery, | ||
Locale, | ||
LocationProvider, | ||
OperationResult, | ||
OperationVariables, | ||
} from '@custom/schema'; | ||
import { Frame } from '@custom/ui/routes/Frame'; | ||
import { HomePage } from '@custom/ui/routes/HomePage'; | ||
import { NotFoundPage } from '@custom/ui/routes/NotFoundPage'; | ||
import { Page } from '@custom/ui/routes/Page'; | ||
import React from 'react'; | ||
import { createPages } from 'waku'; | ||
|
||
import { BrokenLinkHandler } from './broken-link-handler.js'; | ||
import { ExecutorsClient } from './executors-client.js'; | ||
import { ExecutorsServer } from './executors-server.js'; | ||
|
||
async function query<TOperation extends AnyOperationId>( | ||
operation: TOperation, | ||
variables: OperationVariables<TOperation>, | ||
) { | ||
const url = new URL('http://localhost:8888/graphql'); | ||
url.searchParams.set('queryId', operation); | ||
url.searchParams.set('variables', JSON.stringify(variables || {})); | ||
const { data, errors } = await (await fetch(url)).json(); | ||
if (errors) { | ||
throw errors; | ||
} | ||
return data as OperationResult<TOperation>; | ||
} | ||
|
||
export default createPages(async ({ createPage, createLayout }) => { | ||
createLayout({ | ||
render: 'static', | ||
path: '/', | ||
component: ({ children, path }) => ( | ||
<BrokenLinkHandler> | ||
<LocationProvider | ||
currentLocation={{ | ||
pathname: path, | ||
searchParams: new URLSearchParams(), | ||
search: '', | ||
hash: '', | ||
}} | ||
> | ||
<ExecutorsServer> | ||
<ExecutorsClient> | ||
<Frame>{children}</Frame> | ||
</ExecutorsClient> | ||
</ExecutorsServer> | ||
</LocationProvider> | ||
</BrokenLinkHandler> | ||
), | ||
}); | ||
|
||
Object.values(Locale).forEach((lang) => { | ||
createPage({ | ||
render: 'static', | ||
path: `/${lang}`, | ||
component: HomePage, | ||
}); | ||
}); | ||
|
||
createPage({ | ||
render: 'static', | ||
path: '/404', | ||
component: NotFoundPage, | ||
}); | ||
|
||
// TODO: Paginate properly to not load all nodes in Drupal | ||
const pagePaths = new Set<string>(); | ||
const pages = await query(ListPagesQuery, { args: 'pageSize=0&page=1' }); | ||
pages.ssgPages?.rows.forEach((page) => { | ||
page?.translations?.forEach((translation) => { | ||
if (translation?.path) { | ||
pagePaths.add(translation.path); | ||
} | ||
}); | ||
}); | ||
|
||
createPage({ | ||
render: 'static', | ||
path: '/[...path]', | ||
staticPaths: [...pagePaths].map((path) => path.substring(1).split('/')), | ||
component: Page, | ||
}); | ||
}); |
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 @@ | ||
'use client'; | ||
import React, { PropsWithChildren } from 'react'; | ||
|
||
import { DrupalExecutor } from './drupal-executor.js'; | ||
|
||
export function ExecutorsClient({ children }: PropsWithChildren) { | ||
return <DrupalExecutor>{children}</DrupalExecutor>; | ||
} |
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,7 @@ | ||
import React, { PropsWithChildren } from 'react'; | ||
|
||
import { DrupalExecutor } from './drupal-executor.js'; | ||
|
||
export function ExecutorsServer({ children }: PropsWithChildren) { | ||
return <DrupalExecutor>{children}</DrupalExecutor>; | ||
} |
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,15 @@ | ||
import React, { StrictMode } from 'react'; | ||
import { createRoot, hydrateRoot } from 'react-dom/client'; | ||
import { Router } from 'waku/router/client'; | ||
|
||
const rootElement = ( | ||
<StrictMode> | ||
<Router /> | ||
</StrictMode> | ||
); | ||
|
||
if (document.body.dataset.hydrate) { | ||
hydrateRoot(document.body, rootElement); | ||
} else { | ||
createRoot(document.body).render(rootElement); | ||
} |
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,7 @@ | ||
export default { | ||
resolve: { | ||
alias: { | ||
'@amazeelabs/bridge': './src/bridge.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/eslintrc.json", | ||
"root": true, | ||
"settings": { | ||
"react": { | ||
"version": "18" | ||
} | ||
}, | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:promise/recommended", | ||
"plugin:react/recommended", | ||
"prettier" | ||
], | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint", | ||
"promise", | ||
"simple-import-sort", | ||
"import", | ||
"no-only-tests", | ||
"react", | ||
"react-hooks" | ||
], | ||
"rules": { | ||
"no-unused-vars": ["off"], | ||
"@typescript-eslint/no-unused-vars": ["error"], | ||
"simple-import-sort/imports": "error", | ||
"sort-imports": "off", | ||
"import/first": "error", | ||
"import/newline-after-import": "error", | ||
"import/no-duplicates": "error", | ||
"no-only-tests/no-only-tests": "error", | ||
"react-hooks/rules-of-hooks": "error", | ||
"react-hooks/exhaustive-deps": "warn", | ||
"react/prop-types": ["off"], | ||
"react/prefer-stateless-function": ["error"], | ||
"react/react-in-jsx-scope": ["off"] | ||
} | ||
} |
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 @@ | ||
build |
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,4 @@ | ||
** | ||
!build/* | ||
!CHANGELOG.md | ||
!README.md |
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 @@ | ||
"@amazeelabs/prettier-config" |
Oops, something went wrong.