Integrated the DomainContext.jsx into the LinkContext.jsx
This commit is contained in:
@ -1,25 +1,27 @@
|
||||
import React, {createContext, useEffect, useState} from "react";
|
||||
import React, {createContext, useContext, useEffect, useState} from "react";
|
||||
import {jsonRequest} from "@/common/utils/RequestUtil";
|
||||
import {DomainContext} from "@/common/contexts/Domain/DomainContext.jsx";
|
||||
|
||||
export const LinkContext = createContext({});
|
||||
|
||||
export const LinkProvider = (props) => {
|
||||
|
||||
const [domain, setDomain] = useState(localStorage.getItem("domain") || "localhost"); // TODO
|
||||
const [currentDomain] = useContext(DomainContext);
|
||||
const [links, setLinks] = useState([]);
|
||||
const [query, setQuery] = useState(""); // TODO
|
||||
|
||||
const updateLinks = () => jsonRequest(`/link/${domain}/list`)
|
||||
const updateLinks = () => jsonRequest(`/link/${currentDomain}/list`)
|
||||
.then(json => setLinks(json));
|
||||
|
||||
useEffect(() => {
|
||||
updateLinks();
|
||||
|
||||
const interval = setInterval(() => updateLinks(), 15000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
}, [currentDomain]);
|
||||
|
||||
return (
|
||||
<LinkContext.Provider value={[links, updateLinks, setQuery, setDomain]}>
|
||||
<LinkContext.Provider value={[links, updateLinks, setQuery]}>
|
||||
{props.children}
|
||||
</LinkContext.Provider>
|
||||
)
|
||||
|
Reference in New Issue
Block a user