diondiondion 072c30681e [Glitch] Split collection editor into dedicated routes
Port 8ebe2e673e2fd175140df7275eb362c8eecfec31 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2026-02-04 19:34:34 +01:00

42 lines
1.1 KiB
TypeScript

import type {
ApiCollectionJSON,
ApiCreateCollectionPayload,
} from '@/flavours/glitch/api_types/collections';
/**
* Temporary editor state across creation steps,
* kept in location state
*/
export type TempCollectionState =
| Partial<ApiCreateCollectionPayload>
| undefined;
/**
* Resolve initial editor state. Temporary location state
* trumps stored data, otherwise initial values are returned.
*/
export function getInitialState(
collection: ApiCollectionJSON | null | undefined,
locationState: TempCollectionState,
) {
const {
id,
name = '',
description = '',
tag,
language = '',
discoverable = true,
sensitive = false,
} = collection ?? {};
return {
id,
initialName: locationState?.name ?? name,
initialDescription: locationState?.description ?? description,
initialTopic: locationState?.tag_name ?? tag?.name ?? '',
initialLanguage: locationState?.language ?? language,
initialDiscoverable: locationState?.discoverable ?? discoverable,
initialSensitive: locationState?.sensitive ?? sensitive,
};
}