@@ -16,6 +16,7 @@ import { pickAndUploadMedia } from "@/shared/api/tauri";
1616import { rewriteRelayUrl } from "@/shared/lib/mediaUrl" ;
1717import { Button } from "@/shared/ui/button" ;
1818import { Input } from "@/shared/ui/input" ;
19+ import { SettingsOptionGroup } from "@/features/settings/ui/SettingsOptionGroup" ;
1920
2021/**
2122 * Custom emoji management (NIP-30, kind:30030). Each member owns their own set:
@@ -122,198 +123,211 @@ export function CustomEmojiSettingsCard() {
122123 const othersEmoji = workspace . filter ( ( e ) => ! ownShortcodes . has ( e . shortcode ) ) ;
123124
124125 return (
125- < section className = "min-w-0 space-y-6 " data-testid = "settings-custom-emoji" >
126- < div className = "space-y-1" >
127- < h2 className = "text-sm font-semibold tracking-tight" > Custom Emoji</ h2 >
128- < p className = "text-sm text-muted-foreground" >
126+ < section className = "min-w-0" data-testid = "settings-custom-emoji" >
127+ < div className = "mb-12 space-y-1" >
128+ < h2 className = "text-2xl font-semibold tracking-tight" > Custom Emoji</ h2 >
129+ < p className = "text-base font-normal text-muted-foreground" >
129130 Add your own custom emoji for everyone on this relay to use. Type{ " " }
130131 < code > :name:</ code > in messages and reactions.
131132 </ p >
132133 </ div >
133134
134- < form
135- className = "max-w-2xl space-y-4"
136- onSubmit = { ( event ) => {
137- event . preventDefault ( ) ;
138- if ( canSubmit ) void handleAdd ( ) ;
139- } }
140- >
141- < div className = "space-y-3" >
142- < div >
143- < h4 className = "text-sm font-semibold" > 1. Upload an image</ h4 >
144- < p className = "text-sm text-muted-foreground" >
145- Square images work best. GIF, PNG, JPEG, and WebP files are
146- supported.
147- </ p >
148- </ div >
149- < div className = "flex flex-wrap items-center gap-4" >
150- < div className = "flex h-16 w-16 shrink-0 items-center justify-center rounded-md border bg-background" >
151- { pendingUpload ? (
152- < img
153- alt = "Selected custom emoji preview"
154- src = { rewriteRelayUrl ( pendingUpload . url ) }
155- className = "h-14 w-14 object-contain"
156- draggable = { false }
157- />
158- ) : (
159- < ImagePlus className = "h-6 w-6 text-muted-foreground" />
160- ) }
135+ < div className = "space-y-6" >
136+ < form
137+ className = "w-full"
138+ onSubmit = { ( event ) => {
139+ event . preventDefault ( ) ;
140+ if ( canSubmit ) void handleAdd ( ) ;
141+ } }
142+ >
143+ < SettingsOptionGroup >
144+ < div className = "flex flex-col gap-3 px-4 py-3 text-sm sm:flex-row sm:items-center sm:justify-between" >
145+ < div className = "min-w-0" >
146+ < h4 className = "text-sm font-medium" > Upload an image</ h4 >
147+ < p className = "text-sm font-normal text-muted-foreground" >
148+ Square images work best. GIF, PNG, JPEG, and WebP files are
149+ supported.
150+ </ p >
151+ </ div >
152+ < div className = "flex min-w-0 items-center gap-3" >
153+ < div className = "flex h-16 w-16 shrink-0 items-center justify-center rounded-md border bg-background" >
154+ { pendingUpload ? (
155+ < img
156+ alt = "Selected custom emoji preview"
157+ src = { rewriteRelayUrl ( pendingUpload . url ) }
158+ className = "h-14 w-14 object-contain"
159+ draggable = { false }
160+ />
161+ ) : (
162+ < ImagePlus className = "h-6 w-6 text-muted-foreground" />
163+ ) }
164+ </ div >
165+ < div className = "min-w-0 space-y-2" >
166+ < p className = "max-w-48 truncate text-sm font-normal text-muted-foreground" >
167+ { pendingUpload ?. filename ?? "No image selected" }
168+ </ p >
169+ < Button
170+ type = "button"
171+ data-testid = "custom-emoji-upload"
172+ onClick = { ( ) => void handleUpload ( ) }
173+ disabled = { isUploading || setEmoji . isPending }
174+ variant = "outline"
175+ >
176+ { isUploading
177+ ? "Uploading…"
178+ : pendingUpload
179+ ? "Choose different image"
180+ : "Upload image" }
181+ </ Button >
182+ </ div >
183+ </ div >
184+ </ div >
185+
186+ < div className = "flex flex-col gap-3 px-4 py-3 text-sm sm:flex-row sm:items-start sm:justify-between" >
187+ < div className = "min-w-0" >
188+ < h4 className = "text-sm font-medium" > Give it a name</ h4 >
189+ < p className = "text-sm font-normal text-muted-foreground" >
190+ This is what you’ll type to add this emoji to messages and
191+ reactions.
192+ </ p >
193+ </ div >
194+ < div className = "w-full min-w-0 max-w-sm space-y-2" >
195+ < div className = "relative" >
196+ < span className = "absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground" >
197+ :
198+ </ span >
199+ < Input
200+ id = "custom-emoji-name"
201+ data-testid = "custom-emoji-name-input"
202+ autoCapitalize = "none"
203+ autoCorrect = "off"
204+ className = "px-6"
205+ placeholder = "party-parrot"
206+ spellCheck = { false }
207+ value = { name }
208+ onChange = { ( event ) => setName ( event . target . value ) }
209+ />
210+ < span className = "absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground" >
211+ :
212+ </ span >
213+ </ div >
214+ { nameInvalid ? (
215+ < p className = "text-sm text-destructive" >
216+ Use only letters, numbers, hyphen, or underscore.
217+ </ p >
218+ ) : pendingUpload === null ? (
219+ < p className = "text-sm font-normal text-muted-foreground" >
220+ Choose an image first; Sprout will suggest a name from the
221+ filename.
222+ </ p >
223+ ) : ownDuplicate ? (
224+ < p className = "text-sm font-normal text-muted-foreground" >
225+ You already have :{ normalized } : — saving will replace its
226+ image.
227+ </ p >
228+ ) : null }
229+ </ div >
161230 </ div >
162- < div className = "min-w-0 flex-1 space-y-2" >
163- < p className = "truncate text-sm text-muted-foreground" >
164- { pendingUpload ?. filename ?? "No image selected" }
165- </ p >
231+
232+ < div className = "flex justify-end gap-2 px-4 py-3" >
166233 < Button
167234 type = "button"
168- data-testid = "custom-emoji-upload"
169- onClick = { ( ) => void handleUpload ( ) }
170- disabled = { isUploading || setEmoji . isPending }
171235 variant = "outline"
236+ onClick = { handleReset }
237+ disabled = {
238+ setEmoji . isPending || ( name . length === 0 && ! pendingUpload )
239+ }
240+ >
241+ Clear
242+ </ Button >
243+ < Button
244+ type = "submit"
245+ data-testid = "custom-emoji-add"
246+ disabled = { ! canSubmit }
172247 >
173- { isUploading
174- ? "Uploading…"
175- : pendingUpload
176- ? "Choose different image"
177- : "Upload image" }
248+ { setEmoji . isPending ? "Saving…" : "Save emoji" }
178249 </ Button >
179250 </ div >
180- </ div >
181- </ div >
251+ </ SettingsOptionGroup >
252+ </ form >
182253
183- < div className = "space-y-3 border-t pt-4" >
184- < div >
185- < h4 className = "text-sm font-semibold" > 2. Give it a name</ h4 >
186- < p className = "text-sm text-muted-foreground" >
187- This is what you’ll type to add this emoji to messages and
188- reactions.
189- </ p >
190- </ div >
191- < div className = "relative" >
192- < span className = "absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground" >
193- :
194- </ span >
195- < Input
196- id = "custom-emoji-name"
197- data-testid = "custom-emoji-name-input"
198- autoCapitalize = "none"
199- autoCorrect = "off"
200- className = "px-6"
201- placeholder = "party-parrot"
202- spellCheck = { false }
203- value = { name }
204- onChange = { ( event ) => setName ( event . target . value ) }
205- />
206- < span className = "absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground" >
207- :
208- </ span >
209- </ div >
210- { nameInvalid ? (
211- < p className = "text-sm text-destructive" >
212- Use only letters, numbers, hyphen, or underscore.
213- </ p >
214- ) : pendingUpload === null ? (
215- < p className = "text-sm text-muted-foreground" >
216- Choose an image first; Sprout will suggest a name from the
217- filename.
218- </ p >
219- ) : ownDuplicate ? (
220- < p className = "text-sm text-muted-foreground" >
221- You already have :{ normalized } : — saving will replace its image.
222- </ p >
223- ) : null }
224- </ div >
225-
226- < div className = "flex justify-end gap-2 border-t pt-4" >
227- < Button
228- type = "button"
229- variant = "outline"
230- onClick = { handleReset }
231- disabled = {
232- setEmoji . isPending || ( name . length === 0 && ! pendingUpload )
233- }
234- >
235- Clear
236- </ Button >
237- < Button
238- type = "submit"
239- data-testid = "custom-emoji-add"
240- disabled = { ! canSubmit }
241- >
242- { setEmoji . isPending ? "Saving…" : "Save emoji" }
243- </ Button >
254+ < div className = "space-y-3" data-testid = "custom-emoji-mine" >
255+ < h3 className = "text-sm font-medium" >
256+ My emoji{ own . length > 0 ? ` (${ own . length } )` : "" }
257+ </ h3 >
258+ { ownLoading ? (
259+ < SettingsOptionGroup >
260+ < div className = "px-4 py-3 text-sm font-normal text-muted-foreground" >
261+ Loading…
262+ </ div >
263+ </ SettingsOptionGroup >
264+ ) : own . length === 0 ? (
265+ < SettingsOptionGroup >
266+ < div className = "px-4 py-3 text-sm font-normal text-muted-foreground" >
267+ You haven't added any emoji yet. Add one above.
268+ </ div >
269+ </ SettingsOptionGroup >
270+ ) : (
271+ < SettingsOptionGroup >
272+ { own . map ( ( e ) => (
273+ < div
274+ key = { e . shortcode }
275+ className = "flex items-center gap-3 px-4 py-3"
276+ >
277+ < img
278+ alt = { `:${ e . shortcode } :` }
279+ src = { rewriteRelayUrl ( e . url ) }
280+ className = "h-6 w-6 shrink-0 object-contain"
281+ draggable = { false }
282+ />
283+ < span className = "min-w-0 flex-1 truncate text-sm" >
284+ :{ e . shortcode } :
285+ </ span >
286+ < Button
287+ aria-label = { `Remove :${ e . shortcode } :` }
288+ size = "icon"
289+ variant = "ghost"
290+ onClick = { ( ) => void handleRemove ( e . shortcode ) }
291+ disabled = { removeEmoji . isPending }
292+ >
293+ < Trash2 className = "h-4 w-4" />
294+ </ Button >
295+ </ div >
296+ ) ) }
297+ </ SettingsOptionGroup >
298+ ) }
244299 </ div >
245- </ form >
246300
247- < div className = "space-y-3" data-testid = "custom-emoji-mine" >
248- < h3 className = "text-sm font-medium" >
249- My emoji{ own . length > 0 ? ` (${ own . length } )` : "" }
250- </ h3 >
251- { ownLoading ? (
252- < p className = "text-sm text-muted-foreground" > Loading…</ p >
253- ) : own . length === 0 ? (
254- < p className = "text-sm text-muted-foreground" >
255- You haven't added any emoji yet. Add one above.
256- </ p >
257- ) : (
258- < ul className = "grid grid-cols-1 gap-1.5 sm:grid-cols-2" >
259- { own . map ( ( e ) => (
260- < li
261- key = { e . shortcode }
262- className = "flex items-center gap-3 rounded-lg border bg-card px-3 py-2"
263- >
264- < img
265- alt = { `:${ e . shortcode } :` }
266- src = { rewriteRelayUrl ( e . url ) }
267- className = "h-6 w-6 shrink-0 object-contain"
268- draggable = { false }
269- />
270- < span className = "min-w-0 flex-1 truncate text-sm" >
271- :{ e . shortcode } :
272- </ span >
273- < Button
274- aria-label = { `Remove :${ e . shortcode } :` }
275- size = "icon"
276- variant = "ghost"
277- onClick = { ( ) => void handleRemove ( e . shortcode ) }
278- disabled = { removeEmoji . isPending }
301+ { ! workspaceLoading && othersEmoji . length > 0 ? (
302+ < div className = "space-y-3" data-testid = "custom-emoji-workspace" >
303+ < h3 className = "text-sm font-medium" >
304+ Workspace emoji ({ othersEmoji . length } )
305+ </ h3 >
306+ < p className = "text-sm font-normal text-muted-foreground" >
307+ Added by other members. You can use these, but only their owner
308+ can remove them.
309+ </ p >
310+ < SettingsOptionGroup >
311+ { othersEmoji . map ( ( e ) => (
312+ < div
313+ key = { e . shortcode }
314+ className = "flex items-center gap-3 px-4 py-3"
279315 >
280- < Trash2 className = "h-4 w-4" />
281- </ Button >
282- </ li >
283- ) ) }
284- </ ul >
285- ) }
316+ < img
317+ alt = { `:${ e . shortcode } :` }
318+ src = { rewriteRelayUrl ( e . url ) }
319+ className = "h-6 w-6 shrink-0 object-contain"
320+ draggable = { false }
321+ />
322+ < span className = "min-w-0 flex-1 truncate text-sm" >
323+ :{ e . shortcode } :
324+ </ span >
325+ </ div >
326+ ) ) }
327+ </ SettingsOptionGroup >
328+ </ div >
329+ ) : null }
286330 </ div >
287-
288- { ! workspaceLoading && othersEmoji . length > 0 ? (
289- < div className = "space-y-3" data-testid = "custom-emoji-workspace" >
290- < h3 className = "text-sm font-medium" >
291- Workspace emoji ({ othersEmoji . length } )
292- </ h3 >
293- < p className = "text-sm text-muted-foreground" >
294- Added by other members. You can use these, but only their owner can
295- remove them.
296- </ p >
297- < ul className = "grid grid-cols-1 gap-1.5 sm:grid-cols-2" >
298- { othersEmoji . map ( ( e ) => (
299- < li
300- key = { e . shortcode }
301- className = "flex items-center gap-3 rounded-lg border bg-card px-3 py-2"
302- >
303- < img
304- alt = { `:${ e . shortcode } :` }
305- src = { rewriteRelayUrl ( e . url ) }
306- className = "h-6 w-6 shrink-0 object-contain"
307- draggable = { false }
308- />
309- < span className = "min-w-0 flex-1 truncate text-sm" >
310- :{ e . shortcode } :
311- </ span >
312- </ li >
313- ) ) }
314- </ ul >
315- </ div >
316- ) : null }
317331 </ section >
318332 ) ;
319333}
0 commit comments