add vid_type_filter to home and playlist views

This commit is contained in:
Simon 2025-08-11 20:46:16 +07:00
parent d8e5ee7e04
commit 5804fc09e6
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
8 changed files with 37 additions and 38 deletions

View File

@ -5,7 +5,7 @@
from common.src.helper import get_stylesheets
from rest_framework import serializers
from user.models import Account
from video.src.constants import OrderEnum, SortEnum
from video.src.constants import OrderEnum, SortEnum, VideoTypeEnum
class AccountSerializer(serializers.ModelSerializer):
@ -37,6 +37,9 @@ class UserMeConfigSerializer(serializers.Serializer):
view_style_channel = serializers.ChoiceField(choices=["grid", "list"])
view_style_downloads = serializers.ChoiceField(choices=["grid", "list"])
view_style_playlist = serializers.ChoiceField(choices=["grid", "list"])
vid_type_filter = serializers.ChoiceField(
choices=VideoTypeEnum.values_known(), allow_null=True
)
grid_items = serializers.IntegerField(max_value=7, min_value=3)
hide_watched = serializers.BooleanField(allow_null=True)
file_size_unit = serializers.ChoiceField(choices=["binary", "metric"])

View File

@ -20,6 +20,7 @@ class UserConfigType(TypedDict, total=False):
view_style_channel: str
view_style_downloads: str
view_style_playlist: str
vid_type_filter: str | None
grid_items: int
hide_watched: bool | None
file_size_unit: str
@ -43,6 +44,7 @@ class UserConfig:
view_style_channel="list",
view_style_downloads="list",
view_style_playlist="grid",
vid_type_filter=None,
grid_items=3,
hide_watched=False,
file_size_unit="binary",

View File

