feature: improve calendar

This commit is contained in:
WonderAliceUwU committed 2026-07-10 19:50:22 +02:00
1 parent f40e1248b5
commit 8596293345
5 files changed
+402 -80

No files matched your search

+29 -1
View File
@@ -234,7 +234,35 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse):
if (url.pathname === '/api/calendar' && method === 'GET') {
const config = await readConfig(session!.encryptionKey);
sendJson(response, 200, await getCalendar(config));
const startParam = url.searchParams.get('start');
const endParam = url.searchParams.get('end');
let start = new Date();
start.setDate(1);
start.setHours(0, 0, 0, 0);
let end = new Date(start);
end.setMonth(end.getMonth() + 1);
end.setDate(0);
end.setHours(23, 59, 59, 999);
if (startParam) {
try {
start = new Date(startParam);
} catch (e) {
// ignore invalid date
}
}
if (endParam) {
try {
end = new Date(endParam);
} catch (e) {
// ignore invalid date
}
}
sendJson(response, 200, await getCalendar(config, start, end));
return;
}
+3 -5
View File
@@ -523,9 +523,7 @@ export async function getDownloads(config: AppConfig): Promise<DownloadItem[]> {
return downloads.sort((a, b) => b.progress - a.progress);
}
export async function getCalendar(config: AppConfig): Promise<CalendarResponse> {
const start = startOfToday()
const end = addDays(start, 30)
export async function getCalendar(config: AppConfig, start: Date, end: Date): Promise<CalendarResponse> {
const [sonarrResult, radarrResult] = await Promise.allSettled([
getSonarrCalendar(config, start, end),
@@ -3196,7 +3194,7 @@ async function getSonarrCalendar(config: AppConfig, start: Date, end: Date): Pro
}
return fetchJson<SonarrCalendarRecord[]>(
`${config.sonarr.baseUrl}/api/v3/calendar?includeSeries=true&start=${encodeURIComponent(start.toISOString())}&end=${encodeURIComponent(end.toISOString())}`,
`${config.sonarr.baseUrl}/api/v3/calendar?includeSeries=true&unmonitored=true&start=${encodeURIComponent(start.toISOString())}&end=${encodeURIComponent(end.toISOString())}`,
{
headers: {
'X-Api-Key': config.sonarr.apiKey
@@ -3211,7 +3209,7 @@ async function getRadarrCalendar(config: AppConfig, start: Date, end: Date): Pro
}
return fetchJson<RadarrCalendarRecord[]>(
`${config.radarr.baseUrl}/api/v3/calendar?start=${encodeURIComponent(start.toISOString())}&end=${encodeURIComponent(end.toISOString())}`,
`${config.radarr.baseUrl}/api/v3/calendar?unmonitored=true&start=${encodeURIComponent(start.toISOString())}&end=${encodeURIComponent(end.toISOString())}`,
{
headers: {
'X-Api-Key': config.radarr.apiKey
+147 -72
View File
@@ -84,8 +84,7 @@ function App() {
const [connections, setConnections] = useState<ConnectionStatus[]>([])
const [hubPages, setHubPages] = useState<Partial<Record<HubPageResponse['page'], HubPageResponse>>>({})
const [hubLoading, setHubLoading] = useState(false)
const [calendarItems, setCalendarItems] = useState<CalendarEntry[]>([])
const [calendarLoading, setCalendarLoading] = useState(false)
const [searchQuery, setSearchQuery] = useState('')
const [searchResults, setSearchResults] = useState<SearchResponse['items']>([])
const [searchLoading, setSearchLoading] = useState(false)
@@ -146,21 +145,7 @@ function App() {
}
}
async function loadCalendar(options?: { silent?: boolean }) {
if (!options?.silent) {
setCalendarLoading(true)
}
try {
const calendar = await api.getCalendar()
setCalendarItems(calendar.items)
} catch (loadError) {
setError(loadError instanceof Error ? loadError.message : 'Failed to load the calendar.')
} finally {
if (!options?.silent) {
setCalendarLoading(false)
}
}
}
useEffect(() => {
let cancelled = false
@@ -230,13 +215,7 @@ function App() {
}
}, [authState, entryStage, route])
useEffect(() => {
if (authState !== 'app' || entryStage !== 'dashboard' || route !== 'calendar') {
return
}
void loadCalendar()
}, [authState, entryStage, route])
useEffect(() => {
if (authState !== 'app' || entryStage !== 'dashboard') {
@@ -245,9 +224,7 @@ function App() {
const interval = window.setInterval(() => {
void refreshBaseData()
if (route === 'calendar') {
void loadCalendar({ silent: true })
} else if (route !== 'downloads' && route !== 'settings' && route !== 'search') {
if (route !== 'downloads' && route !== 'settings' && route !== 'search' && route !== 'calendar') {
void loadHub(route as HubPageResponse['page'], { silent: true })
}
}, 30000)
@@ -484,7 +461,7 @@ function App() {
{error ? <p className="error-banner">{error}</p> : null}
</div>
{route === 'calendar' ? <CalendarPage entries={calendarItems} loading={calendarLoading} onOpenCard={(card, originRect) => setSelectedCard({ card, originRect: originRect ?? null })} /> : null}
{route === 'calendar' ? <CalendarPage onOpenCard={(card, originRect) => setSelectedCard({ card, originRect: originRect ?? null })} /> : null}
{route === 'downloads' ? <DownloadsPage busyId={downloadDeleteId} downloads={downloads} onDelete={handleDeleteDownload} /> : null}
{route === 'search' ? (
<SearchPage
@@ -2607,64 +2584,162 @@ function DownloadRow(props: {
)
}
function ArrowLeftGlyph() {
return (
<svg aria-hidden="true" className="sidebar-glyph-icon" fill="none" viewBox="0 0 16 16">
<path d="M13 8H3" stroke="currentColor" strokeLinecap="round" strokeWidth="1.6" />
<path d="M6.75 4.25L3 8L6.75 11.75" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.6" />
</svg>
)
}
function CalendarPage(props: {
entries: CalendarEntry[]
loading: boolean
onOpenCard: (card: MediaCard, originRect?: ModalOriginRect | null) => void
}) {
if (props.loading) {
return <LoadingHub />
const [currentDate, setCurrentDate] = useState(new Date());
const [entries, setEntries] = useState<CalendarEntry[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState('');
const scrollContainerRef = useRef<HTMLDivElement>(null);
const nextUpRef = useRef<HTMLButtonElement>(null);
const [monthTransition, setMonthTransition] = useState<'idle' | 'next' | 'prev'>('idle');
useEffect(() => {
const start = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);
const end = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0);
let cancelled = false;
setLoading(true);
setError('');
api.getCalendar(start, end)
.then((response) => {
if (!cancelled) {
setEntries(response.items);
}
})
.catch((err) => {
if (!cancelled) {
setError(err.message || 'Failed to load calendar');
}
})
.finally(() => {
if (!cancelled) {
setLoading(false);
}
});
return () => {
cancelled = true;
};
}, [currentDate]);
useEffect(() => {
if (monthTransition === 'idle') {
return;
}
const timeout = setTimeout(() => {
setCurrentDate(current => {
const newDate = new Date(current);
newDate.setDate(1);
newDate.setMonth(newDate.getMonth() + (monthTransition === 'next' ? 1 : -1));
return newDate;
});
setMonthTransition('idle');
}, 400); // Match animation duration
return () => clearTimeout(timeout);
}, [monthTransition]);
const now = new Date();
const filteredEntries = entries.filter(entry => {
const entryDate = new Date(entry.startsAt);
return entryDate.getFullYear() === currentDate.getFullYear() && entryDate.getMonth() === currentDate.getMonth();
});
const nextUpEntry = filteredEntries.find(entry => new Date(entry.startsAt) >= now);
const nextUpId = nextUpEntry?.id;
const groups = groupCalendarEntries(filteredEntries);
useLayoutEffect(() => {
if (nextUpRef.current && scrollContainerRef.current) {
const container = scrollContainerRef.current;
const element = nextUpRef.current;
const elementRect = element.getBoundingClientRect();
const containerRect = container.getBoundingClientRect();
const scrollTop = element.offsetTop - container.offsetTop - (containerRect.height / 2) + (elementRect.height / 2);
container.scrollTo({ top: scrollTop, behavior: 'auto' });
}
}, [groups]);
function changeMonth(offset: number) {
if (monthTransition !== 'idle') return;
setMonthTransition(offset > 0 ? 'next' : 'prev');
}
if (loading && entries.length === 0) {
return <LoadingHub />;
}
if (!props.entries.length) {
return (
<EmptyState
copy="Upcoming movies and shows will appear here"
title="Nothing upcoming"
/>
)
if (error) {
return <EmptyState title="Error" copy={error} />;
}
const groups = groupCalendarEntries(props.entries)
return (
<div className="calendar-page">
<div className="calendar-header">
<h2>Upcoming</h2>
<button className="calendar-nav-button" onClick={() => changeMonth(-1)} disabled={monthTransition !== 'idle'}>
<ArrowLeftGlyph />
</button>
<h2>{currentDate.toLocaleString('en-US', { month: 'long' })}</h2>
<button className="calendar-nav-button" onClick={() => changeMonth(1)} disabled={monthTransition !== 'idle'}>
<ArrowRightGlyph />
</button>
</div>
<div className="calendar-groups">
{groups.map((group) => (
<section className="calendar-group" key={group.key}>
<div className="calendar-group-header">
<strong>{group.label}</strong>
</div>
<div className="calendar-group-list">
{group.items.map((entry) => (
<button
className="calendar-entry-card"
key={entry.id}
onClick={(event) => props.onOpenCard(entry.card, captureOriginRect(event.currentTarget))}
type="button"
>
<div className="calendar-entry-art">
{entry.imageUrl ? <img alt={entry.title} loading="lazy" src={entry.imageUrl} /> : <div className="media-fallback">{entry.title.slice(0, 1).toUpperCase()}</div>}
</div>
<div className="calendar-entry-copy">
<h4>{entry.title}</h4>
<p className="calendar-entry-subtitle">{entry.subtitle}</p>
<p className="calendar-entry-detail">{entry.detail}</p>
</div>
<div className="calendar-entry-time">
<span>{formatCalendarTime(entry.startsAt)}</span>
</div>
</button>
))}
</div>
</section>
))}
<div className="calendar-container">
<div className="calendar-scroll-container" ref={scrollContainerRef}>
<div className={`calendar-groups ${monthTransition !== 'idle' ? `month-transition-${monthTransition}` : ''}`}>
{groups.map((group) => (
<section className="calendar-group" key={group.key}>
<div className="calendar-group-header">
<strong>{group.label}</strong>
</div>
<div className="calendar-group-list">
{group.items.map((entry) => (
<button
ref={entry.id === nextUpId ? nextUpRef : null}
className={`calendar-entry-card ${entry.id === nextUpId ? 'is-next-up' : ''}`}
key={entry.id}
onClick={(event) => props.onOpenCard(entry.card, captureOriginRect(event.currentTarget))}
type="button"
>
<div className="calendar-entry-art">
{entry.imageUrl ? <img alt={entry.title} loading="lazy" src={entry.imageUrl} /> : <div className="media-fallback">{entry.title.slice(0, 1).toUpperCase()}</div>}
</div>
<div className="calendar-entry-copy">
<h4>{entry.title}</h4>
<p className="calendar-entry-subtitle">{entry.subtitle}</p>
<p className="calendar-entry-detail">{entry.detail}</p>
</div>
<div className="calendar-entry-time">
<span>{formatCalendarTime(entry.startsAt)}</span>
</div>
</button>
))}
</div>
</section>
))}
</div>
</div>
</div>
</div>
)
);
}
function humanizeDownloadState(state: string) {
+1 -1
View File
@@ -83,7 +83,7 @@ export const api = {
body: JSON.stringify(payload),
}),
getDashboard: () => request<DashboardResponse>('/api/dashboard'),
getCalendar: () => request<CalendarResponse>('/api/calendar'),
getCalendar: (start: Date, end: Date) => request<CalendarResponse>(`/api/calendar?start=${start.toISOString()}&end=${end.toISOString()}`),
getHub: (page: HubPageResponse['page']) => request<HubPageResponse>(`/api/hubs/${page}`),
searchTitles: (query: string) => request<SearchResponse>(`/api/search?query=${encodeURIComponent(query)}`),
getTitleDetails: (card: MediaCard, seasonId?: string) =>
+222 -1
View File
@@ -2578,7 +2578,7 @@ img {
.downloads-grid,
.search-results-section,
.settings-page {
padding: 0.4rem 2.35rem 0;
padding: 1rem 0;
}
.search-page {
@@ -3557,3 +3557,224 @@ img {
transform: rotate(360deg);
}
}
.calendar-page {
display: flex;
flex-direction: column;
gap: 1.6rem;
padding: 0 2.35rem 1rem;
height: 100%;
}
.calendar-header {
display: flex;
justify-content: center;
align-items: center;
gap: 1.5rem;
padding-top: 0.4rem;
}
.calendar-header h2 {
margin: 0;
font-size: 1.35rem;
font-weight: 700;
color: #d6d8de;
}
.calendar-nav-button {
background: transparent;
border: none;
color: #d6d8de;
padding: 0.5rem;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
transition: background-color 0.2s;
}
.calendar-nav-button:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.calendar-container {
flex: 1;
min-height: 0;
border-radius: 1.5rem;
overflow: hidden;
background: rgba(255, 255, 255, 0.045);
border: 1px solid rgba(255, 255, 255, 0.06);
padding: 1rem;
display: flex;
flex-direction: column;
}
.calendar-scroll-container {
overflow-y: auto;
height: 100%;
scrollbar-width: none;
}
.calendar-scroll-container::-webkit-scrollbar {
display: none;
}
.calendar-groups {
display: grid;
gap: 1.15rem;
transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s;
}
.month-transition-next,
.month-transition-prev {
transform: translateY(20px);
opacity: 0;
}
.calendar-group {
display: grid;
gap: 0.8rem;
}
.calendar-group-header {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 1rem;
padding: 0 1.2rem;
}
.calendar-group-header strong {
color: #eef4ff;
font-size: 1.04rem;
font-weight: 700;
}
.calendar-group-header span {
color: #8f9ab0;
font-size: 0.82rem;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.calendar-group-list {
display: grid;
gap: 0.9rem;
}
.calendar-entry-card {
display: grid;
grid-template-columns: 12rem minmax(0, 1fr) auto;
gap: 1rem;
align-items: center;
width: 100%;
padding: 1rem 1.1rem;
border: 1px solid rgba(255, 255, 255, 0.06);
border-radius: 1.35rem;
background: rgba(255, 255, 255, 0.045);
color: inherit;
text-align: left;
position: relative;
}
.calendar-entry-card.is-next-up::before {
content: "";
position: absolute;
inset: 0;
z-index: 0;
border-radius: 1.35rem;
padding: 2px;
background: linear-gradient(90deg, #68abff, #ffd166);
-webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
}
.calendar-entry-time {
display: grid;
align-content: center;
justify-items: end;
}
.calendar-entry-time span {
display: inline-flex;
align-items: center;
min-height: 2rem;
padding: 0;
border-radius: 0;
background-color: transparent;
color: #c4cee0;
font-size: 2rem;
font-weight: 700;
}
.calendar-entry-art {
border-radius: 1rem;
overflow: hidden;
aspect-ratio: 16 / 9;
background: rgba(255, 255, 255, 0.06);
position: relative;
z-index: 1;
}
.calendar-entry-art img,
.calendar-entry-art .media-fallback {
width: 100%;
height: 100%;
object-fit: cover;
}
.calendar-entry-copy {
display: grid;
align-content: center;
gap: 0.42rem;
min-width: 0;
position: relative;
z-index: 1;
}
.calendar-entry-meta {
display: flex;
flex-wrap: wrap;
gap: 0.45rem;
}
.calendar-entry-meta span {
padding: 0.2rem 0.55rem;
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
color: #aab5ca;
font-size: 0.7rem;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.calendar-entry-meta .calendar-entry-source.is-sonarr {
color: #8fc8ff;
}
.calendar-entry-meta .calendar-entry-source.is-radarr {
color: #ffd27a;
}
.calendar-entry-copy h4,
.calendar-entry-subtitle,
.calendar-entry-detail {
margin: 0;
}
.calendar-entry-copy h4 {
color: #eef4ff;
font-size: 1.08rem;
font-weight: 700;
}
.calendar-entry-subtitle {
color: #d9e1f0;
}
.calendar-entry-detail {
color: #93a0b9;
}