Debian Codegraph @

frontend/src/sidebar/AccountIndicator.svelte

raw
1 <script lang="ts">
2 import { timeDay } from "d3-time";
3
4 import { account_details, fava_options } from "../stores";
5
6 interface Props {
7 /** The account name. */
8 account: string;
9 /** Whether the indicator should be slightly smaller for the tree tables. */
10 small?: boolean;
11 }
12
13 let { account, small = false }: Props = $props();
14
15 let details = $derived($account_details[account]);
16 let status = $derived(details?.uptodate_status);
17 let balance = $derived(details?.balance_string ?? "");
18 let last_entry = $derived(details?.last_entry);
19
20 let last_account_activity = $derived(
21 last_entry ? timeDay.count(last_entry.date, new Date()) : 0,
22 );
23 </script>
24
25 {#if status}
26 {#if status === "green"}
27 <span
28 class="status-indicator status-green"
29 class:small
30 title="The last entry is a passing balance check."
31 ></span>
32 {:else}
33 <copyable-text
34 class="status-indicator status-{status}"
35 class:small
36 title={`${
37 status === "yellow"
38 ? "The last entry is not a balance check."
39 : "The last entry is a failing balance check."
40 }
41
42 Click to copy the balance directives to the clipboard:
43
44 ${balance}`}
45 data-clipboard-text={balance}
46 ></copyable-text>
47 {/if}
48 {#if last_account_activity > $fava_options.uptodate_indicator_grey_lookback_days}
49 <span
50 class="status-indicator status-gray"
51 class:small
52 title="This account has not been updated in a while. ({last_account_activity} days ago)"
53 ></span>
54 {/if}
55 {/if}
56
57 <style>
58 .status-indicator {
59 width: 10px;
60 height: 10px;
61 margin: 0 0 0 10px;
62 border-radius: 10px;
63 }
64
65 .status-indicator.small {
66 display: inline-block;
67 width: 6px;
68 height: 6px;
69 margin: 5px;
70 border-radius: 6px;
71 }
72
73 .status-indicator.status-gray {
74 margin-left: 0;
75 }
76 </style>