Skip to content

Commit

Permalink
hiding long streams!
Browse files Browse the repository at this point in the history
  • Loading branch information
sphinxrave committed Oct 18, 2024
1 parent 4816e1a commit 0053aa0
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
33 changes: 33 additions & 0 deletions packages/react/src/hooks/useVideoFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ function filterDeadStreams(video: VideoBase, now: dayjs.Dayjs) {
);
}

function filterLongVideos(video: VideoBase) {
return video.duration <= 24 * 60 * 60; // 24 hours in seconds
}

type PageContext = "org" | "favorites" | "search" | "watch" | "channel";

export function useVideoFilter(
Expand All @@ -22,6 +26,7 @@ export function useVideoFilter(
overrides?: Partial<{
hideCollabStreams: boolean;
filterDeadStreams: boolean;
filterLongVideos: boolean;
ignoredTopics: string[];
}>,
) {
Expand All @@ -47,6 +52,8 @@ export function useVideoFilter(
const shouldFilterDeadStreams =
type === "stream_schedule" &&
(overrides?.filterDeadStreams ?? settings.filterDeadStreams);
const shouldFilterLongVideos =
overrides?.filterLongVideos ?? settings.filterLongStreams;
const now = shouldFilterDeadStreams ? dayjs() : null;

const filteredVideos = videos.filter((video) => {
Expand Down Expand Up @@ -79,12 +86,38 @@ export function useVideoFilter(
keep = keep && filterDeadStreams(video, now);
}

// Filter long videos
if (shouldFilterLongVideos) {
keep = keep && filterLongVideos(video);
}

// Filter ignored topics
const ignoredTopics = overrides?.ignoredTopics ?? settings.ignoredTopics;
if (ignoredTopics.length > 0) {
keep = keep && !ignoredTopics.includes(video.topic_id ?? "_N_A");
}

// filter clips whose channels and uploaders are all irrelevant to current context
const videoMentions = (video as Partial<Video>).mentions;
if ("clip" === type && videoMentions) {
keep =
keep && // don't keep if every video is invalid
![...videoMentions, video.channel].every((mention) => {
// thunk => true if video invalid for page context:
const mentionBlocked = blockedSet.has(mention.id); // it has to be blocked
switch (pageContext) {
case "org":
return mentionBlocked || mention.org !== defaultOrg; // and it has to be relevant to the org
case "favorites":
return mentionBlocked || !favoritesSet.has(mention.id); // or not your favorites list.
case "channel":
case "watch":
case "search":
return !mentionBlocked; // or just be blocked.
}
});
}

return keep;
});

Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/locales/en/ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ views:
hideFeaturesLabel: Hide Features
showTimezonesOnHover: Show Timezones on hover
orgs: Starred Orgs
filterDeadStreams: Hide Streams that don't go live for >2 hours
filterLongStreams: Hide Streams that are live for longer than 24 hours
app:
update_available: An update is available
update_btn: Update
Expand Down
19 changes: 19 additions & 0 deletions packages/react/src/routes/settings/homepage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Checkbox } from "@/shadcn/ui/checkbox";
import { Label } from "@/shadcn/ui/label";
import {
defaultOpenAtom,
filterDeadStreamsAtom,
filterLongStreamsAtom,
hideCollabStreamsAtom,
hidePlaceholderAtom,
hideThumbnailAtom,
Expand All @@ -24,6 +26,13 @@ export function SettingsHomepage() {
const [hideCollab, setHideCollab] = useAtom(hideCollabStreamsAtom);
const [hidePlaceholder, setHidePlaceholder] = useAtom(hidePlaceholderAtom);

const [filterDeadStreams, setFilterDeadStreams] = useAtom(
filterDeadStreamsAtom,
);
const [filterLongStreams, setFilterLongStreams] = useAtom(
filterLongStreamsAtom,
);

const defaultPages = [
{
value: "Home",
Expand Down Expand Up @@ -71,6 +80,16 @@ export function SettingsHomepage() {
value: hidePlaceholder,
onChange: () => setHidePlaceholder(!hidePlaceholder),
},
{
label: t("views.settings.filterDeadStreams"),
value: filterDeadStreams,
onChange: () => setFilterDeadStreams(!filterDeadStreams),
},
{
label: t("views.settings.filterLongStreams"),
value: filterLongStreams,
onChange: () => setFilterLongStreams(!filterLongStreams),
},
] as const;

return (
Expand Down
14 changes: 14 additions & 0 deletions packages/react/src/store/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface HolodexSettings {
gridDensity: number;
defaultOpen: "Favorites" | "Home";
hideCollabStreams: boolean;
filterLongStreams: boolean; // New setting
filterDeadStreams: boolean;
ignoredTopics: string[];
blockedChannels: ShortChannel[];
Expand All @@ -24,11 +25,14 @@ export const settingsAtom = atomWithStorage<HolodexSettings>(
englishName: false,
clipLanguage: [],
redirectMode: false,
// homepage settings
hideThumbnail: false,
hidePlaceholder: false,
// homepage settings
gridDensity: 0,
defaultOpen: "Home",
hideCollabStreams: false,
filterLongStreams: true, // homepage settings
filterDeadStreams: true,
ignoredTopics: [],
blockedChannels: [],
Expand Down Expand Up @@ -126,6 +130,16 @@ export const filterDeadStreamsAtom = atom(
},
);

export const filterLongStreamsAtom = atom(
(get) => get(settingsAtom).filterLongStreams,
(get, set, newValue: boolean) => {
set(settingsAtom, {
...get(settingsAtom),
filterLongVideos: newValue,
});
},
);

export const ignoredTopicsAtom = atom(
(get) => get(settingsAtom).ignoredTopics,
(get, set, newValue: string[]) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/types/channel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ interface ChannelBase {
english_name?: string;
type: ChannelType;
photo?: string;
org?: string;
suborg?: string;
}

interface Channel extends ChannelBase {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/types/video.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ interface Video extends VideoBase {
sources?: Clip[];
refers?: Clip[];
simulcasts?: Clip[];
mentions?: ChannelBase[];
mentions?: ShortChannel[];
comments?: CommentBase[];
recommendations?: VideoBase[];
live_tl_count?: {
Expand Down

0 comments on commit 0053aa0

Please sign in to comment.