-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
layout change and new component rewrite
- Loading branch information
Showing
6 changed files
with
191 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<script lang="ts"> | ||
import { selectedRecord } from "$lib/stores/recordStore.js"; | ||
import { pb } from "$lib/pocketbase.js"; | ||
import { getDate, isExpired } from "$lib/utils.js"; | ||
import TypeSelector from "$lib/components/TypeSelector.svelte"; | ||
let record: any; | ||
let loading = false; | ||
selectedRecord.subscribe(value => { | ||
loading = true; | ||
if (value) { | ||
getRecord(value).then((res) => { | ||
record = res; | ||
loading = false; | ||
console.log(record); | ||
}); | ||
} | ||
}); | ||
async function getRecord(id: string) { | ||
return await pb.collection("content").getOne(id, ({ | ||
sort: "-created", | ||
expand: "category" | ||
})); | ||
} | ||
let editName = false; | ||
$: if (editName) { | ||
console.log("editing"); | ||
} | ||
</script> | ||
|
||
<div class="flex flex-1"> | ||
{#if loading} | ||
<div class="flex items-center justify-center w-full h-full"> | ||
<span class="loading loading-ring loading-lg"></span> | ||
</div> | ||
{:else} | ||
<div> | ||
<div class="flex gap-2"> | ||
<h1 id="nameBox" class="text-2xl text-primary font-bold" contenteditable={editName}> | ||
{record.name} | ||
</h1> | ||
<button class="btn btn-sm btn-outline" | ||
on:click={() => editName = !editName}>{editName ? "Done" : "Edit"}</button> | ||
</div> | ||
<div class="flex flex-col gap-2 w-fit"> | ||
<p class="text-secondary/50">{record.id}</p> | ||
<p class="text-sm text-base-100 capitalize py-1 px-2 rounded-md bg-secondary">{record.type}</p> | ||
<TypeSelector type={record.type}/> | ||
<p class="text-sm text-base-100 capitalize py-1 px-2 rounded-md {record.expand.category.cat_color}">{record.expand.category.cat_name}</p> | ||
{#if isExpired(record.expiry)} | ||
<p class="text-sm text-base-100 capitalize py-1 px-2 rounded-md bg-error">Expired</p> | ||
{:else} | ||
<p class="text-sm text-base-100 capitalize py-1 px-2 rounded-md bg-accent">Expires: {getDate(record.expiry)}</p> | ||
{/if} | ||
</div> | ||
</div> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<script lang="ts"> | ||
import { selectedRecord } from "$lib/stores/recordStore"; | ||
export let id: string; | ||
export let name: string; | ||
export let type: string; | ||
export let categoryName: string; | ||
export let categoryColour: string; | ||
export let expiry: string; | ||
function isExpired(expiry: string): boolean { | ||
const dateObj = new Date(expiry); | ||
const today = new Date(); | ||
return dateObj < today; | ||
} | ||
function getDate(datetime: string): string { | ||
const dateObj = new Date(datetime); | ||
const year = dateObj.getUTCFullYear(); | ||
const month = (dateObj.getUTCMonth() + 1).toString().padStart(2, "0"); | ||
const day = dateObj.getUTCDate().toString().padStart(2, "0"); | ||
return `${day}/${month}/${year}`; | ||
} | ||
function handleView() { | ||
console.log("Viewing:", id); | ||
selectedRecord.set(id); | ||
} | ||
</script> | ||
|
||
<div class="flex text-nowrap w-full gap-4 items-center rounded-xl bg-base-100 py-2 px-4"> | ||
<div class="flex flex-col gap-2 w-full"> | ||
<h1 class="text-lg font-bold text-primary">{name}</h1> | ||
<div class="flex w-full items-center gap-2 font-bold"> | ||
<p class="text-sm text-base-100 capitalize py-1 px-2 rounded-md bg-secondary">{type}</p> | ||
<p class="text-sm text-base-100 capitalize py-1 px-2 rounded-md {categoryColour}">{categoryName}</p> | ||
{#if isExpired(expiry)} | ||
<p class="text-sm text-base-100 capitalize py-1 px-2 rounded-md bg-error">Expired</p> | ||
{:else} | ||
<p class="text-sm text-base-100 capitalize py-1 px-2 rounded-md bg-accent">Expires: {getDate(expiry)}</p> | ||
{/if} | ||
</div> | ||
</div> | ||
<div class="flex gap-4 items-center"> | ||
<button class="btn btn-primary btn-md" on:click={handleView}>View</button> | ||
<button class="btn btn-primary btn-md">Copy Url</button> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script> | ||
import { selectedRecord } from "$lib/stores/recordStore"; | ||
import { pb } from "$lib/pocketbase.js"; | ||
export let type = 'password' || 'markdown' | ||
// update the selected record with the new type | ||
async function updateType() { | ||
return await pb.collection('content').update($selectedRecord, { type: type }) | ||
} | ||
</script> | ||
|
||
<select bind:value={type} on:change={updateType}> | ||
<option value="password">Password</option> | ||
<option value="markdown">Markdown</option> | ||
</select> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { type Writable, writable } from "svelte/store"; | ||
|
||
export const selectedRecord: Writable<string> = writable(''); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters