Handle project list loading issue
This commit is contained in:
parent
542748f12c
commit
5af745958e
@ -5,14 +5,14 @@ import { useProfile } from "./useProfile";
|
|||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { setProjectId } from "../slices/localVariablesSlice";
|
import { setProjectId } from "../slices/localVariablesSlice";
|
||||||
|
|
||||||
export const useProjects = () =>
|
export const useProjects = () => {
|
||||||
{
|
const { profile } = useProfile();
|
||||||
const {profile} = useProfile()
|
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const [projects, setProjects] = useState([]);
|
const [projects, setProjects] = useState([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
|
const projects_cache = getCachedData("projectslist");
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
const projectIds = profile?.projects || [];
|
const projectIds = profile?.projects || [];
|
||||||
|
|
||||||
@ -22,7 +22,6 @@ export const useProjects = () =>
|
|||||||
.sort((a, b) => a.name.localeCompare(b.name));
|
.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if (!projects_cache) {
|
if (!projects_cache) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
@ -40,20 +39,15 @@ export const useProjects = () =>
|
|||||||
if (!projects.length) {
|
if (!projects.length) {
|
||||||
const filtered = filterProjects(projects_cache);
|
const filtered = filterProjects(projects_cache);
|
||||||
setProjects(filtered);
|
setProjects(filtered);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect( () =>
|
useEffect(() => {
|
||||||
{
|
if (profile) {
|
||||||
if ( profile )
|
|
||||||
{
|
|
||||||
fetchData();
|
fetchData();
|
||||||
}
|
}
|
||||||
}, []);
|
}, [profile]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return { projects, loading, error, refetch: fetchData };
|
return { projects, loading, error, refetch: fetchData };
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user