mirror of
https://github.com/WonderAliceUwU/OmniArr.git
synced 2026-11-21 03:35:56 +00:00
feature: add calendar
This commit is contained in:
1 parent
b38d3e03c1
commit
7de5dcf00d
6 files changed
+621
-12
No files matched your search
+157
-10
@@ -11,6 +11,7 @@ import {
|
||||
} from 'react'
|
||||
import { api } from './api'
|
||||
import {
|
||||
type CalendarEntry,
|
||||
defaultConfig,
|
||||
type AppConfig,
|
||||
type AppRoute,
|
||||
@@ -35,11 +36,12 @@ const EPISODE_SCROLL_DISTANCE_RATIO = 0.72
|
||||
const SEASON_DOMINANCE_SWITCH_RATIO = 0.12
|
||||
const SEASON_DOMINANCE_SWITCH_MIN_PX = 56
|
||||
|
||||
const sidebarItems: Array<{ route: AppRoute; label: string; short: string }> = [
|
||||
const sidebarItems: Array<{ route: AppRoute; label: string; short: string; icon?: 'calendar' }> = [
|
||||
{ route: 'home', label: 'Inicio', short: 'H' },
|
||||
{ route: 'dorama', label: 'K-Drama', short: 'K' },
|
||||
{ route: 'anime', label: 'Anime', short: 'A' },
|
||||
{ route: 'library', label: 'Library', short: 'L' },
|
||||
{ route: 'calendar', label: 'Upcoming', short: 'C', icon: 'calendar' },
|
||||
{ route: 'downloads', label: 'Downloads', short: 'D' },
|
||||
]
|
||||
|
||||
@@ -73,6 +75,8 @@ 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 [selectedCard, setSelectedCard] = useState<SelectedCardState | null>(null)
|
||||
const [downloadDeleteId, setDownloadDeleteId] = useState('')
|
||||
const [entryTransitionState, setEntryTransitionState] = useState<EntryTransitionState>('idle')
|
||||
@@ -129,6 +133,22 @@ 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
|
||||
|
||||
@@ -170,7 +190,7 @@ function App() {
|
||||
return
|
||||
}
|
||||
|
||||
if (route === 'downloads' || route === 'settings') {
|
||||
if (route === 'downloads' || route === 'settings' || route === 'calendar') {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -197,6 +217,14 @@ 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') {
|
||||
return
|
||||
@@ -204,7 +232,9 @@ function App() {
|
||||
|
||||
const interval = window.setInterval(() => {
|
||||
void refreshBaseData()
|
||||
if (route !== 'downloads' && route !== 'settings') {
|
||||
if (route === 'calendar') {
|
||||
void loadCalendar({ silent: true })
|
||||
} else if (route !== 'downloads' && route !== 'settings') {
|
||||
void loadHub(route as HubPageResponse['page'], { silent: true })
|
||||
}
|
||||
}, 30000)
|
||||
@@ -306,7 +336,9 @@ function App() {
|
||||
} else {
|
||||
await api.requestSeries(card.tmdbId)
|
||||
}
|
||||
if (route !== 'downloads' && route !== 'settings') {
|
||||
if (route === 'calendar') {
|
||||
await loadCalendar({ silent: true })
|
||||
} else if (route !== 'downloads' && route !== 'settings') {
|
||||
await loadHub(route as HubPageResponse['page'], { silent: true })
|
||||
}
|
||||
setNotice(`${card.title} sent to ${card.mediaType === 'movie' ? 'Radarr' : 'Sonarr'}.`)
|
||||
@@ -395,7 +427,7 @@ function App() {
|
||||
|
||||
const currentJellyfinUser =
|
||||
options.jellyfinUsers.find((option) => option.id === config.jellyfin.userId)?.label || 'Media cockpit'
|
||||
const currentHub = route !== 'downloads' && route !== 'settings' ? hubPages[route as HubPageResponse['page']] : undefined
|
||||
const currentHub = route !== 'downloads' && route !== 'settings' && route !== 'calendar' ? hubPages[route as HubPageResponse['page']] : undefined
|
||||
|
||||
return (
|
||||
<div className={`reiverr-app ${getEntryTransitionClassName(entryTransitionState)}`}>
|
||||
@@ -416,6 +448,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 === 'downloads' ? <DownloadsPage busyId={downloadDeleteId} downloads={downloads} onDelete={handleDeleteDownload} /> : null}
|
||||
{route === 'settings' ? (
|
||||
<SettingsView
|
||||
@@ -429,7 +462,7 @@ function App() {
|
||||
updateConfig={updateConfig}
|
||||
/>
|
||||
) : null}
|
||||
{route !== 'downloads' && route !== 'settings' ? (
|
||||
{route !== 'downloads' && route !== 'settings' && route !== 'calendar' ? (
|
||||
<HubPageView
|
||||
busy={busy}
|
||||
hub={currentHub}
|
||||
@@ -494,7 +527,9 @@ function Sidebar(props: {
|
||||
onClick={() => startTransition(() => props.setRoute(item.route))}
|
||||
type="button"
|
||||
>
|
||||
<span className="sidebar-link-short" aria-hidden="true">{item.short}</span>
|
||||
<span className="sidebar-link-short" aria-hidden="true">
|
||||
{item.icon === 'calendar' ? <CalendarGlyph /> : item.short}
|
||||
</span>
|
||||
<span>{item.label}</span>
|
||||
</button>
|
||||
))}
|
||||
@@ -799,11 +834,20 @@ function HeroShowcase({ hero, onOpenCard, tmdbToken }: { hero: MediaCard[]; onOp
|
||||
|
||||
useEffect(() => {
|
||||
if (!featured?.tmdbId) {
|
||||
setActiveLogoUrl('')
|
||||
setActiveLogoUrl(featured?.logoUrl || '')
|
||||
return
|
||||
}
|
||||
|
||||
const mediaType = featured.mediaType === 'movie' ? 'movie' : featured.mediaType === 'tv' || featured.mediaType === 'series' ? 'tv' : ''
|
||||
if (featured.logoUrl) {
|
||||
setActiveLogoUrl(featured.logoUrl)
|
||||
return
|
||||
}
|
||||
|
||||
const mediaType = featured.mediaType === 'movie'
|
||||
? 'movie'
|
||||
: featured.mediaType === 'tv' || featured.mediaType === 'series' || featured.mediaType === 'episode'
|
||||
? 'tv'
|
||||
: ''
|
||||
if (!mediaType) {
|
||||
setActiveLogoUrl('')
|
||||
return
|
||||
@@ -855,7 +899,7 @@ function HeroShowcase({ hero, onOpenCard, tmdbToken }: { hero: MediaCard[]; onOp
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [featured])
|
||||
}, [featured, tmdbToken])
|
||||
|
||||
if (!featured) {
|
||||
return (
|
||||
@@ -1944,6 +1988,14 @@ function PlayGlyph() {
|
||||
)
|
||||
}
|
||||
|
||||
function CalendarGlyph() {
|
||||
return (
|
||||
<svg aria-hidden="true" className="sidebar-glyph-icon" viewBox="0 0 16 16">
|
||||
<path d="M4.25 2.35h1.1v1.3h5.3v-1.3h1.1v1.3h1.05c.9 0 1.55.65 1.55 1.55v6.55c0 .9-.65 1.55-1.55 1.55H3.2c-.9 0-1.55-.65-1.55-1.55V5.2c0-.9.65-1.55 1.55-1.55h1.05v-1.3Zm-1.05 2.4c-.27 0-.45.18-.45.45v1.15h10.5V5.2c0-.27-.18-.45-.45-.45H3.2Zm10.05 2.7H2.75v4.3c0 .27.18.45.45.45h9.6c.27 0 .45-.18.45-.45v-4.3Z" fill="currentColor" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
function MenuGlyph() {
|
||||
return (
|
||||
<svg aria-hidden="true" className="title-action-icon" viewBox="0 0 16 16">
|
||||
@@ -2088,6 +2140,66 @@ function DownloadRow(props: {
|
||||
)
|
||||
}
|
||||
|
||||
function CalendarPage(props: {
|
||||
entries: CalendarEntry[]
|
||||
loading: boolean
|
||||
onOpenCard: (card: MediaCard, originRect?: ModalOriginRect | null) => void
|
||||
}) {
|
||||
if (props.loading) {
|
||||
return <LoadingHub />
|
||||
}
|
||||
|
||||
if (!props.entries.length) {
|
||||
return (
|
||||
<EmptyState
|
||||
copy="Upcoming movies and shows will appear here"
|
||||
title="Nothing upcoming"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const groups = groupCalendarEntries(props.entries)
|
||||
|
||||
return (
|
||||
<div className="calendar-page">
|
||||
<div className="calendar-header">
|
||||
<h2>Upcoming</h2>
|
||||
</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>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function humanizeDownloadState(state: string) {
|
||||
return state
|
||||
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
||||
@@ -2095,6 +2207,41 @@ function humanizeDownloadState(state: string) {
|
||||
.replace(/\b\w/g, (match) => match.toUpperCase())
|
||||
}
|
||||
|
||||
function groupCalendarEntries(entries: CalendarEntry[]) {
|
||||
const formatter = new Intl.DateTimeFormat('en-US', {
|
||||
weekday: 'long',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
})
|
||||
const grouped = new Map<string, { key: string; label: string; items: CalendarEntry[] }>()
|
||||
|
||||
for (const entry of entries) {
|
||||
const date = new Date(entry.startsAt)
|
||||
const key = date.toISOString().slice(0, 10)
|
||||
const current = grouped.get(key)
|
||||
if (current) {
|
||||
current.items.push(entry)
|
||||
continue
|
||||
}
|
||||
grouped.set(key, {
|
||||
key,
|
||||
label: formatter.format(date),
|
||||
items: [entry],
|
||||
})
|
||||
}
|
||||
|
||||
return [...grouped.values()]
|
||||
}
|
||||
|
||||
function formatCalendarTime(startsAt: string) {
|
||||
const date = new Date(startsAt)
|
||||
return new Intl.DateTimeFormat('en-US', {
|
||||
hour: 'numeric',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
}).format(date)
|
||||
}
|
||||
|
||||
function SettingsView(props: {
|
||||
config: AppConfig
|
||||
connections: ConnectionStatus[]
|
||||
|
||||
@@ -2,6 +2,7 @@ import type {
|
||||
AppConfig,
|
||||
AuthPayload,
|
||||
AuthResponse,
|
||||
CalendarResponse,
|
||||
DashboardResponse,
|
||||
DownloadItem,
|
||||
HubPageResponse,
|
||||
@@ -81,6 +82,7 @@ export const api = {
|
||||
body: JSON.stringify(payload),
|
||||
}),
|
||||
getDashboard: () => request<DashboardResponse>('/api/dashboard'),
|
||||
getCalendar: () => request<CalendarResponse>('/api/calendar'),
|
||||
getHub: (page: HubPageResponse['page']) => request<HubPageResponse>(`/api/hubs/${page}`),
|
||||
getTitleDetails: (card: MediaCard, seasonId?: string) =>
|
||||
request<TitleDetailsResponse>('/api/title-details', {
|
||||
|
||||
+181
@@ -369,6 +369,12 @@ img {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.sidebar-glyph-icon {
|
||||
width: 0.98rem;
|
||||
height: 0.98rem;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.sidebar-network-icon {
|
||||
overflow: hidden;
|
||||
padding: 0.2rem;
|
||||
@@ -464,6 +470,7 @@ img {
|
||||
}
|
||||
|
||||
.hub-page,
|
||||
.calendar-page,
|
||||
.downloads-page,
|
||||
.settings-page {
|
||||
display: grid;
|
||||
@@ -2327,11 +2334,168 @@ img {
|
||||
color: #c4cee0;
|
||||
}
|
||||
|
||||
.calendar-groups,
|
||||
.downloads-grid,
|
||||
.settings-page {
|
||||
padding: 0 1.25rem 1rem;
|
||||
}
|
||||
|
||||
.calendar-page {
|
||||
gap: 1.6rem;
|
||||
}
|
||||
|
||||
.calendar-header {
|
||||
display: grid;
|
||||
gap: 0.3rem;
|
||||
padding: 0 2.35rem;
|
||||
}
|
||||
|
||||
.calendar-header h2 {
|
||||
margin: 0;
|
||||
font-size: 1.35rem;
|
||||
font-weight: 700;
|
||||
color: #d6d8de;
|
||||
}
|
||||
|
||||
.calendar-header p {
|
||||
margin: 0;
|
||||
color: #95a2ba;
|
||||
}
|
||||
|
||||
.calendar-groups {
|
||||
display: grid;
|
||||
gap: 1.15rem;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.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);
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.downloads-section {
|
||||
padding-bottom: 1.4rem;
|
||||
}
|
||||
@@ -2994,6 +3158,23 @@ img {
|
||||
.download-card {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.calendar-header {
|
||||
padding-left: 1.25rem;
|
||||
padding-right: 1.25rem;
|
||||
}
|
||||
|
||||
.calendar-entry-card {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.calendar-entry-art {
|
||||
order: -1;
|
||||
}
|
||||
|
||||
.calendar-entry-time {
|
||||
padding-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes titleHeroRise {
|
||||
|
||||
Reference in new issue
Block a user