anki/ts/card-info/Revlog.svelte
Henrik Giesel ab6a68ec49
Introduce our own Container, Row, and Col components (#1495)
* Refactor out Placeholder from CardInfo.svelte

* Add breakpoint parameter for Container

- Use `Container` component inside `TitledContainer`

* Build Item into Row

- Use Row in DeckOptionsPage instead of just Item

* Reengineer Container/Row/Col CSS

* Inline Badges next to Labels when Lable spans multiple rows

* Adjust margins for mobile

* Implement Col component breakpoints

* Move card-info to use new Container and Row components

* Join StickyHeader and StickyFooter to StickyContainer

* Remove default middle vertical-alignment for Badges again

* Satisfy tests

* Restore inline gutters in change-notetype Mapper

* Add some comment to Col and Container

* Fix breaking behavior in DeckOptionsPage when multi-column

* Add back toolbar left padding to counter-act buttongroup right margins

* Make Label in SwitchRow take more of available space
2021-11-17 13:49:52 +10:00

142 lines
4.2 KiB
Svelte

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
import * as tr2 from "../lib/ftl";
import { Stats } from "../lib/proto";
import { Timestamp, timeSpan } from "../lib/time";
type StatsRevlogEntry = Stats.CardStatsResponse.StatsRevlogEntry;
export let revlog: StatsRevlogEntry[];
function reviewKindClass(entry: StatsRevlogEntry): string {
switch (entry.reviewKind) {
case Stats.RevlogEntry.ReviewKind.LEARNING:
return "revlog-learn";
case Stats.RevlogEntry.ReviewKind.REVIEW:
return "revlog-review";
case Stats.RevlogEntry.ReviewKind.RELEARNING:
return "revlog-relearn";
}
return "";
}
function reviewKindLabel(entry: StatsRevlogEntry): string {
switch (entry.reviewKind) {
case Stats.RevlogEntry.ReviewKind.LEARNING:
return tr2.cardStatsReviewLogTypeLearn();
case Stats.RevlogEntry.ReviewKind.REVIEW:
return tr2.cardStatsReviewLogTypeReview();
case Stats.RevlogEntry.ReviewKind.RELEARNING:
return tr2.cardStatsReviewLogTypeRelearn();
case Stats.RevlogEntry.ReviewKind.FILTERED:
return tr2.cardStatsReviewLogTypeFiltered();
case Stats.RevlogEntry.ReviewKind.MANUAL:
return tr2.cardStatsReviewLogTypeManual();
}
}
function ratingClass(entry: StatsRevlogEntry): string {
if (entry.buttonChosen === 1) {
return "revlog-ease1";
}
return "";
}
interface RevlogRow {
date: string;
time: string;
reviewKind: string;
reviewKindClass: string;
rating: number;
ratingClass: string;
interval: string;
ease: string;
takenSecs: string;
}
function revlogRowFromEntry(entry: StatsRevlogEntry): RevlogRow {
const timestamp = new Timestamp(entry.time);
return {
date: timestamp.dateString(),
time: timestamp.timeString(),
reviewKind: reviewKindLabel(entry),
reviewKindClass: reviewKindClass(entry),
rating: entry.buttonChosen,
ratingClass: ratingClass(entry),
interval: timeSpan(entry.interval),
ease: entry.ease ? `${entry.ease / 10}%` : "",
takenSecs: timeSpan(entry.takenSecs, true),
};
}
$: revlogRows = revlog.map(revlogRowFromEntry);
</script>
{#if revlog.length > 0}
<table class="revlog-table">
<tr>
<th class="left">{tr2.cardStatsReviewLogDate()}</th>
<th class="center hidden-xs">{tr2.cardStatsReviewLogType()}</th>
<th class="center">{tr2.cardStatsReviewLogRating()}</th>
<th class="right">{tr2.cardStatsInterval()}</th>
<th class="center hidden-xs">{tr2.cardStatsEase()}</th>
<th class="right">{tr2.cardStatsReviewLogTimeTaken()}</th>
</tr>
{#each revlogRows as row, _index}
<tr>
<td class="left"><b>{row.date}</b> @ {row.time}</td>
<td class="center hidden-xs {row.reviewKindClass}">
{row.reviewKind}
</td>
<td class="center {row.ratingClass}">{row.rating}</td>
<td class="right">{row.interval}</td>
<td class="center hidden-xs">{row.ease}</td>
<td class="right">{row.takenSecs}</td>
</tr>
{/each}
</table>
{/if}
<style>
.left {
text-align: start;
}
.right {
text-align: end;
}
.center {
text-align: center;
}
.revlog-table {
width: 100%;
border-spacing: 1em 0;
border-collapse: collapse;
}
.revlog-learn {
color: var(--new-count);
}
.revlog-review {
color: var(--review-count);
}
.revlog-relearn,
.revlog-ease1 {
color: var(--learn-count);
}
@media only screen and (max-device-width: 480px) and (orientation: portrait) {
.hidden-xs {
display: none;
}
}
</style>