-
Notifications
You must be signed in to change notification settings - Fork 70
When Openweathermap calls for multiple images, split icon Id and get multiple images #526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,8 +75,14 @@ | |
| id="clockweatherinfo" | ||
| class="text-xl sm:text-xl md:text-2xl lg:text-3xl font-semibold text-shadow-sm weather-info" | ||
| > | ||
| {#if $configStore.weatherIconUrl } | ||
| <img src="{ $configStore.weatherIconUrl.replace('{IconId}', encodeURIComponent(weather.iconId)) }" class="icon-weather" alt="{weather.description}"> | ||
| {#if $configStore.weatherIconUrl} | ||
| {#each weather.iconId?.split(',') ?? [] as icon (icon)} | ||
| <img | ||
| src={$configStore.weatherIconUrl.replace('{IconId}', encodeURIComponent(icon.trim()))} | ||
| class="icon-weather" | ||
| alt={weather.description} | ||
| /> | ||
| {/each} | ||
|
Comment on lines
+78
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normalize and filter icon IDs to avoid empty/duplicate entries, and consider precomputing the icon list The multi‑icon rendering logic looks correct overall, but there are a couple of minor robustness concerns:
You can tighten this up by normalizing and filtering the icon IDs once in a derived value and then iterating over that, using a stable key: - {#if $configStore.weatherIconUrl}
- {#each weather.iconId?.split(',') ?? [] as icon (icon)}
- <img
- src={$configStore.weatherIconUrl.replace('{IconId}', encodeURIComponent(icon.trim()))}
- class="icon-weather"
- alt={weather.description}
- />
- {/each}
- {/if}
+ {#if $configStore.weatherIconUrl}
+ {#each weatherIcons() as icon, index (icon + '-' + index)}
+ <img
+ src={$configStore.weatherIconUrl.replace('{IconId}', encodeURIComponent(icon))}
+ class="icon-weather"
+ alt={weather.description}
+ />
+ {/each}
+ {/if}And in the const weatherIcons = $derived(
() =>
weather?.iconId
?.split(',')
.map((id) => id.trim())
.filter((id) => id.length > 0) ?? []
);This avoids broken images from empty IDs, gives you predictable keys, and keeps the template a bit cleaner. 🤖 Prompt for AI Agents |
||
| {/if} | ||
| <div class="weather-location">{weather.location},</div> | ||
| <div class="weather-temperature">{weather.temperature?.toFixed(1)}</div> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested this and it looks OK? I feel like it would look weird having two weather icons. My vote would be split iconId on comma, and just always use element [0].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the same. Also, if the
weather.iconIdwould be an empty string, the split would still return a single element (empty) which would request the URL with an emptyid.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered displaying a single element. This may work fine, but it may result in discounting a weather status that the user would prefer to know about. If the API returns "mist,heavy rain", the second element should probably take priority.