mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-26 14:28:04 +00:00
Rename frontend directory (#472)
* Rename directory * Cleanup * Recover lost images * remove lint
This commit is contained in:
10
frontend/src/hooks/useAlertError.ts
Normal file
10
frontend/src/hooks/useAlertError.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { useContext } from "react";
|
||||
import { ErrorModalContext } from "../context/ErrorModalContext";
|
||||
|
||||
function useAlertError() {
|
||||
const { setShowErrorModal, shouldShowErrorModal } =
|
||||
useContext(ErrorModalContext);
|
||||
return { setShowErrorModal, shouldShowErrorModal };
|
||||
}
|
||||
|
||||
export default useAlertError;
|
||||
34
frontend/src/hooks/useCustomSearchParams.ts
Normal file
34
frontend/src/hooks/useCustomSearchParams.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { useCallback } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
|
||||
const useCustomSearchParams = () => {
|
||||
const [search, setSearch] = useSearchParams();
|
||||
const searchAsObject: { [key: string]: string } = Object.fromEntries(
|
||||
new URLSearchParams(search)
|
||||
);
|
||||
|
||||
const upsertSearchParams = useCallback(
|
||||
(k: string, value: string) => {
|
||||
const copySearchParams = new URLSearchParams(search);
|
||||
copySearchParams.set(k, value);
|
||||
setSearch(copySearchParams);
|
||||
return copySearchParams;
|
||||
},
|
||||
[search, setSearch]
|
||||
);
|
||||
|
||||
const removeSearchParam = (k: string) => {
|
||||
const copySearchParams = new URLSearchParams(search);
|
||||
copySearchParams.delete(k);
|
||||
setSearch(copySearchParams);
|
||||
};
|
||||
|
||||
return {
|
||||
searchParamsObject: searchAsObject,
|
||||
setSearchParams: setSearch,
|
||||
upsertSearchParams,
|
||||
removeSearchParam,
|
||||
};
|
||||
};
|
||||
|
||||
export default useCustomSearchParams;
|
||||
19
frontend/src/hooks/useDebounce.tsx
Normal file
19
frontend/src/hooks/useDebounce.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
function useDebounce<T>(value: T, delay : number) {
|
||||
const [debouncedValue, setDebouncedValue] = useState(value);
|
||||
|
||||
useEffect(() => {
|
||||
const handler = setTimeout(() => {
|
||||
setDebouncedValue(value);
|
||||
}, delay);
|
||||
|
||||
return () => {
|
||||
clearTimeout(handler);
|
||||
};
|
||||
}, [value, delay]);
|
||||
|
||||
return debouncedValue;
|
||||
}
|
||||
|
||||
export default useDebounce;
|
||||
13
frontend/src/hooks/useNavigateWithSearchParams.ts
Normal file
13
frontend/src/hooks/useNavigateWithSearchParams.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
|
||||
const useNavigateWithSearchParams = () => {
|
||||
const navigate = useNavigate();
|
||||
const { search } = useLocation();
|
||||
const navigateWithSearchParams = (url: string, ...restArgs: any[]) => {
|
||||
navigate(url + search, ...restArgs);
|
||||
};
|
||||
|
||||
return navigateWithSearchParams;
|
||||
};
|
||||
|
||||
export default useNavigateWithSearchParams;
|
||||
Reference in New Issue
Block a user