mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-07 06:39:52 +02:00
96 lines
2.1 KiB
TypeScript
96 lines
2.1 KiB
TypeScript
import type {
|
|
LauncherScaleInfo,
|
|
LauncherViewConfig
|
|
} from "@server/routers/launcher/types";
|
|
|
|
export function hasActiveLauncherFilters(config: LauncherViewConfig): boolean {
|
|
return (
|
|
config.query.trim().length > 0 ||
|
|
config.siteIds.length > 0 ||
|
|
config.labelIds.length > 0
|
|
);
|
|
}
|
|
|
|
export function getEffectiveGroupBy(
|
|
scale: LauncherScaleInfo,
|
|
config: LauncherViewConfig
|
|
): LauncherViewConfig["groupBy"] {
|
|
if (scale.mode === "compact") {
|
|
return "none";
|
|
}
|
|
|
|
return config.groupBy;
|
|
}
|
|
|
|
export function getEffectiveLauncherConfig(
|
|
scale: LauncherScaleInfo,
|
|
config: LauncherViewConfig
|
|
): LauncherViewConfig {
|
|
const groupBy = getEffectiveGroupBy(scale, config);
|
|
if (groupBy === config.groupBy) {
|
|
return config;
|
|
}
|
|
|
|
return { ...config, groupBy };
|
|
}
|
|
|
|
export function shouldFetchLauncherGroups(
|
|
scale: LauncherScaleInfo,
|
|
config: LauncherViewConfig
|
|
): boolean {
|
|
const groupBy = getEffectiveGroupBy(scale, config);
|
|
|
|
if (groupBy === "none") {
|
|
return false;
|
|
}
|
|
|
|
if (scale.mode === "full") {
|
|
return true;
|
|
}
|
|
|
|
return (
|
|
scale.capabilities.allowSiteGrouping &&
|
|
groupBy === "site" &&
|
|
config.siteIds.length > 0
|
|
);
|
|
}
|
|
|
|
export function shouldShowLauncherGroupList(
|
|
scale: LauncherScaleInfo,
|
|
config: LauncherViewConfig
|
|
): boolean {
|
|
return shouldFetchLauncherGroups(scale, config);
|
|
}
|
|
|
|
export function shouldShowSearchFirstGate(
|
|
scale: LauncherScaleInfo,
|
|
config: LauncherViewConfig
|
|
): boolean {
|
|
return (
|
|
scale.mode === "compact" &&
|
|
scale.capabilities.requireSearchOrFilter &&
|
|
!hasActiveLauncherFilters(config)
|
|
);
|
|
}
|
|
|
|
export function shouldShowFlatResourceList(
|
|
scale: LauncherScaleInfo,
|
|
config: LauncherViewConfig
|
|
): boolean {
|
|
if (shouldShowSearchFirstGate(scale, config)) {
|
|
return false;
|
|
}
|
|
|
|
const groupBy = getEffectiveGroupBy(scale, config);
|
|
|
|
if (groupBy === "none") {
|
|
return true;
|
|
}
|
|
|
|
if (scale.mode === "full") {
|
|
return false;
|
|
}
|
|
|
|
return !shouldShowLauncherGroupList(scale, config);
|
|
}
|