Skip to content
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

Add PreLoadImage class to substitute IdentityBackground #2434

Merged
merged 3 commits into from
Apr 17, 2024

Conversation

lmuntaner
Copy link
Collaborator

@lmuntaner lmuntaner commented Apr 16, 2024

Main motivation is to remove the IdentityBackground class because it increases more the complexity than the value it adds.

The problem is that importing an asset in the showcase (Astro) and the application means different types of the imported value.

Before, we had a workaround that another instance of the class was created for the showcase and for the application.

IdentityBackground had two functionalities:

  • Ensure only one image is used.
  • Preload the image.

This PR introduces a new class PreLoadImage that has only the preloading functionality and expects an image as input.

This allows us to use the image differently in Astro and app environments.

import { dapps } from "../constants";
import { displayManagePage } from "$src/flows/manage";
import { html } from "lit-html";
import identityCardBackground from "$src/assets/identityCardBackground.png";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing it here we ensure that it doesn't get mixed with the application code and we don't need to cast types.

Ideally, we will move the showcase to its own library with its own package.json and then we will be able to separate import statements better.


export const identityBackground = IdentityBackground.getSingleton(
// When running the build, this is also built but not in an Astro environment
(backgroundImage as unknown as ImageMetadata).src
Copy link
Collaborator Author

@lmuntaner lmuntaner Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way to remove this ugly line was to import the asset in the .astro files directly.

@lmuntaner lmuntaner marked this pull request as ready for review April 16, 2024 14:19
@lmuntaner
Copy link
Collaborator Author

@frederikrothenberger let me know what you think now.

Copy link
Contributor

@frederikrothenberger frederikrothenberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, lgtm!

@lmuntaner lmuntaner added this pull request to the merge queue Apr 17, 2024
Merged via the queue into main with commit 1e31872 Apr 17, 2024
65 checks passed
@lmuntaner lmuntaner deleted the lm-add-image-to-identity-bacground branch April 17, 2024 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants