aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/src/constants/AppDiscoverTypes.ts
blob: bc2736eac9f598aace4d10df2cf7842fff2802cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

/**
 * Currently known types of app discover section elements
 */
export const APP_DISCOVER_KNOWN_TYPES = ['post', 'showcase', 'carousel'] as const

/**
 * Helper for localized values
 */
export type ILocalizedValue<T> = Record<string, T | undefined> & { en: T }

export interface IAppDiscoverElement {
	/**
	 * Type of the element
	 */
	type: typeof APP_DISCOVER_KNOWN_TYPES[number]

	/**
	 * Identifier for this element
	 */
	id: string,

	/**
	 * Order of this element to pin elements (smaller = shown on top)
	 */
	order?: number

	/**
	 * Optional, localized, headline for the element
	 */
	headline?: ILocalizedValue<string>

	/**
	 * Optional link target for the element
	 */
	link?: string

	/**
	 * Optional date when this element will get valid (only show since then)
	 */
	date?: number

	/**
	 * Optional date when this element will be invalid (only show until then)
	 */
	expiryDate?: number
}

/** Wrapper for media source and MIME type */
type MediaSource = { src: string, mime: string }

/**
 * Media content type for posts
 */
interface IAppDiscoverMediaContent {
	/**
	 * The media source to show - either one or a list of sources with their MIME type for fallback options
	 */
	src: MediaSource | MediaSource[]

	/**
	 * Alternative text for the media
	 */
	alt: string

	/**
	 * Optional link target for the media (e.g. to the full video)
	 */
	link?: string
}

/**
 * Wrapper for post media
 */
interface IAppDiscoverMedia {
	/**
	 * The alignment of the media element
	 */
	alignment?: 'start' | 'end' | 'center'

	/**
	 * The (localized) content
	 */
	content: ILocalizedValue<IAppDiscoverMediaContent>
}

/**
 * An app element only used for the showcase type
 */
export interface IAppDiscoverApp {
	/** The App ID */
	type: 'app'
	appId: string
}

export interface IAppDiscoverPost extends IAppDiscoverElement {
	type: 'post'
	text?: ILocalizedValue<string>
	media?: IAppDiscoverMedia
}

export interface IAppDiscoverShowcase extends IAppDiscoverElement {
	type: 'showcase'
	content: (IAppDiscoverPost | IAppDiscoverApp)[]
}

export interface IAppDiscoverCarousel extends IAppDiscoverElement {
	type: 'carousel'
	text?: ILocalizedValue<string>
	content: IAppDiscoverPost[]
}

export type IAppDiscoverElements = IAppDiscoverPost | IAppDiscoverCarousel | IAppDiscoverShowcase