Skip to content

Commit

Permalink
add: begining logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Valexr committed Apr 14, 2024
1 parent f99730b commit efdc987
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 49 deletions.
62 changes: 25 additions & 37 deletions src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts" context="module">
import Gh from "$lib/components/Gh.svelte";
import DateInput from "$lib/components/DateInput.svelte";
import { date, time, start, county } from "$lib/data";
import { getPhotos } from "$lib/images";
</script>
Expand All @@ -8,8 +9,6 @@
export let name: Name;
export let repository: Repository;
$start = "2013-04-09";
async function setBack() {
const image = await getPhotos(1, {});
if (image) {
Expand All @@ -32,40 +31,36 @@

{#await setBack() then}
<header>
<!-- <button>Image</button>
<h1>
<Gh {repository} />
{name}
</h1>
<button>Settings</button> -->
<form action="POST" on:submit|preventDefault>
<label>
<input
type="date"
placeholder="Set start date"
bind:value={$start}
/>
</label>
</form>
{#if $start}
<DateInput bind:value={$start} />
{:else}
<h2>{$date}</h2>
{/if}
</header>

<main>
<!-- <h2>{$date}</h2> -->
<ul>
<li id="years">{$county.years}</li>
<li id="months">{$county.months}</li>
<li id="days">{$county.days}</li>
</ul>
{#if $start}
<ul>
<li id="years">{$county.years}</li>
<li id="months">{$county.months}</li>
<li id="days">{$county.days}</li>
</ul>
{:else}
<h2>Set start date</h2>
<DateInput bind:value={$start} />
{/if}
{#await getQuote() then { quote, author }}
<blockquote>
<p>{quote}</p>
<footer>~ {author}</footer>
<cite>~ {author}</cite>
</blockquote>
{/await}
</main>

<footer>
<button on:click={setBack}>Image</button>
<h2>{$time}</h2>
<button>Settings</button>
</footer>
{/await}

Expand All @@ -75,24 +70,14 @@
header {
justify-content: center;
}
footer h2 {
margin: 0;
}
main {
padding: 1em;
display: grid;
place-content: center;
}
form {
/* display: flex; */
align-items: center;
justify-content: center;
}
input {
font-size: 1.5em;
font-weight: bold;
font-family: inherit;
background: transparent;
border: 0;
color: inherit;
}
ul {
list-style: none;
padding: 0;
Expand All @@ -119,4 +104,7 @@
blockquote p {
font-style: italic;
}
blockquote cite {
font-style: normal;
}
</style>
3 changes: 2 additions & 1 deletion src/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ body::after {
inset: 0;
}

header {
header,
footer {
display: flex;
align-items: center;
justify-content: space-between;
Expand Down
21 changes: 21 additions & 0 deletions src/lib/components/DateInput.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script lang="ts">
export let value = "";
</script>

<form on:submit|preventDefault>
<label>
<input type="date" max={new Date().toLocaleString("ru")} bind:value />
</label>
</form>

<style>
input {
font-size: 1.5em;
font-weight: bold;
font-family: inherit;
background: transparent;
border: 0;
color: inherit;
outline: 0;
}
</style>
24 changes: 13 additions & 11 deletions src/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import { cacheable } from './cacheable';
export const start = cacheable('startDate', '', true)

export const county = derived(start, ($start, set) => {
const now = new Date();
const start = new Date($start);
const elapsedYears = now.getTime() - start.getTime();
const elapsedMonth = now.getMonth() - start.getMonth();
const elapsedDays = now.getDate() - start.getDate();
const daysInMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0,).getDate();
const years = new Date(elapsedYears).getFullYear() - 1970
const months = (years * 12 + elapsedMonth) % 12
const days = (months * daysInMonth + elapsedDays) % daysInMonth

set({ years, months, days })
if (start) {
const now = new Date();
const start = new Date($start);
const elapsedYears = now.getTime() - start.getTime();
const elapsedMonth = now.getMonth() - start.getMonth();
const elapsedDays = now.getDate() - start.getDate();
const daysInMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0,).getDate();
const years = new Date(elapsedYears).getFullYear() - 1970
const months = (years * 12 + elapsedMonth) % 12
const days = (months * daysInMonth + elapsedDays) % daysInMonth

set({ years, months, days })
}

}, { years: 0, months: 0, days: 0 })

Expand Down

0 comments on commit efdc987

Please sign in to comment.