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:
parent
a055c92dea
commit
d4b22deda0
7 changed files with 114 additions and 4 deletions
|
|
@ -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} />
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue