diff --git a/package-lock.json b/package-lock.json
index 6e01222..9aa1958 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -14,6 +14,7 @@
"lucide-svelte": "^0.373.0",
"mode-watcher": "^0.3.0",
"svelte-radix": "^1.1.0",
+ "svelte-sonner": "^0.3.22",
"sveltekit-superforms": "^2.12.6",
"tailwind-merge": "^2.3.0",
"tailwind-variants": "^0.2.1",
@@ -3043,6 +3044,14 @@
"svelte": "^3.54.0 || ^4.0.0 || ^5.0.0"
}
},
+ "node_modules/svelte-sonner": {
+ "version": "0.3.22",
+ "resolved": "https://registry.npmjs.org/svelte-sonner/-/svelte-sonner-0.3.22.tgz",
+ "integrity": "sha512-1AEBl7rTP4oeMAmBmkcvoHNOwB8gPzz73RYApcY8pyDwbjBewU8ATnXV8N42omV1sQvtSX/X0o5A1nfkN3T6cg==",
+ "peerDependencies": {
+ "svelte": ">=3 <5"
+ }
+ },
"node_modules/sveltekit-superforms": {
"version": "2.12.6",
"resolved": "https://registry.npmjs.org/sveltekit-superforms/-/sveltekit-superforms-2.12.6.tgz",
diff --git a/package.json b/package.json
index a8c0102..d01d9ff 100644
--- a/package.json
+++ b/package.json
@@ -35,6 +35,7 @@
"lucide-svelte": "^0.373.0",
"mode-watcher": "^0.3.0",
"svelte-radix": "^1.1.0",
+ "svelte-sonner": "^0.3.22",
"sveltekit-superforms": "^2.12.6",
"tailwind-merge": "^2.3.0",
"tailwind-variants": "^0.2.1",
diff --git a/src/hooks.server.js b/src/hooks.server.js
index 56e31c2..75cb510 100644
--- a/src/hooks.server.js
+++ b/src/hooks.server.js
@@ -2,7 +2,6 @@ import { config } from '$lib/index.js';
/** @type {import('@sveltejs/kit').HandleFetch} */
export async function handleFetch({ event, request, fetch }) {
- console.log(event.request.headers.get("cookie"))
if (request.url.startsWith(config.api_url)) {
// @ts-ignore
request.headers.set('cookie', event.request.headers.get('cookie'));
diff --git a/src/lib/components/ui/sonner/index.js b/src/lib/components/ui/sonner/index.js
new file mode 100644
index 0000000..1ad9f4a
--- /dev/null
+++ b/src/lib/components/ui/sonner/index.js
@@ -0,0 +1 @@
+export { default as Toaster } from "./sonner.svelte";
diff --git a/src/lib/components/ui/sonner/sonner.svelte b/src/lib/components/ui/sonner/sonner.svelte
new file mode 100644
index 0000000..10f3549
--- /dev/null
+++ b/src/lib/components/ui/sonner/sonner.svelte
@@ -0,0 +1,18 @@
+
+
+
diff --git a/src/lib/config.js b/src/lib/config.js
index 4335536..ba0a39d 100644
--- a/src/lib/config.js
+++ b/src/lib/config.js
@@ -1,3 +1,3 @@
export const config = {
- api_url: "http://api.omersabic.com:3001"
+ api_url: "http://localhost:3000"
}
\ No newline at end of file
diff --git a/src/routes/(app)/+layout.server.js b/src/routes/(app)/+layout.server.js
new file mode 100644
index 0000000..9a4f80e
--- /dev/null
+++ b/src/routes/(app)/+layout.server.js
@@ -0,0 +1,20 @@
+import { config } from "$lib"
+import { redirect } from "@sveltejs/kit";
+
+/** @type {import("./$types").LayoutServerLoad} */
+export const load = async ({fetch, cookies}) => {
+ if(!cookies.get("token")) return redirect(302, "/auth")
+ const res = await fetch(config.api_url+"/me")
+ if(res.status > 399 && res.status < 499) {
+ cookies.delete("token", {
+ path: "/"
+ });
+
+ redirect(302, "/auth");
+ }
+ const data = await res.json();
+
+ return {
+ me: data
+ }
+}
\ No newline at end of file
diff --git a/src/routes/+layout.svelte b/src/routes/(app)/+layout.svelte
similarity index 98%
rename from src/routes/+layout.svelte
rename to src/routes/(app)/+layout.svelte
index 5444a54..f383714 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/(app)/+layout.svelte
@@ -1,5 +1,5 @@
+
diff --git a/src/routes/+page.svelte b/src/routes/(app)/+page.svelte
similarity index 100%
rename from src/routes/+page.svelte
rename to src/routes/(app)/+page.svelte
diff --git a/src/routes/(app)/articles/+page.server.js b/src/routes/(app)/articles/+page.server.js
new file mode 100644
index 0000000..c923de6
--- /dev/null
+++ b/src/routes/(app)/articles/+page.server.js
@@ -0,0 +1,50 @@
+import { config } from "$lib"
+import { superValidate } from "sveltekit-superforms";
+import { formSchema } from "./schema";
+import { zod } from "sveltekit-superforms/adapters";
+import { fail } from "@sveltejs/kit";
+
+/** @type {import("./$types").PageServerLoad} */
+export const load = async ({ fetch }) => {
+ const blogRes = await fetch(config.api_url + "/blog?mine=true", {
+ credentials: 'include'
+ });
+
+ const videosRes = await fetch(config.api_url + "/videos", {
+ credentials: 'include'
+ });
+
+ const dataBlog = await blogRes.json();
+ const dataVideos = await videosRes.json();
+ return {
+ articles: dataBlog.articles,
+ videos: dataVideos.videos,
+ form: await superValidate(zod(formSchema)),
+ }
+}
+
+/** @type {import("@sveltejs/kit").Actions} */
+export const actions = {
+ default: async (event) => {
+ console.log("creating article...")
+ const form = await superValidate(event, zod(formSchema));
+ console.log(form.data)
+ console.log(form.valid)
+ if (!form.valid) {
+ return fail(400, {
+ form,
+ });
+ }
+ const res = await event.fetch(config.api_url + "/blog/create", {
+ method: "POST",
+ body: JSON.stringify(form.data)
+ });
+
+ console.log(res.status)
+ console.log(await res.json())
+
+ return {
+ form,
+ };
+ },
+};
\ No newline at end of file
diff --git a/src/routes/articles/+page.svelte b/src/routes/(app)/articles/+page.svelte
similarity index 72%
rename from src/routes/articles/+page.svelte
rename to src/routes/(app)/articles/+page.svelte
index ac43282..23987dd 100644
--- a/src/routes/articles/+page.svelte
+++ b/src/routes/(app)/articles/+page.svelte
@@ -10,11 +10,14 @@
import TooltipButton from '$lib/components/molecules/tooltipbutton.svelte';
import ProBadge from '$lib/components/molecules/probadge.svelte';
- import { formSchema } from "./schema";
+ import { formSchema } from './schema';
import { superForm } from 'sveltekit-superforms';
import { zodClient } from 'sveltekit-superforms/adapters';
+ import { toast } from 'svelte-sonner';
+
/** @type {import("./$types").PageData} */
export let data;
+ let isDialogOpen = false;
const form = superForm(data.form, {
validators: zodClient(formSchema)
@@ -22,7 +25,12 @@
const { form: formData, enhance } = form;
- const invoices = [
+ function submitArticle() {
+ isDialogOpen = false;
+ toast('Article is queued for generation.');
+ }
+
+ const articles = [
{
id: 'AG64NE',
title: 'Nullam ornare ornare orci a auctor.',
@@ -59,12 +67,13 @@
source: 'Youtube'
}
];
+
-
-
+
+
Create Article
-
+
Create Article
@@ -72,19 +81,41 @@
-
+
-
Youtube video URL*
- Youtube video*
+
+
+
+
+
+
+
+ {#each data.videos as video}
+ {video.snippet.title}
+ {/each}
+
+
+
+
-
+
@@ -134,7 +165,7 @@
-
+ Create
@@ -143,24 +174,20 @@
ID
- Title
- Preview
- Source
- Actions
+ Title
+ Source
+ Actions
- {#each invoices as invoice, i (i)}
+ {#each articles as invoice, i (i)}
{invoice.id}
- {invoice.title}
- {invoice.preview}
- {invoice.source}
-
+ {invoice.source}
+
diff --git a/src/routes/(app)/articles/schema.js b/src/routes/(app)/articles/schema.js
new file mode 100644
index 0000000..0feaa50
--- /dev/null
+++ b/src/routes/(app)/articles/schema.js
@@ -0,0 +1,9 @@
+import { z } from "zod";
+
+export const formSchema = z.object({
+ video_id: z.string(),
+ // length: z.number().optional(),
+ // format: z.enum(["summary", "listicle", "product review", "news report", "tutorial"]).optional(),
+});
+
+/** @typedef {typeof formSchema} FormSchema */
\ No newline at end of file
diff --git a/src/routes/(auth)/auth/+page.server.js b/src/routes/(auth)/auth/+page.server.js
new file mode 100644
index 0000000..c3ffa1e
--- /dev/null
+++ b/src/routes/(auth)/auth/+page.server.js
@@ -0,0 +1,21 @@
+import { config } from "$lib"
+import { redirect } from "@sveltejs/kit";
+
+/** @type {import("./$types").PageServerLoad} */
+export const load = async ({request, cookies}) => {
+ let url = new URL(request.url);
+
+ if(url.searchParams.has("token")) {
+ // @ts-ignore
+ cookies.set("token", url.searchParams.get("token"), {
+ path: "/",
+ });
+
+ redirect(302, "/");
+ }
+
+ return {
+ success: false,
+ message: "missing token"
+ }
+}
\ No newline at end of file
diff --git a/src/routes/auth/+page.svelte b/src/routes/(auth)/auth/+page.svelte
similarity index 100%
rename from src/routes/auth/+page.svelte
rename to src/routes/(auth)/auth/+page.svelte
diff --git a/src/routes/+layout.server.js b/src/routes/+layout.server.js
deleted file mode 100644
index 55d373b..0000000
--- a/src/routes/+layout.server.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import { config } from "$lib"
-
-/** @type {import("./$types").LayoutServerLoad} */
-export const load = async ({fetch}) => {
- const res = await fetch(config.api_url+"/me")
-
- const data = await res.json();
-
- return {
- me: data
- }
-}
\ No newline at end of file
diff --git a/src/routes/articles/+page.server.js b/src/routes/articles/+page.server.js
deleted file mode 100644
index e1cd31b..0000000
--- a/src/routes/articles/+page.server.js
+++ /dev/null
@@ -1,18 +0,0 @@
-import { config } from "$lib"
-import { superValidate } from "sveltekit-superforms";
-import { formSchema } from "./schema";
-import { zod } from "sveltekit-superforms/adapters";
-
-/** @type {import("./$types").PageServerLoad} */
-export const load = async ({fetch}) => {
- const res = await fetch(config.api_url+"/blog?mine=true", {
- credentials: 'include'
- });
-
- const data = await res.json();
- console.log(data);
- return {
- articles: data,
- form: await superValidate(zod(formSchema)),
- }
-}
\ No newline at end of file
diff --git a/src/routes/articles/schema.js b/src/routes/articles/schema.js
deleted file mode 100644
index 465bfa7..0000000
--- a/src/routes/articles/schema.js
+++ /dev/null
@@ -1,9 +0,0 @@
-import { z } from "zod";
-
-export const formSchema = z.object({
- youtube_url: z.string().url(),
- length: z.enum(["short", "medium", "long"]).optional(),
- format: z.enum(["summary", "listicle", "product review", "news report", "tutorial"]).optional(),
-});
-
-/** @typedef {typeof formSchema} FormSchema */
\ No newline at end of file