2020-06-22 11:11:50 +02:00
|
|
|
<script context="module">
|
|
|
|
import style from "./graphs.css";
|
|
|
|
|
|
|
|
document.head.append(style);
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="typescript">
|
|
|
|
import debounce from "lodash.debounce";
|
|
|
|
|
|
|
|
import { assertUnreachable } from "../typing";
|
|
|
|
import pb from "../backend/proto";
|
|
|
|
import { getGraphData, GraphRange } from "./graphs";
|
|
|
|
import IntervalsGraph from "./IntervalsGraph.svelte";
|
|
|
|
|
|
|
|
let data: pb.BackendProto.GraphsOut | null = null;
|
|
|
|
|
2020-06-22 12:28:36 +02:00
|
|
|
enum SearchRange {
|
|
|
|
Deck = 1,
|
|
|
|
Collection = 2,
|
|
|
|
Custom = 3,
|
|
|
|
}
|
|
|
|
|
|
|
|
let searchRange: SearchRange = SearchRange.Deck;
|
2020-06-22 11:11:50 +02:00
|
|
|
let range: GraphRange = GraphRange.Month;
|
|
|
|
let days: number = 31;
|
|
|
|
|
2020-06-22 12:28:36 +02:00
|
|
|
let search = "deck:current";
|
|
|
|
|
2020-06-22 11:11:50 +02:00
|
|
|
const refresh = async () => {
|
2020-06-22 12:28:36 +02:00
|
|
|
console.log(`search is ${search}`);
|
2020-06-22 11:11:50 +02:00
|
|
|
data = await getGraphData(search, days);
|
|
|
|
};
|
|
|
|
|
2020-06-22 12:28:36 +02:00
|
|
|
$: {
|
|
|
|
switch (searchRange as SearchRange) {
|
|
|
|
case SearchRange.Deck:
|
|
|
|
search = "deck:current";
|
|
|
|
refresh();
|
|
|
|
break;
|
|
|
|
case SearchRange.Collection:
|
|
|
|
search = "";
|
|
|
|
refresh();
|
|
|
|
break;
|
|
|
|
case SearchRange.Custom:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-22 11:11:50 +02:00
|
|
|
$: {
|
2020-06-22 11:51:23 +02:00
|
|
|
const rangeTmp = range as GraphRange; // ts workaround
|
|
|
|
switch (rangeTmp) {
|
2020-06-22 11:11:50 +02:00
|
|
|
case GraphRange.Month:
|
|
|
|
days = 31;
|
|
|
|
break;
|
|
|
|
case GraphRange.Year:
|
|
|
|
days = 365;
|
|
|
|
break;
|
|
|
|
case GraphRange.All:
|
|
|
|
days = 0;
|
|
|
|
break;
|
|
|
|
default:
|
2020-06-22 11:51:23 +02:00
|
|
|
assertUnreachable(rangeTmp);
|
2020-06-22 11:11:50 +02:00
|
|
|
}
|
|
|
|
console.log("refresh");
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
const scheduleRefresh = debounce(() => {
|
|
|
|
refresh();
|
|
|
|
}, 1000);
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="range-box">
|
2020-06-22 12:28:36 +02:00
|
|
|
<label>
|
|
|
|
<input type="radio" bind:group={searchRange} value={SearchRange.Deck} />
|
|
|
|
Deck
|
|
|
|
</label>
|
|
|
|
<label>
|
|
|
|
<input type="radio" bind:group={searchRange} value={SearchRange.Collection} />
|
|
|
|
Collection
|
|
|
|
</label>
|
|
|
|
<label>
|
|
|
|
<input type="radio" bind:group={searchRange} value={SearchRange.Custom} />
|
|
|
|
Custom
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<input type="text" bind:value={search} on:input={scheduleRefresh} />
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="range-box">
|
|
|
|
Review history:
|
2020-06-22 11:11:50 +02:00
|
|
|
<label>
|
|
|
|
<input type="radio" bind:group={range} value={GraphRange.Month} />
|
|
|
|
Month
|
|
|
|
</label>
|
|
|
|
<label>
|
|
|
|
<input type="radio" bind:group={range} value={GraphRange.Year} />
|
|
|
|
Year
|
|
|
|
</label>
|
|
|
|
<label>
|
|
|
|
<input type="radio" bind:group={range} value={GraphRange.All} />
|
|
|
|
All
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<IntervalsGraph {data} />
|