diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ebc1bb20..f473d683 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,6 +27,8 @@ jobs: name: Build problem list and static files needs: test runs-on: ubuntu-latest + env: + REACT_APP_PROBLEM_SET: ${{secrets.REACT_APP_PROBLEM_SET}} steps: - uses: actions/checkout@v4 - run: git submodule sync diff --git a/src/problems b/src/problems deleted file mode 120000 index 87ad854b..00000000 --- a/src/problems +++ /dev/null @@ -1 +0,0 @@ -public-problems \ No newline at end of file diff --git a/src/problems.ts b/src/problems.ts new file mode 100644 index 00000000..2ce70a8c --- /dev/null +++ b/src/problems.ts @@ -0,0 +1,24 @@ + +/** + * Here you define the different types of questions + */ +const questionTypeList = [ + 'private-problems', + 'public-problems' +] + +/** + * Depending on the REACT_APP_PROBLEM_SET, it returns am ESM module based off that ones + * @returns ESM Module Import for the different problems + */ +function chooseQuestionType() { + const questionType = process.env.REACT_APP_PROBLEM_SET; + + if(questionTypeList.includes(questionType!)) { + return import(`./${questionType}/problems.js`) + } else{ + throw Error('The env REACT_APP_PROBLEM_SET is incorrect or not set') + } +} + +export default chooseQuestionType; \ No newline at end of file diff --git a/src/utils/getCategoryList.ts b/src/utils/getCategoryList.ts index d973a6b7..4c8c415b 100644 --- a/src/utils/getCategoryList.ts +++ b/src/utils/getCategoryList.ts @@ -1,4 +1,6 @@ -import problems from "../problems/problems"; +import chooseQuestionType from "../problems"; + +const {problems} = await chooseQuestionType() // TODO: since mutation and haystack aren't considered categories, // the array this function returns doesn't contain them. if the issue @@ -6,7 +8,7 @@ import problems from "../problems/problems"; export function getCategoryList() { const categories = new Set(); - problems.forEach((p) => { + problems.forEach((p: any) => { categories.add(p.meta.category); }); diff --git a/src/utils/getCompletedProblems.ts b/src/utils/getCompletedProblems.ts index 6cfea907..99b0bb56 100644 --- a/src/utils/getCompletedProblems.ts +++ b/src/utils/getCompletedProblems.ts @@ -1,6 +1,8 @@ -import problems from "../problems/problems"; +import chooseQuestionType from "../problems"; import { Progress, Submission } from "../types"; +const {problems} = await chooseQuestionType() + interface CompletedByCategory { problems: { title: string; diff --git a/tsconfig.json b/tsconfig.json index a273b0cf..bdbb01a3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es5", + "target": "es2022", "lib": [ "dom", "dom.iterable",