Skip to content

Commit

Permalink
Possibly fix weather images in prod (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel-Therrien-Beslogic committed Nov 28, 2024
1 parent 2b42bee commit a9359bf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 46 deletions.
2 changes: 1 addition & 1 deletion canopeum_frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ module.exports = {
['^'],
// Relative imports.
// Anything that starts with a dot or src/
// KEEP IN SYNC WITH canopeum_frontend/tsconfig.json AND canopeum_frontend/vite.config.ts
[
// KEEP IN SYNC WITH canopeum_frontend/tsconfig.json & canopeum_frontend/vite.config.ts
'^(\\.'
+ '|src/'
+ '|@assets'
Expand Down
26 changes: 0 additions & 26 deletions canopeum_frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion canopeum_frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-prefer-function-component": "^3.3.0",
"eslint-plugin-react-refresh": "^0.4.5",
"readonly-types": "^4.5.0",
"sass": "1.77.6",
"typescript": "~5.5.4",
"vite": "^5.4.6"
Expand Down
36 changes: 18 additions & 18 deletions canopeum_frontend/src/constants/weatherImageMap.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { type ReadonlyURL, readonlyURL } from 'readonly-types'
import cloudyURL from '@assets/images/weather/cloudy-bg.jpeg'
import foggyURL from '@assets/images/weather/foggy-bg.jpeg'
import rainyURL from '@assets/images/weather/rainy-bg.jpeg'
import snowyURL from '@assets/images/weather/snowy-bg.jpeg'
import sunnyURL from '@assets/images/weather/sunny-bg.jpeg'
import thunderstormURL from '@assets/images/weather/thunderstorm-bg.jpeg'

type WMOCategoriesImageUrls = {
readonly imageUrl: ReadonlyURL | undefined,
readonly imageUrl: string | undefined,
WMOCategories: string[],
}

const WMOCategoriesImages: WMOCategoriesImageUrls[] = [
{
imageUrl: readonlyURL('../assets/images/weather/sunny-bg.jpeg', import.meta.url),
imageUrl: sunnyURL,
WMOCategories: ['Clear sky', 'Mainly clear'],
},
{
imageUrl: readonlyURL('../assets/images/weather/cloudy-bg.jpeg', import.meta.url),
imageUrl: cloudyURL,
WMOCategories: ['Partly cloudy', 'Overcast', 'Foggy', 'Depositing rime fog'],
},
{
imageUrl: readonlyURL('../assets/images/weather/rainy-bg.jpeg', import.meta.url),
imageUrl: rainyURL,
WMOCategories: [
'Slight Rain',
'Moderate Rain',
Expand All @@ -30,11 +35,11 @@ const WMOCategoriesImages: WMOCategoriesImageUrls[] = [
],
},
{
imageUrl: readonlyURL('../assets/images/weather/snowy-bg.jpeg', import.meta.url),
imageUrl: snowyURL,
WMOCategories: ['Slight Snow fall', 'Moderate Snow fall', 'Heavy Snow fall', 'Snow grains'],
},
{
imageUrl: readonlyURL('../assets/images/weather/foggy-bg.jpeg', import.meta.url),
imageUrl: foggyURL,
WMOCategories: [
'Light Drizzle',
'Moderate Drizzle',
Expand All @@ -44,7 +49,7 @@ const WMOCategoriesImages: WMOCategoriesImageUrls[] = [
],
},
{
imageUrl: readonlyURL('../assets/images/weather/thunderstorm-bg.jpeg', import.meta.url),
imageUrl: thunderstormURL,
WMOCategories: [
'Thunderstorm with slight hail',
'Thunderstorm with hail',
Expand All @@ -53,15 +58,10 @@ const WMOCategoriesImages: WMOCategoriesImageUrls[] = [
},
]

const getImageNameByWMOCategories = (WMOCategory: string): string | undefined => {
const image =
WMOCategoriesImages.find(wmoCategoriesImage =>
wmoCategoriesImage.WMOCategories.some(category => WMOCategory.includes(category))
) ?? undefined

return image && image.imageUrl
? image.imageUrl.href
: WMOCategoriesImages[0].imageUrl?.href
}
const getImageNameByWMOCategories = (WMOCategory: string) =>
WMOCategoriesImages
.find(wmoCategoriesImage => wmoCategoriesImage.WMOCategories.includes(WMOCategory))
?.imageUrl
?? WMOCategoriesImages[0].imageUrl

export { getImageNameByWMOCategories }

0 comments on commit a9359bf

Please sign in to comment.