Skip to content

Commit

Permalink
fix: start logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Valexr committed Apr 14, 2024
1 parent bf11182 commit f77341a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
22 changes: 13 additions & 9 deletions src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" context="module">
import { date, time, start, quote } from "$lib/data";
import { date, time, start, quote, county } from "$lib/data";
import { images } from "$lib/images";
import DateInput from "$lib/components/DateInput.svelte";
Expand All @@ -10,6 +10,13 @@
<script lang="ts">
export let name: Name;
export let repository: Repository;
let input: HTMLInputElement;
function openDatepicker() {
input.focus();
input.showPicker();
}
</script>

<svelte:head>
Expand All @@ -18,19 +25,16 @@

{#await images.back() then}
<header>
{#if $start}
<DateInput bind:value={$start} />
{:else}
<h2>{$date}</h2>
{/if}
<DateInput date={$date} bind:input bind:value={$start} />
</header>

<main>
{#if $start}
<County />
<County county={$county} />
{:else}
<h2>Set start date</h2>
<DateInput bind:value={$start} />
<h2>
<button on:click={openDatepicker}>Set start date</button>
</h2>
{/if}
{#await quote.load() then}
{#if $quote}
Expand Down
10 changes: 5 additions & 5 deletions src/lib/components/County.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script lang="ts" context="module">
import { county } from "$lib/data";
<script lang="ts">
export let county: { years: number; months: number; days: number };
</script>

<ul>
<li id="years">{$county.years}</li>
<li id="months">{$county.months}</li>
<li id="days">{$county.days}</li>
<li id="years">{county.years}</li>
<li id="months">{county.months}</li>
<li id="days">{county.days}</li>
</ul>

<style>
Expand Down
18 changes: 16 additions & 2 deletions src/lib/components/DateInput.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
<script lang="ts">
export let date = "";
export let value = "";
export let input: HTMLInputElement;
</script>

<form on:submit|preventDefault>
<form method="post" on:submit|preventDefault>
{#if !value}
<h2>{date}</h2>
{/if}
<label>
<input type="date" max={new Date().toLocaleString("ru")} bind:value />
<input
type="date"
max={new Date().toLocaleString("ru")}
class:hidden={!value}
bind:this={input}
bind:value
/>
</label>
</form>

Expand All @@ -18,4 +29,7 @@
color: inherit;
outline: 0;
}
input.hidden {
opacity: 0;
}
</style>

0 comments on commit f77341a

Please sign in to comment.