@ -1,6 +1,6 @@
import { ViewStylesType } from '../../configuration/constants/ViewStyle';
import APIClient from '../../functions/APIClient';
import { SortByType, SortOrderType } from '../loader/loadVideoListByPage';
import { SortByType, SortOrderType, VideoTypes } from '../loader/loadVideoListByPage';
export type ColourVariants =
| 'dark.css'
@ -31,6 +31,7 @@ export type UserConfigType = {
view_style_channel: ViewStylesType;
view_style_downloads: ViewStylesType;
view_style_playlist: ViewStylesType;
vid_type_filter: VideoTypes | null;
grid_items: number;
hide_watched: boolean | null;
file_size_unit: 'binary' | 'metric';

View File

@ -13,15 +13,16 @@ import {
SortByType,
SortOrderEnum,
SortOrderType,
VideoTypes,
} from '../api/loader/loadVideoListByPage';
type FilterbarProps = {
hideToggleText: string;
viewStyle: ViewStyleNamesType;
showSort?: boolean;
showTypeFilter?: boolean;
};
const Filterbar = ({ hideToggleText, viewStyle, showSort = true }: FilterbarProps) => {
const Filterbar = ({ viewStyle, showSort = true, showTypeFilter = false }: FilterbarProps) => {
const { userConfig, setUserConfig } = useUserConfigStore();
const [showHidden, setShowHidden] = useState(false);
@ -29,8 +30,6 @@ const Filterbar = ({ hideToggleText, viewStyle, showSort = true }: FilterbarProp
const currentViewStyle = userConfig[viewStyle];
const isGridView = currentViewStyle === ViewStylesEnum.Grid;
console.log(hideToggleText);
useEffect(() => {
if (!showSort) {
return;
@ -67,30 +66,23 @@ const Filterbar = ({ hideToggleText, viewStyle, showSort = true }: FilterbarProp
<option value="true">Watched only</option>
<option value="false">Unwatched only</option>
</select>
</div>
{/* <div className="toggle">
<span>{hideToggleText}</span>
<div className="toggleBox">
<input
id="hide_watched"
type="checkbox"
checked={userConfig.hide_watched}
onChange={() => {
handleUserConfigUpdate({ hide_watched: !userConfig.hide_watched });
{showTypeFilter && (
<select
value={userConfig.vid_type_filter === null ? '' : userConfig.vid_type_filter}
onChange={event => {
handleUserConfigUpdate({
vid_type_filter:
event.target.value === '' ? null : (event.target.value as VideoTypes),
});
}}
/>
{userConfig.hide_watched ? (
<label htmlFor="" className="onbtn">
On
</label>
) : (
<label htmlFor="" className="ofbtn">
Off
</label>
)}
</div>
</div> */}
>
<option value="">All Types</option>
<option value="videos">Videos</option>
<option value="streams">Streams</option>
<option value="shorts">Shorts</option>
</select>
)}
</div>
{showHidden && (
<div className="sort">

View File

@ -163,10 +163,7 @@ const ChannelVideo = ({ videoType }: ChannelVideoProps) => {
</div>
<div className={`boxed-content ${gridView}`}>
<Filterbar
hideToggleText={'Hide watched videos:'}
viewStyle={ViewStyleNames.Home as ViewStyleNamesType}
/>
<Filterbar viewStyle={ViewStyleNames.Home as ViewStyleNamesType} />
</div>
<EmbeddableVideoPlayer videoId={videoId} />

View File

@ -4,6 +4,7 @@ import Routes from '../configuration/routes/RouteList';
import Pagination from '../components/Pagination';
import loadVideoListByFilter, {
VideoListByFilterResponseType,
VideoTypes,
WatchTypes,
WatchTypesEnum,
} from '../api/loader/loadVideoListByPage';
@ -141,6 +142,7 @@ const Home = () => {
: ((userConfig.hide_watched
? WatchTypesEnum.Watched
: WatchTypesEnum.Unwatched) as WatchTypes),
type: userConfig.vid_type_filter as VideoTypes,
sort: userConfig.sort_by,
order: userConfig.sort_order,
});
@ -162,6 +164,7 @@ const Home = () => {
userConfig.sort_by,
userConfig.sort_order,
userConfig.hide_watched,
userConfig.vid_type_filter,
currentPage,
pagination?.current_page,
videoId,
@ -194,10 +197,7 @@ const Home = () => {
<h1>Recent Videos</h1>
</div>
<Filterbar
hideToggleText="Show unwatched only:"
viewStyle={ViewStyleNames.Home as ViewStyleNamesType}
/>
<Filterbar viewStyle={ViewStyleNames.Home as ViewStyleNamesType} showTypeFilter={true} />
</div>
<div className={`boxed-content ${gridView}`}>

View File

@ -24,6 +24,7 @@ import ScrollToTopOnNavigate from '../components/ScrollToTop';
import EmbeddableVideoPlayer from '../components/EmbeddableVideoPlayer';
import Button from '../components/Button';
import loadVideoListByFilter, {
VideoTypes,
WatchTypes,
WatchTypesEnum,
} from '../api/loader/loadVideoListByPage';
@ -88,6 +89,7 @@ const Playlist = () => {
: ((userConfig.hide_watched
? WatchTypesEnum.Watched
: WatchTypesEnum.Unwatched) as WatchTypes),
type: userConfig.vid_type_filter as VideoTypes,
});
setPlaylistResponse(playlist);
@ -106,6 +108,7 @@ const Playlist = () => {
}, [
playlistId,
userConfig.hide_watched,
userConfig.vid_type_filter,
refresh,
currentPage,
pagination?.current_page,
@ -343,9 +346,9 @@ const Playlist = () => {
<div className={`boxed-content ${gridView}`}>
<Filterbar
hideToggleText="Hide watched videos:"
viewStyle={ViewStyleNames.Home as ViewStyleNamesType} // its a list of videos, so ViewStyleNames.Home
showSort={false}
showTypeFilter={true}
/>
</div>

View File

@ -18,6 +18,7 @@ export const useUserConfigStore = create<UserConfigState>(set => ({
view_style_channel: ViewStylesEnum.List as ViewStylesType,
view_style_downloads: ViewStylesEnum.List as ViewStylesType,
view_style_playlist: ViewStylesEnum.Grid as ViewStylesType,
vid_type_filter: null,
grid_items: 3,
hide_watched: false,
file_size_unit: 'binary',