From ccb5d42faa085aeb8867f399265f137221e96258 Mon Sep 17 00:00:00 2001 From: Ota Prokopec Date: Tue, 25 Apr 2023 20:23:07 +0200 Subject: [PATCH] much faster experience loading --- src/lib/components/Inputs/Input.svelte | 81 ++++++++++++++++--- src/lib/utils/database/experience.ts | 26 +++--- src/routes/authorization/login/log_in.svelte | 16 +++- .../authorization/register/register.svelte | 12 +-- 4 files changed, 100 insertions(+), 35 deletions(-) diff --git a/src/lib/components/Inputs/Input.svelte b/src/lib/components/Inputs/Input.svelte index 0113fde..950c6a1 100644 --- a/src/lib/components/Inputs/Input.svelte +++ b/src/lib/components/Inputs/Input.svelte @@ -7,17 +7,16 @@ export let value = '' export let placeholder = '' export let id = elementIdGenerator() - export let podm = true export let readOnly = false export let maxLength = Infinity - export let icon: string | null = null + export let icon: string | null | boolean | undefined = null export let iconFunction: 'password' = null export let changedIconOnActive = icon export let iconPosition: 'right' | 'left' = 'left' //erant-new export let autocomplete = '' - export let pattern: any = null + export let pattern: RegExp = null export let prefix: string = '' export let invisiblePrefix = icon ? true : false @@ -46,16 +45,17 @@ let className: string = '' export { className as class } - $: inputValue = pattern ? value.replace(pattern, '') : value //this is here because we always want to equal input.value = value + $: inputValue = /*pattern ? value.replace(pattern, '') :*/ value //this is here because we always want to equal input.value = value $: prefixControl(inputValue) //when inputValue changes => it will check prefix (so when we do $: inputValue = value this func will trigger every moment when inputValue will change and it will overwhite currect input.value thats will be {value}) + $: patternControl(inputValue) //when inputValue changes => it will check prefix (so when we do $: inputValue = value this func will trigger every moment when inputValue will change and it will overwhite currect input.value thats will be {value}) const prefixControl = (_e) => { if (prefix) { if (!invisiblePrefix) { - if (inputValue?.indexOf(prefix) < 0) inputValue = `${prefix}${inputValue}` + if (inputValue?.indexOf(prefix) !== 0) inputValue = `${prefix}${inputValue}` value = inputValue - } else if (inputValue?.indexOf(prefix) < 0) { + } else if (inputValue?.indexOf(prefix) !== 0) { value = `${prefix}${inputValue}` //inputValue = value.slice(prefix.length, value.length) } else value = inputValue @@ -64,8 +64,18 @@ } } + const patternControl = (_e) => { + inputValue = inputValue.replace(pattern, '') + } + + $: console.log(pattern?.test(inputValue)) + + let inputElement: HTMLElement = null + onMount(() => { prefixControl('') + patternControl('') + inputElement = document.getElementById(id) }) let iconActived = false @@ -75,10 +85,55 @@ iconPushedCount++ iconActived = iconPushedCount % 2 === 1 dispatch('iconClick') - if (iconFunction === 'password') type = type === 'text' ? 'password' : 'text' + if (iconFunction === 'password') { + type = type === 'text' ? 'password' : 'text' + retype(inputElement) + } + } + const retype = (e: HTMLElement) => { + e.setAttribute('type', type) } +
+ {#if icon} + + {/if} + + +
+ +