Skip to content

Commit

Permalink
Load terms-types as a dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndpnt committed Nov 15, 2024
1 parent b770542 commit 6114dd7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
1 change: 1 addition & 0 deletions additional.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ type WithClassname<T = {}> = T & { className?: string };
declare module '@opentermsarchive/engine/fetch';
declare module '@opentermsarchive/engine/extract';
declare module '@opentermsarchive/engine/sourceDocument';
declare module '@opentermsarchive/terms-types';

declare module '*.svg' {
const content: React.FC<React.SVGProps<SVGSVGElement>>;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"@headlessui/react": "^1.5.0",
"@opentermsarchive/engine": "^2.5.0",
"@opentermsarchive/terms-types": "^1.4.0",
"@socialgouv/matomo-next": "^1.2.1",
"@svgr/webpack": "^5.5.0",
"accept-language": "^3.0.18",
Expand Down
24 changes: 0 additions & 24 deletions src/modules/Github/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
const DOCUMENT_TYPES_URL =
'https://raw.githubusercontent.com/OpenTermsArchive/terms-types/main/termsTypes.json';

import { Octokit } from 'octokit';
import axios from 'axios';
import merge from 'lodash/fp/merge';

const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
Expand Down Expand Up @@ -31,26 +27,6 @@ export interface Author {

export type Commits = Commit[];

export interface DocumentTypes {
[key: string]: {
commitment: {
writer: string;
audience: string;
object: string;
};
};
}

export const getDocumentTypes = async () => {
try {
const { data: documentTypes } = await axios.get<DocumentTypes>(DOCUMENT_TYPES_URL);
return documentTypes;
} catch (e) {
console.error(e);
return {};
}
};

export const getFileContent = async ({
branch,
filePath,
Expand Down
17 changes: 14 additions & 3 deletions src/pages/service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import React from 'react';
import pick from 'lodash/fp/pick';
import api from 'utils/api';
import classNames from 'classnames';
import { getDocumentTypes, DocumentTypes } from 'modules/Github/api';
import s from './service.module.css';
import useNotifier from 'hooks/useNotifier';
import { useRouter } from 'next/router';
Expand All @@ -37,6 +36,16 @@ type DocumentSelectableField = 'select' | 'remove';
type ConfigSelectableField = 'hidden';
type SelectableField = DocumentSelectableField | ConfigSelectableField;

export interface DocumentTypes {
[key: string]: {
commitment: {
writer: string;
audience: string;
object: string;
};
};
}

const ServicePage = ({
documentTypes,
contributorFormMdx,
Expand Down Expand Up @@ -697,11 +706,13 @@ Thank you very much`;
export const getStaticProps = async (props: any) => {
const isGitlab = process.env.NEXT_PUBLIC_REPO_TYPE === "GITLAB";

const TERMS_TYPES = await import('@opentermsarchive/terms-types');

return JSON.parse(
JSON.stringify({
props: {
...props,
documentTypes: await getDocumentTypes(),
documentTypes: TERMS_TYPES.default || TERMS_TYPES,
contributorFormMdx: await loadMdxFile(
{
load: 'mdx',
Expand All @@ -717,7 +728,7 @@ export const getStaticProps = async (props: any) => {
},
revalidate: 60 * 5,
})
)
);
};

export default ServicePage;

0 comments on commit 6114dd7

Please sign in to comment.