Skip to content

Commit

Permalink
fetch test
Browse files Browse the repository at this point in the history
  • Loading branch information
nedredmond committed Jan 14, 2024
1 parent f221f55 commit 2ab90e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
41 changes: 7 additions & 34 deletions src/router.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect } from "react";
import type { RouteObject } from "react-router-dom";
import { RouterProvider, createHashRouter } from "react-router-dom";
import type { WcagResponseData } from "./types";
Expand All @@ -7,39 +7,7 @@ import { WcagContext } from "./contexts/wcag-context";
import loader from "./loaders/wcag-loader";
import { parse } from "./utils";
import { Text } from "./components/text";

// const wcagRoutes = (wcag: WcagResponseData): RouteObject[] => [
// {
// path: "wcag2",
// loader: () => loader(),
// },
// ...wcag.principles
// .map((principle): RouteObject[] =>
// pathAliases.map((pKey) => ({
// path: `wcag2/${parse(principle[pKey])}`,
// loader: () => loader(principle),
// children: principle.guidelines
// .map((guideline): RouteObject[] =>
// pathAliases.map((gKey) => ({
// path: `wcag2/${parse(principle[pKey])}/${parse(guideline[gKey])}`,
// loader: () => loader(guideline),
// children: guideline.successcriteria
// .map((successcriterion): RouteObject[] =>
// pathAliases.map((scKey) => ({
// path: `wcag2/${parse(principle[pKey])}/${parse(
// guideline[gKey],
// )}/${parse(successcriterion[scKey])}`,
// loader: () => loader(successcriterion),
// })),
// )
// .flat(),
// })),
// )
// .flat(),
// })),
// )
// .flat(),
// ];
import getWcag from "./w3c/wcag/get-wcag";

const wcagRoutes = (wcag: WcagResponseData): RouteObject[] => [
{
Expand Down Expand Up @@ -97,6 +65,11 @@ const router = (data: WcagResponseData) =>

const Router = () => {
const data = React.useContext(WcagContext);
useEffect(() => {
getWcag().then((data) => {
console.log(data);
})
}, []);
return <RouterProvider router={router(data)} />;
};

Expand Down
11 changes: 11 additions & 0 deletions src/w3c/wcag/get-wcag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { WcagResponseData } from "../../types";

export default async (): Promise<WcagResponseData> =>
await fetch(
"https://raw.githubusercontent.com/w3c/wcag/main/guidelines/wcag.json",
).then(async (res) => {
if (res.ok) {
return res.json();
}
throw new Error("Failed to fetch WCAG data");
});

0 comments on commit 2ab90e1

Please sign in to comment.