feat: add name limit

This commit is contained in:
max_richter 2023-11-13 17:04:19 +01:00
parent 2ce9a56d70
commit 9ccad393d0
3 changed files with 69 additions and 3 deletions

View File

@ -10,10 +10,12 @@
let data = persisted<{ let data = persisted<{
name: string; name: string;
showNameLengthError: boolean;
nameAccepted?: boolean; nameAccepted?: boolean;
provideAdelsTitel?: boolean; provideAdelsTitel?: boolean;
adelsTitel?: string; adelsTitel?: string;
showAdelsTitelLengthError: boolean;
adelsTitelAccepted?: boolean; adelsTitelAccepted?: boolean;
adelsTitelSuggestions?: string[]; adelsTitelSuggestions?: string[];
@ -32,8 +34,10 @@
createPersonality?: boolean; createPersonality?: boolean;
}>('data', { }>('data', {
name: '', name: '',
showNameLengthError: false,
nameAccepted: false, nameAccepted: false,
adelsTitel: undefined, adelsTitel: undefined,
showAdelsTitelLengthError: false,
adelsTitelSuggestions: [], adelsTitelSuggestions: [],
provideAdelsTitel: undefined, provideAdelsTitel: undefined,
portraitPublic: true, portraitPublic: true,
@ -42,6 +46,14 @@
createPersonality: undefined createPersonality: undefined
}); });
$: if ($data.name.length > 99) {
$data.showNameLengthError = true;
}
$: if ($data?.adelsTitel?.length > 99) {
$data.showAdelsTitelLengthError = true;
}
let loadingAdelsTitel = false; let loadingAdelsTitel = false;
async function fetchAdelsTitel() { async function fetchAdelsTitel() {
if (loadingAdelsTitel) return; if (loadingAdelsTitel) return;
@ -94,11 +106,20 @@
<section in:slide={{ delay: 500 }}> <section in:slide={{ delay: 500 }}>
<TextSplit content="Wie lauten Euer Vor- und Nachname, edler Gast?" /> <TextSplit content="Wie lauten Euer Vor- und Nachname, edler Gast?" />
<input placeholder="Name" type="text" bind:value={$data.name} /> <input placeholder="Name" type="text" bind:value={$data.name} />
{#if $data.name.length > 99}
<p class="error">
Wir bitten um Entschuldigung, aber dieser Name ist zu lang. (maximal 100 Zeichen)
</p>
{:else if $data.showNameLengthError}
<p class="hint">{$data.name.length}/100 Zeichen</p>
{/if}
{#if !$data.nameAccepted} {#if !$data.nameAccepted}
<button <button
disabled={$data.name.length > 99}
on:click={() => { on:click={() => {
$data.nameAccepted = true; $data.nameAccepted = true;
}}>Name akzeptieren</button }}>Name speichern</button
> >
{/if} {/if}
</section> </section>
@ -158,6 +179,14 @@
> >
ja</button ja</button
> >
<button
on:click={() => {
$data.adelsTitel = '';
$data.provideAdelsTitel = true;
}}
>
ich habe bereits einen
</button>
<button <button
on:click={() => { on:click={() => {
$data.adelsTitel = ''; $data.adelsTitel = '';
@ -177,12 +206,26 @@
{:else if typeof $data.adelsTitel === 'string'} {:else if typeof $data.adelsTitel === 'string'}
<TextSplit content="Euer Adelstitel" /> <TextSplit content="Euer Adelstitel" />
<input placeholder="Name" type="text" bind:value={$data.adelsTitel} /> <input placeholder="Name" type="text" bind:value={$data.adelsTitel} />
{#if $data.adelsTitel.length > 99}
<p class="error">
Wir bitten um Entschuldigung, aber dieser Titel ist zu lang. (maximal 100 Zeichen)
</p>
{:else if $data.showAdelsTitelLengthError}
<p class="hint">{$data.name.length}/100 Zeichen</p>
{/if}
{#if !$data.adelsTitelAccepted} {#if !$data.adelsTitelAccepted}
<button <button
disabled={$data.adelsTitel.length > 99}
on:click={() => { on:click={() => {
$data.adelsTitelAccepted = true; $data.adelsTitelAccepted = true;
}}>akzeptieren</button }}>akzeptieren</button
> >
<button
on:click={() => {
$data.adelsTitel = undefined;
fetchAdelsTitel();
}}>neue vorschläge</button
>
{/if} {/if}
{:else if $data.adelsTitelSuggestions?.length} {:else if $data.adelsTitelSuggestions?.length}
<p>Adelstitel Vorschläge</p> <p>Adelstitel Vorschläge</p>
@ -308,6 +351,23 @@
margin-bottom: 200px; margin-bottom: 200px;
} }
p.error {
background: red;
color: white;
padding: 9px;
border-radius: 5px;
font-size: 0.5em;
font-weight: 200;
font-family: sans-serif;
}
p.hint {
font-size: 0.6em;
font-family: sans-serif;
font-weight: 200;
opacity: 0.6;
}
.portrait-frame.loaded { .portrait-frame.loaded {
margin-top: 100px; margin-top: 100px;
border: none; border: none;
@ -323,6 +383,12 @@
cursor: pointer; cursor: pointer;
} }
button:disabled {
opacity: 0.4;
pointer-events: none;
user-select: none;
}
.wrapper { .wrapper {
display: flex; display: flex;
flex-direction: column; flex-direction: column;

View File

@ -18,7 +18,7 @@ function processChatGptResult(resultString: string) {
export async function chat(prompt: string, { isList, temperature }: { isList?: boolean, temperature?: number } = {}) { export async function chat(prompt: string, { isList, temperature }: { isList?: boolean, temperature?: number } = {}) {
const chatCompletion = await openai.chat.completions.create({ const chatCompletion = await openai.chat.completions.create({
model: "gpt-4", model: "gpt-3.5-turbo",
temperature: temperature ?? 0.9, temperature: temperature ?? 0.9,
messages: [ messages: [
{ {

View File

@ -45,7 +45,7 @@ export const POST: RequestHandler = async ({ params, request }) => {
if (!inputName) { if (!inputName) {
throw new Error("Missing name"); throw new Error("Missing name");
} }
if (inputName.length > 50) { if (inputName.length > 100) {
throw new Error("Name too long"); throw new Error("Name too long");
} }