Skip to content

feat: show gif icon #11545

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat: show gif icon #11545

wants to merge 1 commit into from

Conversation

preschian
Copy link
Member

@preschian preschian commented Apr 22, 2025

Thank you for your contribution to the Koda - Generative Art Marketplace.

👇 __ Let's make a quick check before the contribution.

PR Type

  • Bugfix
  • Feature
  • Refactoring

Context

  • show gif icon on item list

Summary by CodeRabbit

  • New Features
    • Media items now display dynamic icons based on the detected file type, including special handling for GIF images.
  • Improvements
    • Enhanced media handling in NFT cards by passing raw image URLs for more accurate file type detection.
  • Chores
    • Internal cleanup by removing unused utility functions related to MIME type fetching.

Copy link

cloudflare-workers-and-pages bot commented Apr 22, 2025

Deploying koda-art-prod with  Cloudflare Pages  Cloudflare Pages

Latest commit: b3d7d45
Status: ✅  Deploy successful!
Preview URL: https://8c0e86e9.kodaart-production.pages.dev
Branch Preview URL: https://feat--show-gif-icon.kodaart-production.pages.dev

View logs

Copy link

coderabbitai bot commented Apr 22, 2025

Walkthrough

This update modifies the MediaItem component to introduce a new rawSrc prop and refactors how MIME types are determined. The logic for fetching and assigning MIME types is moved from a watcher to the onMounted lifecycle hook, and the icon displayed is now dynamically set based on the MIME type. The NftCard component is updated to pass the raw image URL to MediaItem via the new prop. Additionally, the fetchMimeType utility function is removed from the codebase.

Changes

File(s) Change Summary
components/base/MediaItem.vue Added rawSrc prop, refactored MIME type logic to onMounted, introduced dynamic icon assignment.
components/shared/nftCard/NftCard.vue Passed NFT raw image URL to MediaItem via new rawSrc prop.
utils/fetch.ts Removed the fetchMimeType function and its related imports.

Suggested reviewers

  • hassnian
  • Jarsen136

Poem

A hop and a skip, a new prop appears,
rawSrc now guides what the MediaItem steers.
Icons adapt, fetching types on the fly,
While old code and watchers wave a gentle goodbye.
NftCard sends its images, pure and direct—
Bunnies approve, with the changes checked!
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Apr 22, 2025

Deploy Preview for koda-canary ready!

Name Link
🔨 Latest commit b3d7d45
🔍 Latest deploy log https://app.netlify.com/sites/koda-canary/deploys/68077a86da133900080f6a74
😎 Deploy Preview https://deploy-preview-11545--koda-canary.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@preschian preschian marked this pull request as ready for review April 22, 2025 11:27
@preschian preschian requested a review from a team as a code owner April 22, 2025 11:27
@preschian preschian requested review from vikiival and hassnian and removed request for a team April 22, 2025 11:27
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
components/base/MediaItem.vue (2)

197-208: Consider adding a watcher for rawSrc changes.

Currently, the MIME type is only fetched on component mount. If the rawSrc prop changes after the component is mounted, the icon won't update.

onMounted(async () => {
  if (props.animationSrc && !props.mimeType) {
    type.value = await getMimeType(props.animationSrc)
  }
  else if (props.rawSrc) {
    const mimeType = await fetchMimeType(props.rawSrc)
    const icon = {
      'image/gif': 'i-mdi:file-gif-box',
    }
    iconType.value = icon[mimeType.mime_type] || 'i-mdi:file-image-box'
  }
})

+// Add a watcher to update the icon if rawSrc changes after mounting
+watch(() => props.rawSrc, async (newSrc) => {
+  if (newSrc) {
+    try {
+      const mimeType = await fetchMimeType(newSrc)
+      const icon = {
+        'image/gif': 'i-mdi:file-gif-box',
+      }
+      iconType.value = icon[mimeType.mime_type] || 'i-mdi:file-image-box'
+    } catch (error) {
+      console.error('Failed to get MIME type for updated raw source:', error)
+    }
+  }
+}, { immediate: false })

197-208: Extract icon mapping to a constant.

The icon mapping for MIME types could be extracted to a constant outside the component or function for better maintainability, especially if more icons are added in the future.

+const MIME_TYPE_ICONS = {
+  'image/gif': 'i-mdi:file-gif-box',
+}

onMounted(async () => {
  if (props.animationSrc && !props.mimeType) {
    type.value = await getMimeType(props.animationSrc)
  }
  else if (props.rawSrc) {
    const mimeType = await fetchMimeType(props.rawSrc)
-    const icon = {
-      'image/gif': 'i-mdi:file-gif-box',
-    }
-    iconType.value = icon[mimeType.mime_type] || 'i-mdi:file-image-box'
+    iconType.value = MIME_TYPE_ICONS[mimeType.mime_type] || 'i-mdi:file-image-box'
  }
})
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d360ffe and b3d7d45.

📒 Files selected for processing (3)
  • components/base/MediaItem.vue (5 hunks)
  • components/shared/nftCard/NftCard.vue (1 hunks)
  • utils/fetch.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • utils/fetch.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages: koda-art-prod
🔇 Additional comments (5)
components/base/MediaItem.vue (4)

48-48: Good implementation of dynamic icon binding.

The icon name is now dynamically bound to the reactive iconType reference, allowing for different icons based on the media type.


85-85: Good addition of the rawSrc prop.

Adding the rawSrc prop allows the component to work with the original, unsanitized URL for MIME type detection, while still using the sanitized URL for display purposes.

Also applies to: 112-113


133-133: Good default icon choice.

The default icon 'i-mdi:file-image-box' is appropriate for general image files when specific MIME type detection isn't available or applicable.


80-80:

✅ Verification successful

Verify the correct import path for fetchMimeType.

The service import path has changed to @/services/oda. Make sure this is the correct location and that the function signature matches what you're expecting in the component.


🏁 Script executed:

#!/bin/bash
# Check if the fetchMimeType function exists in the specified path
rg -A 5 "export.*fetchMimeType" services/oda

Length of output: 99


Let’s locate where fetchMimeType is actually defined in the repo:


🏁 Script executed:

#!/bin/bash
# Search for all occurrences and definitions of fetchMimeType
rg "fetchMimeType" -n .

Length of output: 639


fetchMimeType import path and signature validated

The fetchMimeType function is exported from src/services/oda.ts at line 69 and matches the signature fetchMimeType(uri: string). All imports (in MediaItem.vue and useGalleryItem.ts) correctly reference @/services/oda, and the usage with a string argument (props.rawSrc) is valid. No changes required.

components/shared/nftCard/NftCard.vue (1)

30-30: Good implementation passing raw source to MediaItem.

Passing the raw NFT image URL to the MediaItem component enables proper MIME type detection, particularly for GIF images, while still using the sanitized URL for display purposes.

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.

1 participant