frontend: add ParamContext
This commit is contained in:
parent
40f86c69a5
commit
dde21f2f22
4 changed files with 17 additions and 14 deletions
2
twenty-frontend/src/js/Context.ts
Normal file
2
twenty-frontend/src/js/Context.ts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
import { createContext } from "react";
|
||||||
|
export const ParamContext = createContext<Record<string, string>>({});
|
|
@ -1,14 +1,21 @@
|
||||||
import React, { PropsWithChildren } from "react";
|
import React, { PropsWithChildren } from "react";
|
||||||
import { ApolloClient, ApolloProvider, InMemoryCache } from "@apollo/client";
|
import { ApolloClient, ApolloProvider, InMemoryCache } from "@apollo/client";
|
||||||
|
import { ParamContext } from "/Context";
|
||||||
|
|
||||||
export function App({children}: PropsWithChildren<{}>) {
|
export function App({ children }: PropsWithChildren<{}>) {
|
||||||
const client = new ApolloClient({
|
const client = new ApolloClient({
|
||||||
uri: "/graphql",
|
uri: "/graphql",
|
||||||
cache: new InMemoryCache(),
|
cache: new InMemoryCache(),
|
||||||
});
|
});
|
||||||
|
const params = Object.fromEntries(
|
||||||
|
location.hash
|
||||||
|
.substring(1, location.hash.length)
|
||||||
|
.split(",")
|
||||||
|
.map(e => e.split("=")),
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<ApolloProvider client={client}>
|
<ParamContext.Provider value={params}>
|
||||||
{children}
|
<ApolloProvider client={client}>{children}</ApolloProvider>
|
||||||
</ApolloProvider>
|
</ParamContext.Provider>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,6 @@ import { rendermd } from "/lib/markdown-utils";
|
||||||
import { NavBar } from "/components/NavBar";
|
import { NavBar } from "/components/NavBar";
|
||||||
import { Tabs, Tab } from "/components/Tabs";
|
import { Tabs, Tab } from "/components/Tabs";
|
||||||
|
|
||||||
import classnames from "classnames";
|
|
||||||
|
|
||||||
const DEFAULT_TASK_CONTENT = [
|
const DEFAULT_TASK_CONTENT = [
|
||||||
"## Subtasks",
|
"## Subtasks",
|
||||||
"",
|
"",
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
import React from "react";
|
import React, { useContext } from "react";
|
||||||
|
import { ParamContext } from "/Context";
|
||||||
import ReactDOM from "react-dom/client";
|
import ReactDOM from "react-dom/client";
|
||||||
import { App } from "/components/App";
|
import { App } from "/components/App";
|
||||||
import { Task } from "/components/Task";
|
import { Task } from "/components/Task";
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
const params = Object.fromEntries(
|
|
||||||
location.hash
|
|
||||||
.substring(1, location.hash.length)
|
|
||||||
.split(",")
|
|
||||||
.map(e => e.split("=")),
|
|
||||||
);
|
|
||||||
const root = document.querySelector(".react-root")!;
|
const root = document.querySelector(".react-root")!;
|
||||||
|
const params = useContext(ParamContext);
|
||||||
ReactDOM.createRoot(root).render(
|
ReactDOM.createRoot(root).render(
|
||||||
<App>
|
<App>
|
||||||
<Task taskId={Number(params.id)} />
|
<Task taskId={Number(params.id)} />
|
||||||
|
|
Loading…
Reference in a new issue