mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Site view
This commit is contained in:
40
hooks/useSite.ts
Normal file
40
hooks/useSite.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import axios from "axios";
|
||||
|
||||
interface Site {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string;
|
||||
networks: string[];
|
||||
}
|
||||
|
||||
const useSite = () => {
|
||||
const [site, setSite] = useState<Site>({
|
||||
id: 0,
|
||||
name: "",
|
||||
description: "",
|
||||
networks: []
|
||||
});
|
||||
const [siteId, setSiteId] = useState("");
|
||||
|
||||
const loadSite = useCallback(() => {
|
||||
if (!siteId) return;
|
||||
axios.get('/api/sites/get', {
|
||||
params: { siteId }
|
||||
}).then((response) => {
|
||||
setSite(response.data.site);
|
||||
});
|
||||
}, [siteId]);
|
||||
|
||||
useEffect(() => {
|
||||
loadSite();
|
||||
}, [loadSite]);
|
||||
|
||||
return {
|
||||
site,
|
||||
loadSite,
|
||||
setSiteId,
|
||||
};
|
||||
};
|
||||
|
||||
export default useSite;
|
||||
Reference in New Issue
Block a user