Finished Metadata Input Mask mechanics

This commit is contained in:
Neshura 2023-11-01 21:55:39 +01:00
parent 5740d173c5
commit d6c5e52527
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
8 changed files with 176 additions and 131 deletions

View file

@ -22,9 +22,6 @@
Settings go here
</p>
{/if}
<div class="row">
<Greet />
</div>
</div>

View file

@ -0,0 +1,48 @@
<script lang="ts">
let open = false;
export let list: Array<string>;
export let activeElement: string;
export let id: string;
function handleDropdownOpen() {
open = !open;
}
function handleSelect(newSelection: string) {
console.log("newSelection")
activeElement = newSelection;
open = false;
}
</script>
<div {id} class="dropdown-container">
<button on:click|preventDefault={handleDropdownOpen}>{activeElement}</button>
{#if open}
<div class="dropdown-list">
{#each list as listElem}
<div class="dropdown-element" on:click|preventDefault={() => {handleSelect(listElem)}}>{listElem}</div>
{/each}
</div>
{/if}
</div>
<style>
.dropdown-container {
position: relative;
}
.dropdown-list {
position: absolute;
max-height: 10rem;
overflow-y: auto;
z-index: 100;
background-color: var(--color-bg);
border: 1px solid var(--color-border)
}
</style>

View file

@ -13,10 +13,6 @@
function inputInteger(event: Event & {currentTarget: (EventTarget & HTMLInputElement)}) {
let newValue = event.currentTarget.value;
if (newValue.startsWith("0") && newValue.length > 1) {
newValue = newValue.slice(1, newValue.length)
}
if (newValue != "" && !isNaN(Number(newValue))) {
value = Number(newValue);
}
@ -25,17 +21,13 @@
event.currentTarget.value = value.toString();
}
}
else if (newValue === "") {
event.currentTarget.value = defaultValue.toString();
value = defaultValue;
}
else {
event.currentTarget.value = value.toString();
}
}
</script>
<input {id} type="text" class="digitInput" style="--valuelen: {value.toString().length + 3}ch" on:input|preventDefault={inputInteger} {value}>
<input {id} type="number" class="digitInput" style="--valuelen: {value.toString().length + 4}ch" on:input|preventDefault={inputInteger} {value}>
<style>
.digitInput {

View file

@ -16,7 +16,7 @@
</script>
<input id="tag-{id}" type="text" class="letterInput" style="--valuelen: {width}ch" bind:value={value}>
<button on:click={handleClick}>X</button>
<button on:click|preventDefault={handleClick}>X</button>
<style>
.letterInput {

View file

@ -7,7 +7,7 @@
}
</script>
<button {id} class="letterInput" on:click={handleClick}>+</button>
<button {id} class="letterInput" on:click|preventDefault={handleClick}>+</button>
<style>
.letterInput {

View file

@ -5,164 +5,162 @@
import ListTextInputElement from "./ListTextInput/ListTextInputElement.svelte";
import {invoke} from "@tauri-apps/api/tauri";
import {AgeRating, LanguageISO, type Metadata} from "./metadata";
import Dropdown from "./Dropdown/Dropdown.svelte";
let returnMessage = "";
let seriesTitle = "";
let volumeTitle = "";
let volumeNumber = 0;
let chapterNumber = 0;
let pageCount = 1;
let chapterCount = 0;
let summary = "";
let releaseYear: number;
let releaseMonth: number;
let releaseDay: number;
let author: string;
let typesetter: string;
let editor: string;
let translator: string;
let publisher: string;
let tags: Array<string> = [];
let genre = "Hentai";
let lang = LanguageISO.EN;
let ageRating = AgeRating.R18;
let metadata: Metadata = {
series_title: "",
title: "",
chapter_number: 0,
total_chapter_count: -1,
volume_number: -1,
summary: "",
release_date: {
year: new Date().getFullYear(),
month: -1,
day: -1,
},
writer: "",
translator: "",
letterer: "",
editor: "",
publisher: "",
genre: "",
tags: [],
page_count: 1,
language: LanguageISO.EN,
characters: [],
age_rating: AgeRating.Unknown
};
$: {
if (releaseYear < 0) {
releaseMonth = -1;
if (metadata.release_date.year < 0) {
metadata.release_date.month = -1;
}
if (releaseMonth < 0) {
releaseDay = -1;
if (metadata.release_date.month < 0) {
metadata.release_date.day = -1;
}
}
function deleteTag(event: any) {
console.log("deleted")
tags.splice(event.detail.tagId, 1);
tags = tags;
metadata.tags.splice(event.detail.tagId, 1);
metadata.tags = metadata.tags;
}
async function saveMetadata() {
let message: Metadata = {
title: volumeTitle,
series_title: seriesTitle,
chapter_number: 0,
total_chapter_count: -1,
volume_number: -1,
summary: "",
year: 2023,
month: -1,
day: -1,
writer: "",
translator: "",
letterer: "",
editor: "",
publisher: "",
genre: "",
tags: [],
page_count: 10,
language: LanguageISO.EN,
characters: [],
age_rating: AgeRating.R18,
}
console.log(message);
returnMessage = await invoke("test", { message })
console.log(metadata);
returnMessage = await invoke("test", { message: metadata })
}
</script>
<form class="metadataInput" on:submit|preventDefault={saveMetadata}>
<div class="metadataInputContainer">
<h1>Metadata</h1>
<label for="series">Series:</label>
<TextInput id="series" bind:value={seriesTitle} placeholder="Series Title" /><br>
<form class="metadataInput" on:submit|preventDefault={saveMetadata}>
<label for="title">Title:</label>
<TextInput id="title" bind:value={volumeTitle} placeholder="Volume Title" /><br>
<label for="volume">Volume:</label>
<IntegerInput id="volume" bind:value={volumeNumber} />
<label for="chapter">Chapter:</label>
<IntegerInput id="chapter" bind:value={chapterNumber} /> /
<label for="series">Series:</label>
<TextInput id="series" bind:value={metadata.series_title} placeholder="Series Title" /><br>
<IntegerInput id="chapter_count" bind:value={chapterCount} negative={true}/><br>
<label for="title">Title:</label>
<TextInput id="title" bind:value={metadata.title} placeholder="Volume Title" /><br>
<label for="page_count">Page Count</label>
<IntegerInput id="page_count" bind:value={pageCount} defaultValue={1} /><br>
<label for="volume">Volume:</label>
<IntegerInput id="volume" bind:value={metadata.volume_number} defaultValue={-1}/>
<label for="chapter">Chapter:</label>
<IntegerInput id="chapter" bind:value={metadata.chapter_number} /> /
<label for="summary">Summary:</label><br>
<label for="summary"></label><input id="series" type="text"><br>
<IntegerInput id="chapter_count" bind:value={metadata.total_chapter_count} negative={true}/><br>
<label for="release_date">Release Date:</label>
<IntegerInput id="release_year" bind:value={releaseYear} defaultValue={new Date().getFullYear()} />
{#if releaseYear > 0}
<IntegerInput id="release_month" bind:value={releaseMonth} defaultValue={new Date().getMonth()} />
{#if releaseMonth > 0}
<IntegerInput id="release_day" bind:value={releaseDay} defaultValue={new Date().getDay()} />
<label for="page_count">Page Count</label>
<IntegerInput id="page_count" bind:value={metadata.page_count} /><br>
<label for="summary">Summary:</label><br>
<label for="summary"></label><textarea rows="3" cols="60" id="series" name="text" placeholder="Summary..." bind:value={metadata.summary}></textarea><br>
<label for="release_date">Release Date:</label>
<IntegerInput id="release_year" bind:value={metadata.release_date.year} />
{#if metadata.release_date.year > 0}
<IntegerInput id="release_month" bind:value={metadata.release_date.month} />
{#if metadata.release_date.month > 0}
<IntegerInput id="release_day" bind:value={metadata.release_date.day} />
{/if}
{/if}
{/if}
<br>
<!--TODO: if date element is 0 do not display finer element, also set finer element to -1-->
<br>
<!--TODO: if date element is 0 do not display finer element, also set finer element to -1-->
<label for="author">Author:</label>
<TextInput id="author" bind:value={author} placeholder="Author" /><br>
<label for="author">Author:</label>
<TextInput id="author" bind:value={metadata.writer} placeholder="Author" /><br>
<label for="translator">Translator:</label>
<TextInput id="translator" bind:value={translator} placeholder="Translator" /><br>
<label for="translator">Translator:</label>
<TextInput id="translator" bind:value={metadata.translator} placeholder="Translator" /><br>
<label for="typesetter">Typesetter:</label>
<TextInput id="typesetter" bind:value={typesetter} placeholder="Typesetter" /><br>
<label for="typesetter">Letterer:</label>
<TextInput id="typesetter" bind:value={metadata.letterer} placeholder="Letterer" /><br>
<label for="editor">Editor:</label>
<TextInput id="editor" bind:value={editor} placeholder="Editor" /><br>
<label for="editor">Editor:</label>
<TextInput id="editor" bind:value={metadata.editor} placeholder="Editor" /><br>
<label for="publisher">Publisher:</label>
<TextInput id="publisher" bind:value={publisher} placeholder="Publisher" /><br>
<label for="publisher">Publisher:</label>
<TextInput id="publisher" bind:value={metadata.publisher} placeholder="Publisher" /><br>
<label for="new-tag">Tags:</label>
<!-- List of Tags, New Button -->
{#each tags as tag, id}
<ListTextInputElement {id} bind:value={tag} on:deleted={deleteTag}/>
{/each}
<NewListTextInput id="new-tag" bind:value={tags[tags.length]}/><br>
<label for="new-tag">Tags:</label>
<!-- List of Tags, New Button -->
{#each metadata.tags as tag, id}
<ListTextInputElement {id} bind:value={tag} on:deleted={deleteTag}/>
{/each}
<NewListTextInput id="new-tag" bind:value={metadata.tags[metadata.tags.length]}/><br>
<label for="genre">Genre:</label>
<TextInput id="genre" bind:value={genre} placeholder="Genre" />
<label for="lang">Language:</label>
<input id="lang" type="text"><br>
<div class="row-left">
<label for="genre">Genre:</label>
<TextInput id="genre" bind:value={metadata.genre} placeholder="Genre" />
<label for="age_rating">Age Rating:</label>
<input id="age_rating" type="text"><br>
<label for="language-select">Language:</label>
<Dropdown id="language-select" bind:activeElement={metadata.language} list={Object.values(LanguageISO)}></Dropdown>
</div>
<div class="row-left">
<label for="age-rating">Age Rating:</label>
<Dropdown id="" bind:activeElement={metadata.age_rating} list={Object.values(AgeRating)}></Dropdown>
</div>
<input type="submit" value="Save"/>
<p>{returnMessage}</p>
</form>
</div>
<input type="submit" value="Save"/>
<p>{returnMessage}</p>
</form>
<style>
.metadataInput {
.metadataInputContainer {
height: 100%;
max-height: 100%;
overflow: auto;
}
.metadataInput label, input[type="submit"] {
.metadataInput {
margin-left: 4rem;
}
.metadataInput label, input[type="submit"] {
}
.metadataInput h1 {
position: sticky;
top: 0;

View file

@ -8,9 +8,7 @@ type Metadata = {
summary: string,
year: number,
month: number,
day: number,
release_date: ReleaseDate,
writer: string,
translator: string,
@ -32,6 +30,12 @@ type Metadata = {
age_rating: AgeRating
}
type ReleaseDate = {
year: number,
month: number,
day: number,
}
enum AgeRating {
Unknown = "Unknown",
AdultsOnly = "Adults Only 18+",
@ -55,4 +59,4 @@ enum LanguageISO {
}
export { LanguageISO, AgeRating}
export type {Metadata}
export type {Metadata, ReleaseDate}

View file

@ -5,6 +5,7 @@
font-weight: 400;
--color-bg: #f6f6f6;
--color-border: #000000;
color: #0f0f0f;
background-color: #f6f6f6;
@ -58,6 +59,11 @@ body, html {
justify-content: center;
}
.row-left {
display: flex;
gap: 0.5rem;
}
a {
font-weight: 500;
color: #646cff;