|
1 | 1 | <script lang="ts"> |
2 | 2 | import { dateToString } from '$lib/tools'; |
3 | 3 | import NotificationRequester from '$lib/components/NotificationRequester.svelte'; |
| 4 | + import Datepicker from 'svelte-calendar/src/Components/Datepicker.svelte'; |
| 5 | +
|
| 6 | + import { MS_IN_DAY } from '$lib/consts' |
| 7 | +
|
| 8 | +
|
4 | 9 |
|
5 | 10 | export let dates: [number, number]; |
| 11 | +
|
| 12 | + let chosenStart: Date = new Date(dates[0]*MS_IN_DAY); |
| 13 | + let chosenEnd: Date = new Date(dates[1]*MS_IN_DAY); |
| 14 | + function timeFromDate (date: Date ): number { |
| 15 | +
|
| 16 | + return Math.round(date.getTime() / MS_IN_DAY); |
| 17 | + }; |
| 18 | +
|
| 19 | + function chosenStartCallback() { |
| 20 | + console.log("Start Chosen",chosenStart); |
| 21 | + dates[0]=timeFromDate(chosenStart) |
| 22 | + } |
| 23 | + function chosenEndCallback() { |
| 24 | + console.log("Start Chosen",chosenStart); |
| 25 | + dates[1]=timeFromDate(chosenEnd) |
| 26 | + } |
| 27 | +
|
| 28 | + |
6 | 29 | </script> |
7 | 30 |
|
8 | 31 | {#if dates} |
|
14 | 37 |
|
15 | 38 | <h3 class="results-info__title">Showing Results</h3> |
16 | 39 | <div class="results-info__body"> |
17 | | - <span class="results-info__body__marker" |
18 | | - >From |
19 | | - <span>{dateToString(dates[0])}</span> |
20 | | - </span> |
21 | | - <span class="results-info__body__marker" |
22 | | - >To |
23 | | - <span>{dateToString(dates[1])}</span> |
24 | | - </span> |
| 40 | + <Datepicker bind:selected={chosenStart} on:dateSelected={chosenStartCallback} end={chosenEnd}> |
| 41 | + <span class="results-info__body__marker" |
| 42 | + >From |
| 43 | + <span>{dateToString(dates[0])}</span> |
| 44 | + </span> |
| 45 | + </Datepicker> |
| 46 | + <Datepicker bind:selected={chosenEnd} on:dateSelected={chosenEndCallback} start={chosenStart} end={new Date()}> |
| 47 | + <span class="results-info__body__marker" |
| 48 | + >To |
| 49 | + <span>{dateToString(dates[1])}</span> |
| 50 | + </span> |
| 51 | + </Datepicker> |
| 52 | + |
25 | 53 | </div> |
26 | 54 | </div> |
27 | 55 | {/if} |
|
80 | 108 | margin-right: 1em; |
81 | 109 |
|
82 | 110 | > span { |
| 111 | + cursor: pointer; |
83 | 112 | } |
84 | 113 | } |
85 | 114 | } |
|
0 commit comments