Add option to disable sources of an extension

This commit is contained in:
schroda
2025-06-23 01:51:14 +02:00
parent ecfde354b8
commit f3c479fe32
7 changed files with 72 additions and 35 deletions

View File

@@ -27,6 +27,7 @@ export type SavedSourceSearch = { query?: string; filters?: IPos[] };
export interface ISourceMetadata {
savedSearches?: Record<string, SavedSourceSearch>;
isPinned: boolean;
isEnabled: boolean;
}
export type SourceFilters = GetSourceBrowseQuery['source']['filters'][number];

View File

@@ -48,7 +48,13 @@ export function Sources({ tabsMenuHeight }: { tabsMenuHeight: number }) {
} = requestManager.useGetSourceList({ notifyOnNetworkStatusChange: true });
const sources = data?.sources.nodes;
const filteredSources = useMemo(
() => SourceService.filter(sources ?? [], { showNsfw, languages: shownLangs, keepLocalSource: true }),
() =>
SourceService.filter(sources ?? [], {
showNsfw,
languages: shownLangs,
keepLocalSource: true,
enabled: true,
}),
[sources, shownLangs],
);
const sourcesByLanguage = useMemo(() => {

View File

@@ -23,6 +23,7 @@ import {
const DEFAULT_SOURCE_METADATA: ISourceMetadata = {
savedSearches: undefined,
isPinned: false,
isEnabled: true,
};
const convertAppMetadataToGqlMetadata = (

View File

@@ -81,7 +81,14 @@ export class Sources {
languages,
keepLocalSource,
pinned,
}: { showNsfw?: boolean; languages?: string[]; keepLocalSource?: boolean; pinned?: boolean } = {},
enabled,
}: {
showNsfw?: boolean;
languages?: string[];
keepLocalSource?: boolean;
pinned?: boolean;
enabled?: boolean;
} = {},
): Source[] {
const normalizedLanguages = toComparableLanguages(toUniqueLanguageCodes(languages ?? []));
@@ -105,6 +112,13 @@ export class Sources {
!pinned ||
getSourceMetadata(source).isPinned ||
(keepLocalSource && Sources.isLocalSource(source)),
)
.filter(
(source) =>
enabled === undefined ||
!enabled ||
getSourceMetadata(source).isEnabled ||
(keepLocalSource && Sources.isLocalSource(source)),
);
}