Skip to content

Commit

Permalink
Merge branch 'master' of github.com:NDLANO/ndla-frontend into learnin…
Browse files Browse the repository at this point in the history
…gpath-enter-selects-resource-resorucePicker
  • Loading branch information
MaPoKen committed Jan 16, 2025
2 parents 22330b1 + f49fcd5 commit 6be4edf
Show file tree
Hide file tree
Showing 46 changed files with 668 additions and 530 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'Release: ndla-frontend'
name: "Release: ndla-frontend"
on:
workflow_dispatch:
inputs: { }
inputs: {}
push:
branches:
- master
Expand Down Expand Up @@ -36,10 +36,13 @@ jobs:
path: ndla/deploy
- uses: actions/setup-python@v4
with:
python-version: '3.11'
python-version: ${{ vars.PYTHON_VERSION }}
- uses: abatilo/actions-poetry@v2
with:
poetry-version: "1.6.1"
poetry-version: ${{ vars.POETRY_VERSION }}
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ vars.TERRAFORM_VERSION }}
- name: Setup ~/bin directory
run: |
mkdir -p /home/runner/bin
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ RUN yarn install --immutable

# Copy necessary source files for server and client build
COPY babel.config.cjs tsconfig.json vite.config.ts panda.config.ts eslint.config.mjs postcss.config.cjs $APP_PATH/
COPY iframe-article.html iframe-embed.html index.html lti.html error.html $APP_PATH/
COPY scripts $APP_PATH/scripts

COPY src $APP_PATH/src
Expand Down

Large diffs are not rendered by default.

27 changes: 0 additions & 27 deletions error.html

This file was deleted.

27 changes: 0 additions & 27 deletions iframe-article.html

This file was deleted.

27 changes: 0 additions & 27 deletions iframe-embed.html

This file was deleted.

27 changes: 0 additions & 27 deletions index.html

This file was deleted.

27 changes: 0 additions & 27 deletions lti.html

This file was deleted.

19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
"@graphql-eslint/eslint-plugin": "^4.3.0",
"@ndla/preset-panda": "^0.0.49",
"@ndla/scripts": "^2.1.7",
"@ndla/types-backend": "^1.0.1",
"@ndla/types-embed": "^5.0.6-alpha.0",
"@ndla/types-taxonomy": "^1.0.33",
"@ndla/types-backend": "^1.0.5",
"@ndla/types-embed": "^5.0.8-alpha.0",
"@ndla/types-taxonomy": "^1.0.34",
"@pandacss/dev": "^0.48.0",
"@playwright/test": "^1.43.1",
"@playwright/test": "^1.49.1",
"@sentry/vite-plugin": "^2.22.6",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
Expand All @@ -75,6 +75,7 @@
"tsx": "^4.19.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.17.0",
"vercel": "^33.6.2",
"vite": "^6.0.2",
"vitest": "^2.1.8"
},
Expand All @@ -89,17 +90,17 @@
"@fontsource/source-sans-pro": "^4.5.9",
"@fontsource/source-serif-pro": "^4.5.7",
"@lexical/react": "^0.12.4",
"@ndla/article-converter": "^10.0.88-alpha.0",
"@ndla/article-converter": "^10.0.90-alpha.0",
"@ndla/core": "^5.0.3",
"@ndla/hooks": "^2.1.11",
"@ndla/icons": "^8.0.49-alpha.0",
"@ndla/image-search": "^11.0.76-alpha.0",
"@ndla/image-search": "^11.0.77-alpha.0",
"@ndla/licenses": "^8.0.6-alpha.0",
"@ndla/primitives": "^1.0.68-alpha.0",
"@ndla/safelink": "^7.0.69-alpha.0",
"@ndla/primitives": "^1.0.69-alpha.0",
"@ndla/safelink": "^7.0.70-alpha.0",
"@ndla/styled-system": "^0.0.30",
"@ndla/tracker": "^5.0.16-alpha.0",
"@ndla/ui": "^56.0.85-alpha.0",
"@ndla/ui": "^56.0.87-alpha.0",
"@ndla/util": "^5.0.5-alpha.0",
"@sentry/react": "^8.42.0",
"cross-env": "^7.0.3",
Expand Down
106 changes: 106 additions & 0 deletions src/Document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* Copyright (c) 2025-present, NDLA.
*
* This source code is licensed under the GPLv3 license found in the
* LICENSE file in the root directory of this source tree.
*
*/

import { ReactNode } from "react";
import type { ManifestChunk } from "vite";
import config from "./config";

interface Props {
language: string;
children?: ReactNode;
chunks?: ManifestChunk[];
devEntrypoint: string;
}

const getUniqueCss = (chunks: ManifestChunk[]) => {
const uniq = chunks.reduce((acc, curr) => {
curr.css?.forEach((css) => acc.add(css));
return acc;
}, new Set<string>());
return Array.from(uniq);
};

