save user queries in redis so that user can refresh the page and still come back to their latest task

This commit is contained in:
Viktor Barzin 2025-07-06 12:02:25 +00:00
parent a055c92dea
commit d4b22deda0
No known key found for this signature in database
GPG key ID: 4056458DBDBF8863
7 changed files with 114 additions and 4 deletions

View file

@ -60,6 +60,26 @@ const fetchData = async (user: User, baseQueyrUri: string, parameters: Parameter
};
const fetchActiveTasksForUser = async (user: User) => {
const accessToken = user?.access_token;
const response = await fetch(`/api/tasks_for_user`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${accessToken}`, // Pass the token
'Content-Type': 'application/json',
},
});
if (!response.ok) {
throw new Error(`Failed to fetch active tasks for user: ${response.status}`);
}
const data =
await response.json();
return data;
};
function App() {
const [listingData, setListingData] = useState({});
const [taskID, setTaskID] = useState<string | null>(null);
@ -83,6 +103,17 @@ function App() {
getUser().then(setUser);
}, []);
useEffect(() => {
if (!user) {
return;
}
fetchActiveTasksForUser(user).then((tasks) => {
if (tasks) {
setTaskID(tasks[0])
}
})
}, [user, taskID])
if (!user) {
return <LoginModal isOpen={user === null} />
}