mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-07 21:48:18 -08:00
* add dev branch container to workflow * correctly set the default range of ActivityGrid * fix: set name/short_name to koito (#61) * fix dev container push workflow * fix: race condition with using getComputedStyle primary color for dynamic activity grid darkening (#76) * Fix race condition with using getComputedStyle primary color for dynamic activity grid darkening Instead just use the color from the current theme directly. Tested works on initial load and theme changes. Fixes https://github.com/gabehf/Koito/issues/75 * Rework theme provider to provide the actual Theme object throughtout the app, in addition to the name Split name out of the Theme struct to simplify custom theme saving/reading * fix: set first artist listed as primary by default (#81) * feat: add server-side configuration with default theme (#90) * docs: add example for usage of the main listenbrainz instance (#71) * docs: add example for usage of the main listenbrainz instance * Update scrobbler.md --------- Co-authored-by: Gabe Farrell <90876006+gabehf@users.noreply.github.com> * feat: add server-side cfg and default theme * fix: repair custom theme --------- Co-authored-by: m0d3rnX <jesper@posteo.de> * docs: add default theme cfg option to docs * feat: add ability to manually scrobble track (#91) * feat: add button to manually scrobble from ui * fix: ensure timestamp is in the past, log fix * test: add integration test * feat: add first listened to dates for media items (#92) * fix: ensure error checks for ErrNoRows * feat: add now playing endpoint and ui (#93) * wip * feat: add now playing * fix: set default theme when config is not set * feat: fetch images from subsonic server (#94) * fix: useQuery instead of useEffect for now playing * feat: custom artist separator regex (#95) * Fix race condition with using getComputedStyle primary color for dynamic activity grid darkening Instead just use the color from the current theme directly. Tested works on initial load and theme changes. Fixes https://github.com/gabehf/Koito/issues/75 * Rework theme provider to provide the actual Theme object throughtout the app, in addition to the name Split name out of the Theme struct to simplify custom theme saving/reading * feat: add server-side configuration with default theme (#90) * docs: add example for usage of the main listenbrainz instance (#71) * docs: add example for usage of the main listenbrainz instance * Update scrobbler.md --------- Co-authored-by: Gabe Farrell <90876006+gabehf@users.noreply.github.com> * feat: add server-side cfg and default theme * fix: repair custom theme --------- Co-authored-by: m0d3rnX <jesper@posteo.de> * fix: rebase errors --------- Co-authored-by: pet <128837728+againstpetra@users.noreply.github.com> Co-authored-by: mlandry <mike.landry@gmail.com> Co-authored-by: m0d3rnX <jesper@posteo.de>
107 lines
4.2 KiB
TypeScript
107 lines
4.2 KiB
TypeScript
import { ChevronDown, ChevronUp } from "lucide-react";
|
|
import { useEffect, useState } from "react";
|
|
|
|
interface Props {
|
|
stepSetter: (value: string) => void;
|
|
currentStep: string;
|
|
rangeSetter: (value: number) => void;
|
|
currentRange: number;
|
|
disableCache?: boolean;
|
|
}
|
|
|
|
export default function ActivityOptsSelector({
|
|
stepSetter,
|
|
currentStep,
|
|
rangeSetter,
|
|
currentRange,
|
|
disableCache = false,
|
|
}: Props) {
|
|
const stepPeriods = ['day', 'week', 'month'];
|
|
const rangePeriods = [105, 182, 364];
|
|
const [collapsed, setCollapsed] = useState(true);
|
|
|
|
const setMenuOpen = (val: boolean) => {
|
|
setCollapsed(val)
|
|
if (!disableCache) {
|
|
localStorage.setItem('activity_configuring_' + window.location.pathname.split('/')[1], String(!val));
|
|
}
|
|
}
|
|
|
|
const setStep = (val: string) => {
|
|
stepSetter(val);
|
|
if (!disableCache) {
|
|
localStorage.setItem('activity_step_' + window.location.pathname.split('/')[1], val);
|
|
}
|
|
};
|
|
|
|
const setRange = (val: number) => {
|
|
rangeSetter(val);
|
|
if (!disableCache) {
|
|
localStorage.setItem('activity_range_' + window.location.pathname.split('/')[1], String(val));
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (!disableCache) {
|
|
// TODO: the '182' here overwrites the default range as configured in the ActivityGrid. This is bad. Only one of these should determine the default.
|
|
const cachedRange = parseInt(localStorage.getItem('activity_range_' + window.location.pathname.split('/')[1]) ?? '182');
|
|
if (cachedRange) rangeSetter(cachedRange);
|
|
const cachedStep = localStorage.getItem('activity_step_' + window.location.pathname.split('/')[1]);
|
|
if (cachedStep) stepSetter(cachedStep);
|
|
const cachedConfiguring = localStorage.getItem('activity_configuring_' + window.location.pathname.split('/')[1]);
|
|
if (cachedStep) setMenuOpen(cachedConfiguring !== "true");
|
|
}
|
|
}, []);
|
|
|
|
return (
|
|
<div className="relative w-full">
|
|
<button
|
|
onClick={() => setMenuOpen(!collapsed)}
|
|
className="absolute left-[75px] -top-9 text-muted hover:color-fg transition"
|
|
title="Toggle options"
|
|
>
|
|
{collapsed ? <ChevronDown size={18} /> : <ChevronUp size={18} />}
|
|
</button>
|
|
|
|
<div
|
|
className={`overflow-hidden transition-[max-height,opacity] duration-250 ease ${
|
|
collapsed ? 'max-h-0 opacity-0' : 'max-h-[100px] opacity-100'
|
|
}`}
|
|
>
|
|
<div className="flex flex-wrap gap-4 mt-1 text-sm">
|
|
<div className="flex items-center gap-1">
|
|
<span className="text-muted">Step:</span>
|
|
{stepPeriods.map((p) => (
|
|
<button
|
|
key={p}
|
|
className={`px-1 rounded transition ${
|
|
p === currentStep ? 'color-fg font-medium' : 'color-fg-secondary hover:color-fg'
|
|
}`}
|
|
onClick={() => setStep(p)}
|
|
disabled={p === currentStep}
|
|
>
|
|
{p}
|
|
</button>
|
|
))}
|
|
</div>
|
|
|
|
<div className="flex items-center gap-1">
|
|
<span className="text-muted">Range:</span>
|
|
{rangePeriods.map((r) => (
|
|
<button
|
|
key={r}
|
|
className={`px-1 rounded transition ${
|
|
r === currentRange ? 'color-fg font-medium' : 'color-fg-secondary hover:color-fg'
|
|
}`}
|
|
onClick={() => setRange(r)}
|
|
disabled={r === currentRange}
|
|
>
|
|
{r}
|
|
</button>
|
|
))}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|