Skip to content

Commit

Permalink
Merge pull request #6 from kamyabnazari/kn-enhancing-dashboard
Browse files Browse the repository at this point in the history
Kn enhancing dashboard
  • Loading branch information
kamyabnazari authored May 27, 2023
2 parents 07ffe65 + 108ea68 commit 8cda284
Show file tree
Hide file tree
Showing 26 changed files with 663 additions and 86 deletions.
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
ports:
- "5003:5003"
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:8081/api/health || exit 1
test: wget --no-verbose --tries=1 --spider http://localhost:5003/api/health || exit 1
interval: 5s
timeout: 5s
retries: 5
Expand All @@ -38,6 +38,8 @@ services:
build:
context: ./frontend
dockerfile: Dockerfile.frontend
env_file:
- ./frontend/.env
depends_on:
- pocketbase
- backend
Expand Down
33 changes: 33 additions & 0 deletions frontend/src/lib/components/ActionCards.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script lang="ts">
import IconFile from '~icons/solar/file-text-outline';
import IconCreate from '~icons/solar/clipboard-add-outline';
</script>

<div class="card bg-base-100 w-96 flex-1 shadow-md">
<div class="card-body">
<h2 class="card-title">Read a new file</h2>
<p>Upload a new file and ask it your questions!</p>
<div class="card-actions justify-end py-4">
<a href="/dashboard/file-read">
<button class="btn btn-primary gap-4">
<IconFile style="font-size: x-large" />
Read
</button></a
>
</div>
</div>
</div>
<div class="card bg-base-100 w-96 flex-1 shadow-md">
<div class="card-body">
<h2 class="card-title">Create a new file</h2>
<p>Tell us what you want and create your file!</p>
<div class="card-actions justify-end py-4">
<a href="/dashboard/file-create">
<button class="btn btn-primary gap-4">
<IconCreate style="font-size: x-large" />
Create
</button>
</a>
</div>
</div>
</div>
59 changes: 59 additions & 0 deletions frontend/src/lib/components/FileTable.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<script lang="ts">
import IconPDF from '~icons/bxs/file-pdf';
</script>

<div class="w-full overflow-x-auto">
<table class="table w-full">
<!-- head -->
<thead>
<tr>
<th>
<label>
<input type="checkbox" class="checkbox" />
</label>
</th>
<th>Name</th>
<th>Type</th>
<th>Create Date</th>
<th />
</tr>
</thead>
<tbody>
<tr>
<th>
<label>
<input type="checkbox" class="checkbox" />
</label>
</th>
<td>
<div class="flex items-center space-x-3">
<div class="mask mask-square flex h-10 w-10 items-center justify-center">
<IconPDF style="font-size: x-large" />
</div>
<div>
<div class="font-bold">file-23.pdf</div>
</div>
</div>
</td>
<td>
<span class="text-sm">Uploaded</span><br />
<span class="badge badge-ghost badge-sm">PDF</span>
</td>
<td>13.05.2023</td>
<th>
<button class="btn btn-sm btn-ghost">Actions</button>
</th>
</tr>
</tbody>
<!-- foot -->
<tfoot>
<tr>
<th />
<th>Name</th>
<th>Type</th>
<th>Create Date</th>
<th />
</tr>
</tfoot>
</table>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
}
</script>

