Skip to content

Commit

Permalink
isom-1687 update site identifier logos (#909)
Browse files Browse the repository at this point in the history
* fix - use logo URL instead

* replace with common method

* change objectFit to contain

* add 1rem padding for image
  • Loading branch information
adriangohjw authored Dec 2, 2024
1 parent 6308a7f commit bd0c671
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 4 additions & 2 deletions apps/studio/src/features/dashboard/SiteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Link } from "@opengovsg/design-system-react"

import { NoResultIcon } from "~/components/Svg/NoResultIcon"
import { withSuspense } from "~/hocs/withSuspense"
import { generateAssetUrl } from "~/utils/generateAssetUrl"
import { trpc } from "~/utils/trpc"

const Site = ({
Expand All @@ -39,10 +40,11 @@ const Site = ({
borderColor="base.divider.medium"
width="100%"
height="100%"
objectFit="cover"
objectFit="contain"
aspectRatio="1/1"
backgroundColor="white"
fallbackSrc="/isomer-sites-placeholder.png"
padding="1rem" // Leave some space so that logo won't be flush with the border
/>
<Box
position="absolute"
Expand Down Expand Up @@ -134,7 +136,7 @@ const SuspendableSiteList = (): JSX.Element => {
<Site
siteId={site.id}
siteName={site.name}
siteLogoUrl={site.config.logoUrl}
siteLogoUrl={generateAssetUrl(site.config.logoUrl)}
/>
))}
</SiteListSection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
import type { ModifiedAsset } from "~/types/assets"
import { JSON_FORMS_RANKING } from "~/constants/formBuilder"
import { useEditorDrawerContext } from "~/contexts/EditorDrawerContext"
import { useEnv } from "~/hooks/useEnv"
import { getPresignedPutUrlSchema } from "~/schemas/asset"
import { generateAssetUrl } from "~/utils/generateAssetUrl"
import {
IMAGE_UPLOAD_ACCEPTED_MIME_TYPES,
MAX_IMG_FILE_SIZE_BYTES,
Expand All @@ -37,9 +37,6 @@ export function JsonFormsImageControl({
errors,
data,
}: ControlProps) {
const {
env: { NEXT_PUBLIC_S3_ASSETS_DOMAIN_NAME },
} = useEnv()
const toast = useToast()
const { modifiedAssets, setModifiedAssets } = useEditorDrawerContext()
const [pendingAsset, setPendingAsset] = useState<ModifiedAsset | undefined>()
Expand Down Expand Up @@ -77,9 +74,7 @@ export function JsonFormsImageControl({
async function convertImage(url: string) {
const fileName = url.split("/").pop()
const fileType = `image/${url.split(".").pop()}`
const imageUrl = url.startsWith("/")
? `https://${NEXT_PUBLIC_S3_ASSETS_DOMAIN_NAME}${url}`
: url
const imageUrl = generateAssetUrl(url)
const file = await urlToFile(imageUrl, fileName || "", fileType)
setPendingAsset({ path, src: url, file })
}
Expand Down
7 changes: 7 additions & 0 deletions apps/studio/src/utils/generateAssetUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { env } from "~/env.mjs"

export const generateAssetUrl = (url: string): string => {
return url.startsWith("/")
? `https://${env.NEXT_PUBLIC_S3_ASSETS_DOMAIN_NAME}${url}`
: url
}

0 comments on commit bd0c671

Please sign in to comment.