Skip to content

Commit d7886a4

Browse files
authored
Refactor image handling for fallback URLs (#354)
1 parent 7f5d124 commit d7886a4

10 files changed

Lines changed: 28 additions & 24 deletions

File tree

src/app/api/speakers/search/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function GET(request: NextRequest) {
2323
email,
2424
title,
2525
bio,
26-
"image": image.asset->url,
26+
"image": coalesce(image.asset->url, imageURL),
2727
"slug": slug.current,
2828
flags
2929
}`,

src/components/cfp/SpeakerDetailsForm.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export function SpeakerDetailsForm({
4848
const [speakerBio, setSpeakerBio] = useState(speaker?.bio ?? '')
4949
const [speakerEmail, setSpeakerEmail] = useState(email ?? '')
5050
const [speakerImage, setSpeakerImage] = useState(speaker?.image ?? '')
51+
const [imageChanged, setImageChanged] = useState(false)
5152
const [speakerImagePreviewUrl, setSpeakerImagePreviewUrl] = useState<
5253
string | null
5354
>(speaker?.image && speaker.image.startsWith('http') ? speaker.image : null)
@@ -153,6 +154,7 @@ export function SpeakerDetailsForm({
153154
const { assetId, url } = await onImageUpload(file)
154155
setSpeakerImage(assetId)
155156
setSpeakerImagePreviewUrl(url)
157+
setImageChanged(true)
156158
} catch (error) {
157159
setImageError(
158160
error instanceof Error ? error.message : 'Failed to upload image',
@@ -164,6 +166,7 @@ export function SpeakerDetailsForm({
164166
setImageError(error.message)
165167
} else if (image) {
166168
setSpeakerImage(image.image)
169+
setImageChanged(true)
167170
}
168171
}
169172

@@ -211,7 +214,7 @@ export function SpeakerDetailsForm({
211214
bio: speakerBio,
212215
flags: speakerFlags,
213216
links,
214-
...(speakerImage && { image: speakerImage }),
217+
...(speakerImage && imageChanged && { image: speakerImage }),
215218
consent: {
216219
dataProcessing: {
217220
granted: dataProcessingConsent,
@@ -240,6 +243,7 @@ export function SpeakerDetailsForm({
240243
speakerFlags,
241244
speakerLinks,
242245
speakerImage,
246+
imageChanged,
243247
dataProcessingConsent,
244248
marketingConsent,
245249
publicProfileConsent,

src/lib/badge/sanity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const BADGE_FIELDS = `
1313
_id,
1414
name,
1515
email,
16-
"image": image.asset->url,
16+
"image": coalesce(image.asset->url, imageURL),
1717
title,
1818
"slug": slug.current,
1919
talks[]->{

src/lib/conference/sanity.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export async function getConferenceForDomain(
116116
? `organizers[]->{
117117
...,
118118
"slug": slug.current,
119-
"image": image.asset->url
119+
"image": coalesce(image.asset->url, imageURL)
120120
},`
121121
: ''
122122
}
@@ -125,7 +125,7 @@ export async function getConferenceForDomain(
125125
? `featuredSpeakers[]->{
126126
...,
127127
"slug": slug.current,
128-
"image": image.asset->url,
128+
"image": coalesce(image.asset->url, imageURL),
129129
"talks": *[_type == "talk" && references(^._id) && conference._ref == ^.^._id && status == "confirmed"]{
130130
_id,
131131
title,
@@ -158,7 +158,7 @@ export async function getConferenceForDomain(
158158
name,
159159
"slug": slug.current,
160160
title,
161-
"image": image.asset->url
161+
"image": coalesce(image.asset->url, imageURL)
162162
}
163163
},`
164164
: ''
@@ -194,7 +194,7 @@ export async function getConferenceForDomain(
194194
name,
195195
"slug": slug.current,
196196
title,
197-
"image": image.asset->url
197+
"image": coalesce(image.asset->url, imageURL)
198198
}
199199
}
200200
}

src/lib/featured/sanity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function getFeaturedSpeakers(
2828
title,
2929
bio,
3030
"slug": slug.current,
31-
"image": image.asset->url,
31+
"image": coalesce(image.asset->url, imageURL),
3232
"talks": *[_type == "talk" && references(^._id) && conference._ref == $conferenceId && status in ["confirmed", "accepted"]] {
3333
_id,
3434
title,
@@ -76,7 +76,7 @@ export async function getFeaturedTalks(
7676
name,
7777
title,
7878
"slug": slug.current,
79-
"image": image.asset->url
79+
"image": coalesce(image.asset->url, imageURL)
8080
}
8181
}`,
8282
{ conferenceId },

src/lib/gallery/sanity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export async function getGalleryImage(
292292
_id,
293293
name,
294294
"slug": slug.current,
295-
"image": image.asset->url
295+
"image": coalesce(image.asset->url, imageURL)
296296
}
297297
}
298298
`
@@ -397,7 +397,7 @@ export async function getGalleryImages(
397397
_id,
398398
name,
399399
"slug": slug.current,
400-
"image": image.asset->url
400+
"image": coalesce(image.asset->url, imageURL)
401401
}
402402
}
403403
`

src/lib/proposal/data/sanity.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function getProposal({
4545
...,
4646
speakers[]-> {
4747
...,
48-
"image": image.asset->url,
48+
"image": coalesce(image.asset->url, imageURL),
4949
${
5050
isOrganizer && includeSubmittedTalks
5151
? `"submittedTalks": *[
@@ -167,7 +167,7 @@ export async function getProposals({
167167
const query = groq`*[${filters}]{
168168
...,
169169
speakers[]-> {
170-
_id, name, email, providers, "image": image.asset->url, flags, "slug": slug.current,
170+
_id, name, email, providers, "image": coalesce(image.asset->url, imageURL), flags, "slug": slug.current,
171171
${
172172
includePreviousAcceptedTalks
173173
? `"previousAcceptedTalks": *[
@@ -456,7 +456,7 @@ export async function searchProposals({
456456
email,
457457
providers,
458458
bio,
459-
"image": image.asset->url,
459+
"image": coalesce(image.asset->url, imageURL),
460460
flags,
461461
"slug": slug.current
462462
${

src/lib/sanity/speaker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export async function getSpeakerByEmail(
1212
name,
1313
email,
1414
isOrganizer,
15-
"image": image.asset->url,
15+
"image": coalesce(image.asset->url, imageURL),
1616
"slug": slug.current
1717
}
1818
`

src/lib/speaker/sanity.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function findSpeakerByProvider(
4343
`*[ _type == "speaker" && $id in providers][0]{
4444
...,
4545
"slug": slug.current,
46-
"image": image.asset->url
46+
"image": coalesce(image.asset->url, imageURL)
4747
}`,
4848
{ id },
4949
)
@@ -65,7 +65,7 @@ async function findSpeakerByEmail(
6565
`*[ _type == "speaker" && email == $email][0]{
6666
...,
6767
"slug": slug.current,
68-
"image": image.asset->url
68+
"image": coalesce(image.asset->url, imageURL)
6969
}`,
7070
{ email },
7171
)
@@ -165,7 +165,7 @@ export async function getSpeaker(
165165
`*[ _type == "speaker" && _id == $speakerId][0]{
166166
...,
167167
"slug": slug.current,
168-
"image": image.asset->url
168+
"image": coalesce(image.asset->url, imageURL)
169169
}`,
170170
{ speakerId },
171171
{ cache: 'no-store' },
@@ -187,7 +187,7 @@ export async function getPublicSpeaker(
187187
try {
188188
data = await clientReadCached.fetch(
189189
`*[ _type == "speaker" && slug.current == $speakerSlug && count(*[_type == "talk" && references(^._id) && status == "confirmed" && conference._ref == $conferenceId]) > 0][0]{
190-
name, title, bio, links, flags, "image": image.asset->url,
190+
name, title, bio, links, flags, "image": coalesce(image.asset->url, imageURL),
191191
"talks": *[_type == "talk" && references(^._id) && status == "confirmed" && conference._ref == $conferenceId]{
192192
_id, title, description, language, level, format, audiences, video,
193193
attachments[]{
@@ -197,7 +197,7 @@ export async function getPublicSpeaker(
197197
}
198198
},
199199
speakers[]-> {
200-
_id, name, title, "slug": slug.current, "image": image.asset->url
200+
_id, name, title, "slug": slug.current, "image": coalesce(image.asset->url, imageURL)
201201
},
202202
topics[]-> {
203203
_id, title, "slug": slug.current
@@ -319,7 +319,7 @@ export async function getSpeakers(
319319
const query = groq`*[_type == "speaker" && count(*[_type == "talk" && references(^._id) && status in [${statusFilter}] ${conferenceFilter}]) > 0] {
320320
...,
321321
"slug": slug.current,
322-
"image": image.asset->url,
322+
"image": coalesce(image.asset->url, imageURL),
323323
"proposals": *[_type == "talk" && references(^._id) && status in [${statusFilter}] ${proposalsConferenceFilter}] {
324324
_id,
325325
title,
@@ -396,7 +396,7 @@ export async function getOrganizers(): Promise<{
396396
const query = groq`*[_type == "speaker" && isOrganizer == true] {
397397
...,
398398
"slug": slug.current,
399-
"image": image.asset->url
399+
"image": coalesce(image.asset->url, imageURL)
400400
} | order(name asc)`
401401

402402
speakers = await clientRead.fetch(query, {}, { cache: 'no-store' })
@@ -419,7 +419,7 @@ export async function getOrganizersByConference(conferenceId: string): Promise<{
419419
const query = groq`*[_type == "conference" && _id == $conferenceId][0].organizers[]-> {
420420
...,
421421
"slug": slug.current,
422-
"image": image.asset->url
422+
"image": coalesce(image.asset->url, imageURL)
423423
} | order(name asc)`
424424

425425
speakers = await clientRead.fetch(

src/lib/workshop/sanity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export async function getWorkshopById(
218218
name,
219219
"slug": slug.current,
220220
bio,
221-
"avatar": image.asset->url,
221+
"avatar": coalesce(image.asset->url, imageURL),
222222
company
223223
},
224224
"signupCount": count(*[_type == "workshopSignup" && workshop._ref == ^._id && status == "confirmed"])

0 commit comments

Comments
 (0)