Skip to content

Commit

Permalink
Add add number
Browse files Browse the repository at this point in the history
  • Loading branch information
aleda145 committed Aug 2, 2022
1 parent bd031d7 commit 9655f83
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions frontend/src/Dashboard/Dashboard.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
import React, { useEffect } from "react";
import { useQuery } from "@tanstack/react-query";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { useNavigate, NavLink } from "react-router-dom";

export default function Dashboard({ client, setIsLoggedIn }) {
const navigate = useNavigate();
const queryClient = useQueryClient();

const addMutation = useMutation(
(url) => {
// return axios.post(getApiDomain() + "/scrape", url);
// return "ok";
return client.Records.create("user_nums", {
user: "KoDn7hCUaY8BIGG",
num: 42,
});
},
{
onSuccess: () => {
queryClient.invalidateQueries("favNumbers");
console.log("succes");
},
onError: (error) => {
console.log(error);
error.customError = error.response.data.message;
},
}
);
async function logOutClicked() {
await client.AuthStore.clear();
setIsLoggedIn(false);
navigate("/");
}
const { isLoading, error, data } = useQuery(["repoData"], () =>
const { isLoading, error, data } = useQuery(["favNumbers"], () =>
client.Records.getList("user_nums", 1, 50, {
filter: "created >= '2022-01-01 00:00:00'",
})
Expand All @@ -23,10 +44,27 @@ export default function Dashboard({ client, setIsLoggedIn }) {
for (const item of data.items) {
favorite_numbers.push(item.num + " ");
}

return (
<div>
<div>My {client.AuthStore.model.email} favorite numbers</div>
<div>{favorite_numbers}</div>

<button
onClick={() => {
addMutation.mutate(
{ url: "ok" },
{
onSuccess: () => {
console.log("button scucces");
},
}
);
}}
>
Lägg till nummer
</button>

<button onClick={logOutClicked}>Log out</button>
</div>
);
Expand Down

0 comments on commit 9655f83

Please sign in to comment.