<div class="navbar text-base-content bg-base-100 sticky left-0 top-0 p-4 shadow-sm">
<div class="flex-none">
<label for="application-drawer" class="btn btn-square btn-ghost drawer-button lg:hidden">
<IconMenu style="font-size: 1.5em" />
<div class="navbar text-base-content bg-base-100 sticky left-0 top-0 px-6 py-4 shadow-sm">
<div class="me-4 flex-none lg:hidden">
<label for="application-drawer" class="btn btn-square btn-ghost drawer-button">
<IconMenu style="font-size: x-large" />
</label>
</div>
<div class="flex-1">
<a class="btn-ghost btn text-xl normal-case" href="/">ADM</a>
<a class="btn-link text-left text-xl font-bold normal-case" href="/">ADM</a>
</div>
<div class="flex-none">
{#await $currentUser then user}
Expand All @@ -60,7 +60,7 @@
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<ul
tabindex="0"
class="menu menu-compact dropdown-content bg-base-100 rounded-box mt-3 w-52 p-2 shadow"
class="menu dropdown-content bg-base-100 rounded-box mt-2 w-52 p-2 shadow-lg"
>
<li><a href="/profile">Profile</a></li>
<li><a href="/settings">Settings</a></li>
Expand All @@ -75,7 +75,7 @@
};
}}
>
<button>Log out</button>
<button class="w-full text-left">Log out</button>
</form>
</li>
</ul>
Expand All @@ -90,7 +90,7 @@
</div>
<label class="swap swap-rotate px-4">
<input type="checkbox" bind:checked={isChecked} on:change={handleCheckboxChange} />
<IconSun class="swap-off fill-current" style="font-size: 1.5em" />
<IconMoon class="swap-on fill-current" style="font-size: 1.5em" />
<IconSun class="swap-off fill-current" style="font-size: x-large" />
<IconMoon class="swap-on fill-current" style="font-size: x-large" />
</label>
</div>
44 changes: 44 additions & 0 deletions frontend/src/lib/components/Stats.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<script lang="ts">
import IconFile from '~icons/solar/file-text-outline';
import IconNewFile from '~icons/solar/pen-new-square-outline';
import IconArrowUp from '~icons/solar/arrow-right-up-outline';
import IconArrowDown from '~icons/solar/arrow-left-down-outline';
import IconWord from '~icons/solar/chat-square-outline';
import IconPage from '~icons/solar/documents-outline';
</script>

<div class="stats flex-auto flex-nowrap shadow-md">
<div class="stat">
<div class="stat-figure text-secondary"><IconFile style="font-size: x-large;" /></div>
<div class="stat-title">Uploaded files</div>
<div class="stat-value">118</div>
<div class="stat-desc">Jan 1st - Dec 1st</div>
</div>
<div class="stat">
<div class="stat-figure text-secondary"><IconNewFile style="font-size: x-large;" /></div>
<div class="stat-title">Created files</div>
<div class="stat-value">24</div>
<div class="stat-desc flex flex-row gap-2">
<IconArrowUp style="font-size: small;" />
<span>12 (22%)</span>
</div>
</div>
<div class="stat">
<div class="stat-figure text-secondary"><IconPage style="font-size: x-large;" /></div>
<div class="stat-title">Total pages</div>
<div class="stat-value">459</div>
<div class="stat-desc flex flex-row gap-2">
<IconArrowDown style="font-size: small;" />
<span>52 (5%)</span>
</div>
</div>
<div class="stat">
<div class="stat-figure text-secondary"><IconWord style="font-size: x-large;" /></div>
<div class="stat-title">Total words</div>
<div class="stat-value">24K</div>
<div class="stat-desc flex flex-row gap-2">
<IconArrowUp style="font-size: small;" />
<span>2K (10%)</span>
</div>
</div>
</div>
5 changes: 4 additions & 1 deletion frontend/src/lib/components/footer.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<footer class="footer footer-center text-base-content bg-base-100 bottom-0 p-10">
<footer
class="footer footer-center text-base-content bg-base-100 border-base-200 bottom-0 border-y-2
p-10"
>
<div class="grid grid-flow-col gap-4">
<a href="/documentation" class="link link-hover">Documentation</a>
<a href="/about-us" class="link link-hover">About us</a>
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/routes/(auth)/email-change/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { redirect } from '@sveltejs/kit';
import type { Actions } from './$types';

export const actions: Actions = {
default: async ({ locals, request }) => {
const data = Object.fromEntries(await request.formData()) as {
email: string;
newEmail: string;
password: string;
};

try {
await locals.pb.collection('users').authWithPassword(data.email, data.password);
await locals.pb.collection('users').requestEmailChange(data.email);
} catch (e) {
console.error(e);
throw e;
}

throw redirect(303, '/login');
}
};
63 changes: 63 additions & 0 deletions frontend/src/routes/(auth)/email-change/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<script lang="ts">
import { applyAction, enhance } from '$app/forms';
import { pb } from '$lib/pocketbase';
</script>

