mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
* refactored common code in recommendation row * Implement front page options in config * Allow customisation from front page * Rename recommendations to front page * Add generic UI settings * Support adding premade filters Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
33 lines
832 B
TypeScript
33 lines
832 B
TypeScript
export const filterData = <T>(data?: (T | null | undefined)[] | null) =>
|
|
data ? (data.filter((item) => item) as T[]) : [];
|
|
|
|
export interface ITypename {
|
|
__typename?: string;
|
|
}
|
|
|
|
const hasTypename = (value: unknown): value is ITypename =>
|
|
!!(value as ITypename)?.__typename;
|
|
|
|
const processNoneObjValue = (value: unknown): unknown =>
|
|
Array.isArray(value)
|
|
? value.map((v) =>
|
|
hasTypename(v) ? withoutTypename(v) : processNoneObjValue(v)
|
|
)
|
|
: value;
|
|
|
|
export function withoutTypename<T extends ITypename>(
|
|
o: T
|
|
): Omit<T, "__typename"> {
|
|
const { __typename, ...data } = o;
|
|
|
|
return Object.entries(data).reduce(
|
|
(ret, [key, value]) => ({
|
|
...ret,
|
|
[key]: hasTypename(value)
|
|
? withoutTypename(value)
|
|
: processNoneObjValue(value),
|
|
}),
|
|
{} as Omit<T, "__typename">
|
|
);
|
|
}
|