|
11 | 11 | } from 'date-fns'; |
12 | 12 | import Dot from '../components/dot.svelte'; |
13 | 13 | import { browser } from '$app/environment'; |
| 14 | + import * as Lockr from "lockr" |
| 15 | +
|
14 | 16 |
|
15 | 17 | function changeBg() { |
16 | 18 | document.querySelector(':root').style.setProperty('--bg-color', '#ffffff'); |
|
19 | 21 | let unit = $state('day'); |
20 | 22 | let timerange = $state('month'); |
21 | 23 |
|
| 24 | + let currentColors = $state(new Array(30).fill('')); |
| 25 | + let currentNotes = $state(new Array(30).fill('')); |
| 26 | +
|
22 | 27 | const secondsPer = { |
23 | 28 | min: 60, |
24 | 29 | hour: 60 * 60, |
|
110 | 115 |
|
111 | 116 | let rows = $derived(Math.ceil(dots / cols)); |
112 | 117 | let lastRow = $derived(dots % cols); |
113 | | - $inspect(nowDots); |
| 118 | +
|
| 119 | + let viewID = $derived(timerange + unit + colsName); |
| 120 | +
|
| 121 | + function save() { |
| 122 | + console.log("SAVING!") |
| 123 | + Lockr.set(viewID + "_notes", currentNotes) |
| 124 | + Lockr.set(viewID + "_colors", currentColors) |
| 125 | + } |
| 126 | +
|
| 127 | + $effect(() => { |
| 128 | + currentColors = Lockr.get(viewID + "_colors", new Array(30).fill('')) |
| 129 | + currentNotes = Lockr.get(viewID + "_notes", new Array(30).fill('')) |
| 130 | + }) |
| 131 | +
|
| 132 | + $inspect(currentColors); |
114 | 133 | </script> |
115 | 134 |
|
116 | 135 | {#snippet grid()} |
|
119 | 138 | <div class="flex flex-row gap-1"> |
120 | 139 | {#each cols != null ? { length: cols } : { length: 1 }, dot} |
121 | 140 | {#if lastRow == 0} |
122 | | - <Dot dotNum={row * cols + dot + 1} {nowDots} /> |
| 141 | + <Dot |
| 142 | + dotNum={row * cols + dot + 1} |
| 143 | + {nowDots} |
| 144 | + bind:newColor={currentColors[calcAmountOfDots(row, dot) - 1]} |
| 145 | + bind:note={currentNotes[calcAmountOfDots(row, dot) - 1]} |
| 146 | + /> |
123 | 147 | {:else if dot + 1 <= lastRow || row + 1 != rows} |
124 | | - <Dot dotNum={row * cols + dot + 1} {nowDots} /> |
| 148 | + <Dot |
| 149 | + dotNum={row * cols + dot + 1} |
| 150 | + {nowDots} |
| 151 | + bind:newColor={currentColors[calcAmountOfDots(row, dot) - 1]} |
| 152 | + bind:note={currentNotes[calcAmountOfDots(row, dot) - 1]} |
| 153 | + /> |
125 | 154 | {/if} |
126 | 155 | {/each} |
127 | 156 | </div> |
128 | 157 | {/each} |
129 | 158 | </div> |
130 | 159 | {/snippet} |
131 | 160 |
|
132 | | -<div class="bg-bg h-full w-full min-h-screen min-w-screen p-50"> |
133 | | - {#if timerange === 'year' && colsName === 'month' && unit === "day"} |
| 161 | +<div class="bg-bg h-full min-h-screen w-full min-w-screen p-50 transition-all"> |
| 162 | + {#if timerange === 'year' && colsName === 'month' && unit === 'day'} |
134 | 163 | <div class="flex flex-col gap-1"> |
135 | 164 | {#each { length: 12 }, row} |
136 | 165 | <div class="flex flex-row gap-1"> |
137 | 166 | {#each { length: daysInMonth[row] }, dot} |
138 | | - <Dot dotNum={calcAmountOfDots(row, dot)} {nowDots} /> |
| 167 | + <Dot |
| 168 | + dotNum={calcAmountOfDots(row, dot)} |
| 169 | + {nowDots} |
| 170 | + bind:newColor={currentColors[calcAmountOfDots(row, dot) - 1]} |
| 171 | + bind:note={currentNotes[calcAmountOfDots(row, dot) - 1]} |
| 172 | + /> |
139 | 173 | {/each} |
140 | 174 | </div> |
141 | 175 | {/each} |
|
174 | 208 | <option value="year">a year</option> |
175 | 209 | </select> |
176 | 210 |
|
177 | | - <div popover id="test" class="size-24 bg-primary"> |
178 | | - <!-- <ColorPicker components={ChromeVariant} sliderDirection="horizontal" isDialog={false} /> --> |
179 | | - |
180 | | - </div> |
181 | | - <button popovertarget="test" class="bg-inactive text-text"> test</button> |
| 211 | + <br /> |
| 212 | + |
| 213 | + <button class="bg-inactive text-text" onclick={save}>save notes and colors to this view</button> |
| 214 | + <button class="bg-inactive text-text">reset saved data for this view</button> |
182 | 215 | </div> |
0 commit comments