mirror of
https://github.com/netbirdio/netbird.git
synced 2026-08-31 12:01:29 +02:00
refresh restrictions also on status changes
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
import { Events } from "@wailsio/runtime";
|
||||
import { Settings as SettingsSvc } from "@bindings/services";
|
||||
import { Restrictions } from "@bindings/services/models.js";
|
||||
import { useStatus } from "@/contexts/StatusContext.tsx";
|
||||
|
||||
const EVENT_SYSTEM = "netbird:event";
|
||||
const EMPTY = new Restrictions();
|
||||
@@ -21,6 +22,7 @@ export const useRestrictions = () => useContext(RestrictionsContext);
|
||||
export const RestrictionsProvider = ({ children }: { children: ReactNode }) => {
|
||||
const [restrictions, setRestrictions] = useState<Restrictions>(EMPTY);
|
||||
const mounted = useRef(true);
|
||||
const { status } = useStatus();
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
try {
|
||||
@@ -33,7 +35,6 @@ export const RestrictionsProvider = ({ children }: { children: ReactNode }) => {
|
||||
|
||||
useEffect(() => {
|
||||
mounted.current = true;
|
||||
refresh();
|
||||
|
||||
const off = Events.On(
|
||||
EVENT_SYSTEM,
|
||||
@@ -54,6 +55,10 @@ export const RestrictionsProvider = ({ children }: { children: ReactNode }) => {
|
||||
};
|
||||
}, [refresh]);
|
||||
|
||||
useEffect(() => {
|
||||
if (status?.status) refresh();
|
||||
}, [status?.status, refresh]);
|
||||
|
||||
return (
|
||||
<RestrictionsContext.Provider value={restrictions}>{children}</RestrictionsContext.Provider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user