export const Document = ({ language, children, chunks = [], devEntrypoint }: Props) => {
const faviconEnvironment = config.ndlaEnvironment === "dev" ? "test" : config.ndlaEnvironment;
const locale = language === "nb" || language === "nn" ? "no" : language;

const [entryPoint, ...importedChunks] = chunks;
const css = getUniqueCss(chunks);

return (
<html lang={locale}>
<head>
<link rel="icon" type="image/png" sizes="32x32" href={`/static/favicon-${faviconEnvironment}-32x32.png`} />
<link rel="icon" type="image/png" sizes="16x16" href={`/static/favicon-${faviconEnvironment}-16x16.png`} />
<link
rel="apple-touch-icon"
type="image/png"
sizes="180x180"
href={`/static/apple-touch-icon-${faviconEnvironment}.png`}
/>
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1 viewport-fit=cover" />
<link href="https://api.fontshare.com/v2/css?f[]=satoshi@1&display=swap" rel="stylesheet" />
</head>
<body>
<script
type="text/javascript"
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
window._mtm = window._mtm || [];
window.originalLocation = {
originalLocation:
document.location.protocol +
"//" +
document.location.hostname +
document.location.pathname +
document.location.search,
};
window.dataLayer.push(window.originalLocation);
`,
}}
></script>
{config.runtimeType === "development" && (
<>
<script
dangerouslySetInnerHTML={{
__html: `
import RefreshRuntime from "/@react-refresh";
RefreshRuntime.injectIntoGlobalHook(window);
window.$RefreshReg$ = () => {};
window.$RefreshSig$ = () => (type) => type;
window.__vite_plugin_react_preamble_installed__ = true;
`,
}}
type="module"
/>
<script src="/@vite/client" type="module" />
<script type="module" src={`/${devEntrypoint}`}></script>
</>
)}
<script
// We're hydrating the entire document. Our config differentiates between server and client, so it's necessary to suppress any hydration warnings here. TODO: Find a better workaround for this
suppressHydrationWarning
dangerouslySetInnerHTML={{
__html: config.isClient ? "" : `window.DATA = "$WINDOW_DATA"`,
}}
></script>
{!!entryPoint && <script type="module" src={`/${entryPoint.file}`}></script>}
{css.map((file) => (
<link rel="stylesheet" href={`/${file}`} key={file} />
))}
{importedChunks.map((chunk) => (
<link rel="modulepreload" href={`/${chunk.file}`} key={chunk.file}></link>
))}
<div id="root">{children}</div>
</body>
</html>
);
};
32 changes: 20 additions & 12 deletions src/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import App from "./App";
import ResponseContext from "./components/ResponseContext";
import { VersionHashProvider } from "./components/VersionHashContext";
import { STORED_LANGUAGE_COOKIE_KEY } from "./constants";
import { Document } from "./Document";
import { entryPoints } from "./entrypoints";
import {
getLangAttributeValue,
getLocaleInfoFromPath,
Expand All @@ -49,7 +51,7 @@ declare global {
}

const {
DATA: { config, serverPath, serverResponse },
DATA: { config, serverPath, serverResponse, chunks },
} = window;

initSentry(config);
Expand Down Expand Up @@ -151,7 +153,7 @@ const LanguageWrapper = ({ basename }: { basename?: string }) => {
);
};

const renderOrHydrate = (container: HTMLElement, children: ReactNode) => {
const renderOrHydrate = (container: Element | Document, children: ReactNode) => {
if (config.disableSSR) {
const root = createRoot(container);
root.render(children);
Expand All @@ -161,14 +163,20 @@ const renderOrHydrate = (container: HTMLElement, children: ReactNode) => {
};

renderOrHydrate(
document.getElementById("root")!,
<I18nextProvider i18n={i18n}>
<ApolloProvider client={client}>
<ResponseContext.Provider value={{ status: serverResponse }}>
<VersionHashProvider value={versionHash}>
<LanguageWrapper basename={basename} />
</VersionHashProvider>
</ResponseContext.Provider>
</ApolloProvider>
</I18nextProvider>,
document,
<Document
chunks={chunks}
language={isValidLocale(storedLanguage) ? storedLanguage : config.defaultLocale}
devEntrypoint={entryPoints.default}
>
<I18nextProvider i18n={i18n}>
<ApolloProvider client={client}>
<ResponseContext.Provider value={{ status: serverResponse }}>
<VersionHashProvider value={versionHash}>
<LanguageWrapper basename={basename} />
</VersionHashProvider>
</ResponseContext.Provider>
</ApolloProvider>
</I18nextProvider>
</Document>,
);
Loading

0 comments on commit 6be4edf

Please sign in to comment.