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 { ApolloClient, ApolloProvider, InMemoryCache } from "@apollo/client";
|
||||
import { ParamContext } from "/Context";
|
||||
|
||||
export function App({children}: PropsWithChildren<{}>) {
|
||||
export function App({ children }: PropsWithChildren<{}>) {
|
||||
const client = new ApolloClient({
|
||||
uri: "/graphql",
|
||||
cache: new InMemoryCache(),
|
||||
});
|
||||
const params = Object.fromEntries(
|
||||
location.hash
|
||||
.substring(1, location.hash.length)
|
||||
.split(",")
|
||||
.map(e => e.split("=")),
|
||||
);
|
||||
return (
|
||||
<ApolloProvider client={client}>
|
||||
{children}
|
||||
</ApolloProvider>
|
||||
)
|
||||
<ParamContext.Provider value={params}>
|
||||
<ApolloProvider client={client}>{children}</ApolloProvider>
|
||||
</ParamContext.Provider>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -9,8 +9,6 @@ import { rendermd } from "/lib/markdown-utils";
|
|||
import { NavBar } from "/components/NavBar";
|
||||
import { Tabs, Tab } from "/components/Tabs";
|
||||
|
||||
import classnames from "classnames";
|
||||
|
||||
const DEFAULT_TASK_CONTENT = [
|
||||
"## 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 { App } from "/components/App";
|
||||
import { Task } from "/components/Task";
|
||||
|
||||
(function () {
|
||||
const params = Object.fromEntries(
|
||||
location.hash
|
||||
.substring(1, location.hash.length)
|
||||
.split(",")
|
||||
.map(e => e.split("=")),
|
||||
);
|
||||
const root = document.querySelector(".react-root")!;
|
||||
const params = useContext(ParamContext);
|
||||
ReactDOM.createRoot(root).render(
|
||||
<App>
|
||||
<Task taskId={Number(params.id)} />
|
||||
|
|
Loading…
Reference in a new issue