Skip to content

Commit 8da20fa

Browse files
still works ??
1 parent 62d075b commit 8da20fa

13 files changed

+81
-138
lines changed

gatsby-browser.js

-3
This file was deleted.

gatsby-config.js

-11
This file was deleted.

gatsby-node.js

-3
This file was deleted.

gatsby-node.ts

+24-39
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import * as fs from 'fs';
2-
import importFresh from 'import-fresh';
3-
import * as path from 'path';
4-
import { SECTIONS } from './content/ordering';
1+
import { execSync } from 'child_process';
2+
import fs from 'fs';
3+
import path from 'path';
4+
import * as freshOrdering from './content/ordering';
55
import { createXdmNode } from './src/gatsby/create-xdm-node';
66
import {
77
checkInvalidUsacoMetadata,
88
getProblemInfo,
99
getProblemURL,
1010
ProblemMetadata,
1111
} from './src/models/problem';
12-
const { execSync } = require('child_process');
1312

1413
// Questionable hack to get full commit history so that timestamps work
1514
try {
@@ -28,9 +27,7 @@ try {
2827
exports.onCreateNode = async api => {
2928
const { node, actions, loadNodeContent, createContentDigest, createNodeId } =
3029
api;
31-
3230
const { createNodeField, createNode, createParentChildLink } = actions;
33-
3431
if (node.internal.type === `File` && node.ext === '.mdx') {
3532
const content = await loadNodeContent(node);
3633
const xdmNode = await createXdmNode(
@@ -44,7 +41,6 @@ exports.onCreateNode = async api => {
4441
createNode(xdmNode);
4542
createParentChildLink({ parent: node, child: xdmNode });
4643
}
47-
4844
function transformObject(obj, id) {
4945
const problemInfoNode = {
5046
...obj,
@@ -59,7 +55,6 @@ exports.onCreateNode = async api => {
5955
createNode(problemInfoNode);
6056
createParentChildLink({ parent: node, child: problemInfoNode });
6157
}
62-
6358
const isExtraProblems =
6459
node.internal.mediaType === 'application/json' &&
6560
node.sourceInstanceName === 'content' &&
@@ -79,15 +74,15 @@ exports.onCreateNode = async api => {
7974
: `in node ${node.id}`;
8075
throw new Error(`Unable to parse JSON: ${hint}`);
8176
}
82-
8377
const moduleId = parsedContent['MODULE_ID'];
8478
if (!moduleId && !isExtraProblems) {
8579
throw new Error(
8680
'Module ID not found in problem JSON file: ' + node.absolutePath
8781
);
8882
}
89-
90-
const freshOrdering = importFresh<any>('./content/ordering');
83+
//const freshOrdering = importFresh<any>(
84+
// path.join(__dirname, './content/ordering.ts')
85+
//);
9186
if (!isExtraProblems && !(moduleId in freshOrdering.moduleIDToSectionMap)) {
9287
throw new Error(
9388
'.problems.json moduleId does not correspond to module: ' +
@@ -96,13 +91,14 @@ exports.onCreateNode = async api => {
9691
node.absolutePath
9792
);
9893
}
99-
10094
Object.keys(parsedContent).forEach(tableId => {
10195
if (tableId === 'MODULE_ID') return;
10296
try {
10397
parsedContent[tableId].forEach((metadata: ProblemMetadata) => {
10498
checkInvalidUsacoMetadata(metadata);
105-
const freshOrdering = importFresh<any>('./content/ordering');
99+
//const freshOrdering = importFresh<any>(
100+
// path.join(__dirname, './content/ordering.ts')
101+
//);
106102
transformObject(
107103
{
108104
...getProblemInfo(metadata, freshOrdering),
@@ -121,7 +117,6 @@ exports.onCreateNode = async api => {
121117
throw new Error(e);
122118
}
123119
});
124-
125120
if (moduleId) {
126121
// create a node that contains all of a module's problems
127122
const id = createNodeId(`${node.id} >>> ModuleProblemLists`);
@@ -130,8 +125,9 @@ exports.onCreateNode = async api => {
130125
.map(listId => ({
131126
listId,
132127
problems: parsedContent[listId].map(x => {
133-
const freshOrdering = importFresh<any>('./content/ordering');
134-
128+
//const freshOrdering = importFresh<any>(
129+
// path.join(__dirname, './content/ordering.ts')
130+
//);
135131
return {
136132
...getProblemInfo(x, freshOrdering),
137133
};
@@ -158,8 +154,8 @@ exports.onCreateNode = async api => {
158154
node.internal.type === 'Xdm' &&
159155
node.fileAbsolutePath.includes('content')
160156
) {
161-
const ordering = importFresh<any>('./content/ordering');
162-
if (!(node.frontmatter.id in ordering.moduleIDToSectionMap)) {
157+
// const ordering = importFresh<any>('./content/ordering.ts');
158+
if (!(node.frontmatter.id in freshOrdering.moduleIDToSectionMap)) {
163159
throw new Error(
164160
'module id does not show up in ordering: ' +
165161
node.frontmatter.id +
@@ -170,9 +166,8 @@ exports.onCreateNode = async api => {
170166
createNodeField({
171167
name: 'division',
172168
node,
173-
value: ordering.moduleIDToSectionMap[node.frontmatter.id],
169+
value: freshOrdering.moduleIDToSectionMap[node.frontmatter.id],
174170
});
175-
176171
// https://angelos.dev/2019/09/add-support-for-modification-times-in-gatsby/
177172
const gitAuthorTime = execSync(
178173
`git log -1 --pretty=format:%aI ${node.fileAbsolutePath}`
@@ -208,7 +203,6 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
208203
});
209204
});
210205
});
211-
212206
const result = await graphql(`
213207
query {
214208
modules: allXdm(filter: { fileAbsolutePath: { regex: "/content/" } }) {
@@ -226,7 +220,6 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
226220
}
227221
}
228222
}
229-
230223
solutions: allXdm(
231224
filter: { fileAbsolutePath: { regex: "/solutions/" } }
232225
) {
@@ -240,7 +233,6 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
240233
}
241234
}
242235
}
243-
244236
problems: allProblemInfo {
245237
edges {
246238
node {
@@ -271,7 +263,6 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
271263
if (result.errors) {
272264
reporter.panicOnBuild('🚨 ERROR: Loading "createPages" query');
273265
}
274-
275266
// Check to make sure problems with the same unique ID have consistent information, and that there aren't duplicate slugs
276267
const problems = result.data.problems.edges;
277268
let problemSlugs = {}; // maps slug to problem unique ID
@@ -328,13 +319,11 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
328319
problemURLToUniqueID[node.url] = node.uniqueId;
329320
});
330321
// End problems check
331-
332-
const moduleTemplate = require.resolve(`./src/templates/moduleTemplate.tsx`);
322+
const moduleTemplate = path.resolve(`./src/templates/moduleTemplate.tsx`);
333323
const modules = result.data.modules.edges;
334324
modules.forEach(({ node }) => {
335325
if (!node.fields?.division) return;
336326
const path = `/${node.fields.division}/${node.frontmatter.id}`;
337-
338327
if (node.frontmatter.redirects) {
339328
node.frontmatter.redirects.forEach(fromPath => {
340329
createRedirect({
@@ -345,7 +334,6 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
345334
});
346335
});
347336
}
348-
349337
createPage({
350338
path,
351339
component: moduleTemplate,
@@ -354,7 +342,9 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
354342
},
355343
});
356344

357-
const freshOrdering = importFresh<any>('./content/ordering');
345+
// const freshOrdering = importFresh<any>(
346+
// path.join(__dirname, './content/ordering.ts')
347+
// );
358348
if (node.frontmatter.prerequisites)
359349
for (const prereq of node.frontmatter.prerequisites) {
360350
if (!(prereq in freshOrdering.moduleIDToSectionMap)) {
@@ -368,9 +358,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
368358
}
369359
}
370360
});
371-
const solutionTemplate = require.resolve(
372-
`./src/templates/solutionTemplate.tsx`
373-
);
361+
const solutionTemplate = path.resolve(`./src/templates/solutionTemplate.tsx`);
374362
const solutions = result.data.solutions.edges;
375363
solutions.forEach(({ node }) => {
376364
try {
@@ -437,12 +425,9 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
437425
throw e;
438426
}
439427
});
440-
441428
// Generate Syllabus Pages //
442-
const syllabusTemplate = require.resolve(
443-
`./src/templates/syllabusTemplate.tsx`
444-
);
445-
SECTIONS.forEach(division => {
429+
const syllabusTemplate = path.resolve(`./src/templates/syllabusTemplate.tsx`);
430+
freshOrdering.SECTIONS.forEach(division => {
446431
createPage({
447432
path: `/${division}`,
448433
component: syllabusTemplate,
@@ -538,7 +523,7 @@ exports.onCreateWebpackConfig = ({ actions, stage, loaders, plugins }) => {
538523
actions.setWebpackConfig({
539524
resolve: {
540525
alias: {
541-
path: require.resolve('path-browserify'),
526+
path: path.resolve('path-browserify'),
542527
},
543528
fallback: {
544529
fs: false,

gatsby-ssr.js

-6
This file was deleted.

src/components/DynamicMarkdownRenderer/DynamicMarkdownRenderer.tsx

+24-32
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import * as React from 'react';
22
import { useEffect, useRef, useState } from 'react';
3-
import ReactDOM from 'react-dom';
43
// eslint-disable-next-line
54
// @ts-ignore
65
import { Fragment, jsx, jsxs } from 'react/jsx-runtime';
7-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
8-
// @ts-ignore
9-
import Worker from 'worker-loader!./mdx-renderer.js';
106
import { MarkdownProblemListsProvider } from '../../context/MarkdownProblemListsContext';
117
import { components } from '../markdown/MDXComponents';
128

13-
class ErrorBoundary extends React.Component {
9+
class ErrorBoundary extends React.Component<{ children?: React.ReactNode }> {
1410
state: {
1511
error: null | any;
1612
};
@@ -61,16 +57,14 @@ export default function DynamicMarkdownRenderer({
6157
] = useState([]);
6258
const [error, setError] = useState(null);
6359
const workerRef = useRef(null);
64-
const currentlyCompilingRef =
65-
useRef<{
66-
markdown: string;
67-
problems: string;
68-
}>(null);
69-
const waitingToBeCompiledRef =
70-
useRef<{
71-
markdown: string;
72-
problems: string;
73-
}>(null);
60+
const currentlyCompilingRef = useRef<{
61+
markdown: string;
62+
problems: string;
63+
}>(null);
64+
const waitingToBeCompiledRef = useRef<{
65+
markdown: string;
66+
problems: string;
67+
}>(null);
7468

7569
const requestMarkdownCompilation = () => {
7670
if (workerRef.current === null) return;
@@ -83,25 +77,23 @@ export default function DynamicMarkdownRenderer({
8377
};
8478

8579
React.useEffect(() => {
86-
const worker = new Worker();
80+
const worker = new Worker(new URL('./mdx-renderer.js', import.meta.url));
8781
worker.onmessage = ({ data }) => {
8882
currentlyCompilingRef.current = null;
89-
ReactDOM.unstable_batchedUpdates(() => {
90-
if (data.compiledResult) {
91-
setMdxContent(
92-
new Function(data.compiledResult)({
93-
Fragment,
94-
jsx,
95-
jsxs,
96-
}).default({ components })
97-
);
98-
setMarkdownProblemListsProviderValue(data.problemsList);
99-
setError(null);
100-
} else {
101-
setError(data.error);
102-
setMdxContent(null);
103-
}
104-
});
83+
if (data.compiledResult) {
84+
setMdxContent(
85+
new Function(data.compiledResult)({
86+
Fragment,
87+
jsx,
88+
jsxs,
89+
}).default({ components })
90+
);
91+
setMarkdownProblemListsProviderValue(data.problemsList);
92+
setError(null);
93+
} else {
94+
setError(data.error);
95+
setMdxContent(null);
96+
}
10597
requestMarkdownCompilation();
10698
};
10799
workerRef.current = worker;

src/components/DynamicMarkdownRenderer/mdx-renderer.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { compile as xdmCompile } from 'xdm/lib/compile';
2-
import gfm from 'remark-gfm';
3-
import remarkMath from 'remark-math';
41
import remarkAutolinkHeadings from 'remark-autolink-headings';
5-
import remarkSlug from 'remark-slug';
62
import remarkExternalLinks from 'remark-external-links';
73
import remarkFrontmatter from 'remark-frontmatter';
4+
import gfm from 'remark-gfm';
5+
import remarkMath from 'remark-math';
86
import { remarkMdxFrontmatter } from 'remark-mdx-frontmatter';
9-
import remarkToC from '../../mdx-plugins/remark-toc';
7+
import remarkSlug from 'remark-slug';
8+
import { compile as xdmCompile } from 'xdm/lib/compile';
109
import customRehypeKatex from '../../mdx-plugins/rehype-math';
1110
import rehypeSnippets from '../../mdx-plugins/rehype-snippets';
11+
import remarkToC from '../../mdx-plugins/remark-toc';
1212

1313
// See: https://github.com/mdx-js/mdx/blob/main/packages/runtime/src/index.js
1414
const compile = async ({ markdown, problems }) => {

src/components/Settings/AdminSettings.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { getFunctions, httpsCallable } from 'firebase/functions';
22
import React from 'react';
33
import toast from 'react-hot-toast';
4-
import { unstable_batchedUpdates } from 'react-dom';
54
import {
65
UserPermissionInformation,
76
UserPermissions,
@@ -44,10 +43,8 @@ export default function AdminSettings() {
4443
toast.error('The user with email ' + email + ' could not be found.');
4544
} else {
4645
console.log('Got user: ', response.data.users[0]);
47-
unstable_batchedUpdates(() => {
48-
setUserData(response.data.users[0]);
49-
setUserPermissions(response.data.users[0].customClaims);
50-
});
46+
setUserData(response.data.users[0]);
47+
setUserPermissions(response.data.users[0].customClaims);
5148
}
5249
} catch (e) {
5350
toast.error(e.message);

src/components/layout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { useAnalyticsEffect } from '../hooks/useAnalyticsEffect';
33
import { useUpdateStreakEffect } from '../hooks/useUpdateStreakEffect';
44

5-
const Layout: React.FC = ({ children }) => {
5+
const Layout = ({ children }: { children?: React.ReactNode }): JSX.Element => {
66
useAnalyticsEffect();
77
useUpdateStreakEffect();
88
return <div className="font-sans">{children}</div>;

src/context/SignInContext.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ export const SignInContext = React.createContext<{
55
signIn: () => void;
66
}>(null);
77

8-
export const SignInProvider: React.FC = ({ children }) => {
8+
export const SignInProvider = ({
9+
children,
10+
}: {
11+
children?: React.ReactNode;
12+
}): JSX.Element => {
913
const [isOpen, setIsOpen] = React.useState<boolean>(false);
1014
const providerValue = React.useMemo(() => {
1115
return {

0 commit comments

Comments
 (0)