Implement Phases 1-5: skeleton, OAuth, categories, video sync/feed, playback
- FastAPI + PostgreSQL + Alembic + React/Vite skeleton, Docker Compose, healthcheck
- Google OAuth (single allowed account), encrypted refresh token storage
- Subscriptions sync with pagination, uploads playlist batch fetch
- Categories CRUD, many-to-many channel assignment, category filtering
- Video sync (playlistItems + videos.list batching), cached feed with cursor
pagination, background scheduler (APScheduler)
- Video detail page with YouTube embed player
- SPA fallback routing, optimistic UI updates, client-side query caching
40 backend tests covering OAuth allow-list, sync idempotency, cascade deletes,
cursor pagination, and category filtering.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-16 18:44:30 +00:00
|
|
|
|
import { useMutation, useInfiniteQuery, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
|
|
|
|
import { Link } from 'react-router-dom'
|
2026-09-16 20:38:06 +00:00
|
|
|
|
import { getFeed, getSyncStatus, listCategories, listChannels, logout, syncVideos } from '../api/client'
|
Implement Phases 1-5: skeleton, OAuth, categories, video sync/feed, playback
- FastAPI + PostgreSQL + Alembic + React/Vite skeleton, Docker Compose, healthcheck
- Google OAuth (single allowed account), encrypted refresh token storage
- Subscriptions sync with pagination, uploads playlist batch fetch
- Categories CRUD, many-to-many channel assignment, category filtering
- Video sync (playlistItems + videos.list batching), cached feed with cursor
pagination, background scheduler (APScheduler)
- Video detail page with YouTube embed player
- SPA fallback routing, optimistic UI updates, client-side query caching
40 backend tests covering OAuth allow-list, sync idempotency, cascade deletes,
cursor pagination, and category filtering.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-16 18:44:30 +00:00
|
|
|
|
import CategoryNav, { type CategoryFilter } from '../components/CategoryNav'
|
|
|
|
|
|
import VideoCard from '../components/VideoCard'
|
|
|
|
|
|
import { useState } from 'react'
|
|
|
|
|
|
|
|
|
|
|
|
function Feed() {
|
|
|
|
|
|
const [filter, setFilter] = useState<CategoryFilter>('all')
|
|
|
|
|
|
const queryClient = useQueryClient()
|
|
|
|
|
|
|
|
|
|
|
|
const categoriesQuery = useQuery({ queryKey: ['categories'], queryFn: listCategories })
|
|
|
|
|
|
const categories = categoriesQuery.data ?? []
|
|
|
|
|
|
|
2026-09-16 20:38:06 +00:00
|
|
|
|
const allChannelsQuery = useQuery({
|
|
|
|
|
|
queryKey: ['channels', 'all-for-counts'],
|
|
|
|
|
|
queryFn: () => listChannels({ subscribed: true }),
|
|
|
|
|
|
})
|
|
|
|
|
|
const allChannels = allChannelsQuery.data ?? []
|
|
|
|
|
|
const uncategorizedCount = allChannels.filter((c) => c.category_ids.length === 0).length
|
|
|
|
|
|
|
Implement Phases 1-5: skeleton, OAuth, categories, video sync/feed, playback
- FastAPI + PostgreSQL + Alembic + React/Vite skeleton, Docker Compose, healthcheck
- Google OAuth (single allowed account), encrypted refresh token storage
- Subscriptions sync with pagination, uploads playlist batch fetch
- Categories CRUD, many-to-many channel assignment, category filtering
- Video sync (playlistItems + videos.list batching), cached feed with cursor
pagination, background scheduler (APScheduler)
- Video detail page with YouTube embed player
- SPA fallback routing, optimistic UI updates, client-side query caching
40 backend tests covering OAuth allow-list, sync idempotency, cascade deletes,
cursor pagination, and category filtering.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-16 18:44:30 +00:00
|
|
|
|
const feedQuery = useInfiniteQuery({
|
|
|
|
|
|
queryKey: ['feed', filter],
|
|
|
|
|
|
queryFn: ({ pageParam }) =>
|
|
|
|
|
|
getFeed({
|
|
|
|
|
|
categoryId: typeof filter === 'number' ? filter : undefined,
|
|
|
|
|
|
uncategorized: filter === 'uncategorized',
|
|
|
|
|
|
cursor: pageParam,
|
|
|
|
|
|
}),
|
|
|
|
|
|
initialPageParam: undefined as string | undefined,
|
|
|
|
|
|
getNextPageParam: (lastPage) => lastPage.next_cursor ?? undefined,
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const syncStatusQuery = useQuery({
|
|
|
|
|
|
queryKey: ['sync-status'],
|
|
|
|
|
|
queryFn: getSyncStatus,
|
|
|
|
|
|
refetchInterval: (query) => (query.state.data?.videos.running ? 1500 : false),
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const syncMutation = useMutation({
|
|
|
|
|
|
mutationFn: syncVideos,
|
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
|
queryClient.invalidateQueries({ queryKey: ['feed'] })
|
|
|
|
|
|
queryClient.invalidateQueries({ queryKey: ['sync-status'] })
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const logoutMutation = useMutation({
|
|
|
|
|
|
mutationFn: logout,
|
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
|
queryClient.invalidateQueries({ queryKey: ['auth-status'] })
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const running = syncStatusQuery.data?.videos.running
|
|
|
|
|
|
const items = feedQuery.data?.pages.flatMap((page) => page.items) ?? []
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="feed-screen">
|
|
|
|
|
|
<header>
|
|
|
|
|
|
<h1>Лента</h1>
|
|
|
|
|
|
<div className="actions">
|
2026-09-16 20:23:33 +00:00
|
|
|
|
<Link to="/saved">Сохранённые</Link>
|
Implement Phases 1-5: skeleton, OAuth, categories, video sync/feed, playback
- FastAPI + PostgreSQL + Alembic + React/Vite skeleton, Docker Compose, healthcheck
- Google OAuth (single allowed account), encrypted refresh token storage
- Subscriptions sync with pagination, uploads playlist batch fetch
- Categories CRUD, many-to-many channel assignment, category filtering
- Video sync (playlistItems + videos.list batching), cached feed with cursor
pagination, background scheduler (APScheduler)
- Video detail page with YouTube embed player
- SPA fallback routing, optimistic UI updates, client-side query caching
40 backend tests covering OAuth allow-list, sync idempotency, cascade deletes,
cursor pagination, and category filtering.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-16 18:44:30 +00:00
|
|
|
|
<Link to="/channels">Каналы</Link>
|
|
|
|
|
|
<Link to="/categories">Категории</Link>
|
|
|
|
|
|
<button onClick={() => syncMutation.mutate()} disabled={running}>
|
|
|
|
|
|
{running ? 'Синхронизация...' : 'Обновить сейчас'}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button onClick={() => logoutMutation.mutate()}>Выйти</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
{syncMutation.isError && <p className="error">{(syncMutation.error as Error).message}</p>}
|
|
|
|
|
|
{syncStatusQuery.data?.videos.status === 'failed' && (
|
|
|
|
|
|
<p className="error">Последняя синхронизация видео завершилась ошибкой: {syncStatusQuery.data.videos.error}</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<div className="layout">
|
2026-09-16 20:38:06 +00:00
|
|
|
|
<CategoryNav
|
|
|
|
|
|
categories={categories}
|
|
|
|
|
|
value={filter}
|
|
|
|
|
|
onChange={setFilter}
|
|
|
|
|
|
allCount={allChannels.length}
|
|
|
|
|
|
uncategorizedCount={uncategorizedCount}
|
|
|
|
|
|
/>
|
Implement Phases 1-5: skeleton, OAuth, categories, video sync/feed, playback
- FastAPI + PostgreSQL + Alembic + React/Vite skeleton, Docker Compose, healthcheck
- Google OAuth (single allowed account), encrypted refresh token storage
- Subscriptions sync with pagination, uploads playlist batch fetch
- Categories CRUD, many-to-many channel assignment, category filtering
- Video sync (playlistItems + videos.list batching), cached feed with cursor
pagination, background scheduler (APScheduler)
- Video detail page with YouTube embed player
- SPA fallback routing, optimistic UI updates, client-side query caching
40 backend tests covering OAuth allow-list, sync idempotency, cascade deletes,
cursor pagination, and category filtering.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-16 18:44:30 +00:00
|
|
|
|
|
|
|
|
|
|
<div className="content">
|
|
|
|
|
|
{feedQuery.isLoading && <p>Загрузка...</p>}
|
|
|
|
|
|
{feedQuery.isError && <p className="error">Не удалось загрузить ленту</p>}
|
|
|
|
|
|
|
|
|
|
|
|
<ul className="video-grid">
|
|
|
|
|
|
{items.map((video) => (
|
|
|
|
|
|
<VideoCard key={video.youtube_video_id} video={video} />
|
|
|
|
|
|
))}
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
{!feedQuery.isLoading && items.length === 0 && (
|
|
|
|
|
|
<p>Видео пока нет. Нажми "Обновить сейчас" или проверь, есть ли каналы в этой категории.</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{feedQuery.hasNextPage && (
|
|
|
|
|
|
<button
|
|
|
|
|
|
className="load-more"
|
|
|
|
|
|
onClick={() => feedQuery.fetchNextPage()}
|
|
|
|
|
|
disabled={feedQuery.isFetchingNextPage}
|
|
|
|
|
|
>
|
|
|
|
|
|
{feedQuery.isFetchingNextPage ? 'Загрузка...' : 'Показать ещё'}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default Feed
|