This commit is contained in:
MuslemRahimi 2024-11-10 17:23:12 +01:00
parent 28f68c1d1d
commit 53b75876b8
5 changed files with 44 additions and 10 deletions

View File

@ -68,7 +68,7 @@
<a
href="/pricing"
class="mt-10 flex justify-center text-[1rem] items-center px-5 w-fit m-auto rounded-md btn text-white bg-[#fff] sm:hover:bg-gray-300 transition duration-150 ease-in-out group"
class="mt-10 flex justify-center text-[1rem] items-center px-5 w-fit m-auto rounded-md btn text-black bg-[#fff] sm:hover:bg-gray-300 transition duration-150 ease-in-out group"
>
Become a Pro
<span
@ -83,7 +83,7 @@
><path
d="M24 0v24H0V0h24ZM12.593 23.258l-.011.002l-.071.035l-.02.004l-.014-.004l-.071-.035c-.01-.004-.019-.001-.024.005l-.004.01l-.017.428l.005.02l.01.013l.104.074l.015.004l.012-.004l.104-.074l.012-.016l.004-.017l-.017-.427c-.002-.01-.009-.017-.017-.018Zm.265-.113l-.013.002l-.185.093l-.01.01l-.003.011l.018.43l.005.012l.008.007l.201.093c.012.004.023 0 .029-.008l.004-.014l-.034-.614c-.003-.012-.01-.02-.02-.022Zm-.715.002a.023.023 0 0 0-.027.006l-.006.014l-.034.614c0 .012.007.02.017.024l.015-.002l.201-.093l.01-.008l.004-.011l.017-.43l-.003-.012l-.01-.01l-.184-.092Z"
/><path
fill="white"
fill="black"
d="M13.06 3.283a1.5 1.5 0 0 0-2.12 0L5.281 8.939a1.5 1.5 0 0 0 2.122 2.122L10.5 7.965V19.5a1.5 1.5 0 0 0 3 0V7.965l3.096 3.096a1.5 1.5 0 1 0 2.122-2.122L13.06 3.283Z"
/></g
></g

View File

@ -0,0 +1,17 @@
import type { RequestHandler } from "./$types";
export const POST: RequestHandler = async ({ request, locals }) => {
const { pb } = locals;
const data = await request.json();
let output;
try {
output = await pb.collection("watchlist").create(data)
}
catch(e) {
//console.log(e)
output = {};
}
console.log(output)
return new Response(JSON.stringify(output));
};

View File

@ -0,0 +1,20 @@
import type { RequestHandler } from "./$types";
export const POST: RequestHandler = async ({ request, locals }) => {
const { pb } = locals;
const data = await request.json();
const watchListId = data?.watchListId
let output;
try {
await pb.collection("watchlist").delete(watchListId)
output = 'success';
}
catch(e) {
//console.log(e)
output = 'failure';
}
return new Response(JSON.stringify(output));
};

View File

@ -163,7 +163,7 @@
</svelte:head>
<section
class="w-full max-w-3xl sm:max-w-screen-2xl overflow-hidden pb-20 pt-5 px-4 lg:px-3"
class="w-full max-w-3xl sm:max-w-screen-2xl overflow-hidden min-h-screen pb-20 pt-5 px-4 lg:px-3"
>
<div class="text-sm sm:text-[1rem] breadcrumbs">
<ul>

View File

@ -213,24 +213,21 @@
for (const [key, value] of formData?.entries()) {
postData[key] = value;
}
postData["path"] = "create-watchlist";
try {
const response = await fetch("/api/fastify-post-data", {
const response = await fetch("/api/create-watchlist", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(postData),
}); // make a POST request to the server with the FormData object
if (response.ok) {
if (response?.ok) {
toast.success("Watchlist created successfully!", {
style: "border-radius: 200px; background: #333; color: #fff;",
});
const clicked = document.getElementById("addWatchlist");
clicked?.dispatchEvent(new MouseEvent("click"));
const anchor = document.createElement("a");
anchor.href = "/watchlist/stocks";
anchor.dispatchEvent(new MouseEvent("click"));
@ -262,7 +259,7 @@
};
try {
const response = await fetch("/api/fastify-post-data", {
const response = await fetch("/api/delete-watchlist", {
method: "POST",
headers: {
"Content-Type": "application/json",
@ -270,7 +267,7 @@
body: JSON.stringify(postData),
});
const output = (await response.json())?.items;
const output = await response.json();
if (output === "success") {
toast.success("Watchlist deleted successfully!", {