<div class="hero bg-base-100 min-h-full">
<div class="hero-content flex-col lg:flex-row-reverse">
<div class="text-center lg:text-left">
<h1 class="text-5xl font-bold">Email Change</h1>
<p class="py-6">
Enter your new email below. <br />
We'll send a confirmation to verify it's correct and accessible. Follow the instructions in the
confirmation to complete the change.
</p>
</div>
<div class="card bg-base-100 w-full max-w-sm flex-shrink-0 shadow-2xl">
<div class="card-body">
<form
method="POST"
use:enhance={() => {
return async ({ result }) => {
pb.authStore.loadFromCookie(document.cookie);
await applyAction(result);
};
}}
>
<div class="form-control gap-2">
<label for="email" class="label">
<span class="label-text">Email</span>
</label>
<input
type="email"
name="email"
placeholder="your@email.com"
class="input input-bordered"
/>
<label for="newEmail" class="label">
<span class="label-text">New Email</span>
</label>
<input
type="newEmail"
name="newEmail"
placeholder="yournew@email.com"
class="input input-bordered"
/>
<label for="password" class="label">
<span class="label-text">Password</span>
</label>
<input
type="password"
name="password"
placeholder="password"
class="input input-bordered"
/>
<div class="form-control mt-6">
<button class="btn btn-primary">Send email</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
11 changes: 0 additions & 11 deletions frontend/src/routes/(auth)/login/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,6 @@ import type { Actions, PageServerLoad } from './$types';

export const actions: Actions = {
default: async ({ locals, request }) => {
/*
const { formData, errors } = await validateData(await request.formData(), loginUserSchema);
if (errors) {
return invalid(400, {
data: formData,
errors: errors.fieldErrors
});
}
*/

const data = Object.fromEntries(await request.formData()) as {
email: string;
password: string;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/(auth)/login/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { pb } from '$lib/pocketbase';
</script>

<div class="hero bg-base-200 min-h-screen">
<div class="hero bg-base-100 min-h-full">
<div class="hero-content flex-col lg:flex-row-reverse">
<div class="text-center lg:text-left">
<h1 class="text-5xl font-bold">Login</h1>
Expand Down
8 changes: 1 addition & 7 deletions frontend/src/routes/(auth)/password-reset/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { redirect } from '@sveltejs/kit';
import type { Actions, PageServerLoad } from './$types';
import type { Actions } from './$types';

export const actions: Actions = {
default: async ({ locals, request }) => {
Expand All @@ -17,9 +17,3 @@ export const actions: Actions = {
throw redirect(303, '/login');
}
};

export const load: PageServerLoad = async ({ locals }) => {
if (locals.user) {
throw redirect(303, '/dashboard');
}
};
2 changes: 1 addition & 1 deletion frontend/src/routes/(auth)/password-reset/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { pb } from '$lib/pocketbase';
</script>

<div class="hero bg-base-200 min-h-screen">
<div class="hero bg-base-100 min-h-full">
<div class="hero-content flex-col lg:flex-row-reverse">
<div class="text-center lg:text-left">
<h1 class="text-5xl font-bold">Password Reset</h1>
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/routes/(auth)/profile/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import type { Actions } from './$types';

export const actions: Actions = {
default: async ({ locals, request }) => {
const data = Object.fromEntries(await request.formData()) as {
name: string;
email: string;
};

try {
await locals.pb.collection('users').update(locals.user.id, data);
} catch (err) {
console.error(err);
throw err;
}

throw redirect(303, '/dashboard');
}
};

export const load: PageServerLoad = async ({ locals }) => {
if (!locals.user) {
Expand Down
Loading

0 comments on commit 8cda284

Please sign in to comment.