/** * External dependencies */ import type { AuthorId, AutoShareEndModeId, AutomationSources, EditingPost, ImageId, Maybe, MetaKey, PostId, PostStatusSlug, RegularQueryArg, Series, SocialNetworkName, TaxonomySlug, Term, Url, } from '@nelio-content/types'; export type PostAction = | SetCustomField | RemoveCustomField | SetPost | SetPostId | SetTitle | SetExcerpt | SetContent | SetDate | SetAuthor | SetPermalink | SetFollowers | SetFeaturedImage | RemoveFeaturedImage | SetStatus | SetSeries | SetTerms | EnableAutoShare | SetAutoShareEndMode | SetAutomationSources | SetQueryArgs | SetNetworkImage | MarkAsLoadingPostItems; export function setCustomField( key: MetaKey, value: string ): SetCustomField { return { type: 'SET_CUSTOM_FIELD', key, value, }; } export function removeCustomField( key: MetaKey ): RemoveCustomField { return { type: 'REMOVE_CUSTOM_FIELD', key, }; } export function setPost( post: EditingPost ): SetPost { return { type: 'SET_POST', post, }; } export function setPostId( id: PostId ): SetPostId { return { type: 'SET_POST_ID', id, }; } export function setTitle( title: string ): SetTitle { return { type: 'SET_TITLE', title, }; } export function setExcerpt( excerpt: string ): SetExcerpt { return { type: 'SET_EXCERPT', excerpt, }; } export function setContent( content: string ): SetContent { return { type: 'SET_CONTENT', content, }; } export function setDate( date: Maybe< string > ): SetDate { return { type: 'SET_DATE', date, }; } export function setAuthor( authorId: AuthorId, authorName: string ): SetAuthor { return { type: 'SET_AUTHOR', authorId, authorName, }; } export function setPermalink( permalink: Url ): SetPermalink { return { type: 'SET_PERMALINK', permalink, }; } export function setFollowers( followerIds: ReadonlyArray< AuthorId > ): SetFollowers { return { type: 'SET_FOLLOWERS', followers: followerIds, }; } export function setFeaturedImage( imageId: ImageId | 0, imageSrc: Url | false, imageAltText: string | undefined ): SetFeaturedImage { return { type: 'SET_FEATURED_IMAGE', imageId, imageSrc: imageSrc || false, thumbnailSrc: imageSrc || false, imageAltText, }; } export function removeFeaturedImage(): RemoveFeaturedImage { return { type: 'REMOVE_FEATURED_IMAGE', }; } export function setStatus( status: PostStatusSlug ): SetStatus { return { type: 'SET_STATUS', status, }; } export function setTerms( taxonomy: TaxonomySlug, terms: ReadonlyArray< Term > ): SetTerms { return { type: 'SET_TERMS', taxonomy, terms, }; } export function enableAutoShare( isAutoShareEnabled: boolean ): EnableAutoShare { return { type: 'ENABLE_AUTO_SHARE', isAutoShareEnabled, }; } export function setAutoShareEndMode( autoShareEndMode: AutoShareEndModeId ): SetAutoShareEndMode { return { type: 'SET_AUTO_SHARE_END_MODE', autoShareEndMode, }; } export function setAutomationSources( sources: Partial< AutomationSources > ): SetAutomationSources { return { type: 'SET_AUTOMATION_SOURCES', sources, }; } export function setQueryArgs( args: ReadonlyArray< RegularQueryArg > ): SetQueryArgs { return { type: 'SET_QUERY_ARGS', args, }; } export function setNetworkImage( network: SocialNetworkName, imageId?: ImageId, imageUrl?: Url, imageAltText?: string ): SetNetworkImage { return { type: 'SET_NETWORK_IMAGE', network, imageId, imageUrl, imageAltText, }; } export function setSeries( series: ReadonlyArray< Series > ): SetSeries { return { type: 'SET_SERIES', series, }; } export function markAsLoadingPostItems( isLoading: boolean ): MarkAsLoadingPostItems { return { type: 'MARK_AS_LOADING_POST_ITEMS', isLoading, }; } // ============ // HELPER TYPES // ============ type SetCustomField = { readonly type: 'SET_CUSTOM_FIELD'; readonly key: MetaKey; readonly value: string; }; type RemoveCustomField = { readonly type: 'REMOVE_CUSTOM_FIELD'; readonly key: MetaKey; }; export type SetPost = { readonly type: 'SET_POST'; readonly post: EditingPost; }; type SetPostId = { readonly type: 'SET_POST_ID'; readonly id: PostId; }; type SetTitle = { readonly type: 'SET_TITLE'; readonly title: string; }; type SetExcerpt = { readonly type: 'SET_EXCERPT'; readonly excerpt: string; }; export type SetContent = { readonly type: 'SET_CONTENT'; readonly content: string; }; type SetDate = { readonly type: 'SET_DATE'; readonly date: Maybe< string >; }; type SetAuthor = { readonly type: 'SET_AUTHOR'; readonly authorId: AuthorId; readonly authorName: string; }; type SetPermalink = { readonly type: 'SET_PERMALINK'; readonly permalink: Url; }; type SetFollowers = { readonly type: 'SET_FOLLOWERS'; readonly followers: ReadonlyArray< AuthorId >; }; type SetFeaturedImage = { readonly type: 'SET_FEATURED_IMAGE'; readonly imageId: ImageId | 0; readonly imageSrc: Url | false; readonly thumbnailSrc: Url | false; readonly imageAltText: string | undefined; }; type RemoveFeaturedImage = { readonly type: 'REMOVE_FEATURED_IMAGE'; }; type SetStatus = { readonly type: 'SET_STATUS'; readonly status: PostStatusSlug; }; type SetTerms = { readonly type: 'SET_TERMS'; readonly taxonomy: TaxonomySlug; readonly terms: ReadonlyArray< Term >; }; type EnableAutoShare = { readonly type: 'ENABLE_AUTO_SHARE'; readonly isAutoShareEnabled: boolean; }; type SetAutoShareEndMode = { readonly type: 'SET_AUTO_SHARE_END_MODE'; readonly autoShareEndMode: AutoShareEndModeId; }; type SetAutomationSources = { readonly type: 'SET_AUTOMATION_SOURCES'; readonly sources: Partial< AutomationSources >; }; type SetQueryArgs = { readonly type: 'SET_QUERY_ARGS'; readonly args: ReadonlyArray< RegularQueryArg >; }; type SetSeries = { readonly type: 'SET_SERIES'; readonly series: ReadonlyArray< Series >; }; type SetNetworkImage = { readonly type: 'SET_NETWORK_IMAGE'; readonly network: SocialNetworkName; readonly imageId?: ImageId; readonly imageUrl?: Url; readonly imageAltText?: string; }; export type MarkAsLoadingPostItems = { readonly type: 'MARK_AS_LOADING_POST_ITEMS'; readonly isLoading: boolean; };