| 1 |
import { derived, writable } from "svelte/store"; |
| 2 |
|
| 3 |
/** The time filter. */ |
| 4 |
export const time_filter = writable(""); |
| 5 |
/** The account filter. */ |
| 6 |
export const account_filter = writable(""); |
| 7 |
/** The filter with our custom query syntax. */ |
| 8 |
export const fql_filter = writable(""); |
| 9 |
|
| 10 |
/** The three entry filters that Fava supports. */ |
| 11 |
export interface Filters extends Record<string, string | undefined> { |
| 12 |
account: string; |
| 13 |
filter: string; |
| 14 |
time: string; |
| 15 |
} |
| 16 |
|
| 17 |
/** The three filters as well as conversion and interval. */ |
| 18 |
export interface FiltersConversionInterval extends Filters { |
| 19 |
conversion: string; |
| 20 |
interval: string; |
| 21 |
} |
| 22 |
|
| 23 |
/** The current filters, can be used as URL parameters. */ |
| 24 |
export const filter_params = derived( |
| 25 |
[time_filter, account_filter, fql_filter], |
| 26 |
([$time_filter, $account_filter, $fql_filter]): Filters => ({ |
| 27 |
time: $time_filter, |
| 28 |
account: $account_filter, |
| 29 |
filter: $fql_filter, |
| 30 |
}), |
| 31 |
); |
| 32 |
|
| 33 |
export function getURLFilters(url: URL): FiltersConversionInterval { |
| 34 |
return { |
| 35 |
account: url.searchParams.get("account") ?? "", |
| 36 |
filter: url.searchParams.get("filter") ?? "", |
| 37 |
time: url.searchParams.get("time") ?? "", |
| 38 |
conversion: url.searchParams.get("conversion") ?? "", |
| 39 |
interval: url.searchParams.get("interval") ?? "", |
| 40 |
}; |
| 41 |
} |