From faa14c5db0cde222685014cb58f851ae443427c2 Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Sat, 27 Jul 2024 09:28:58 +0530 Subject: added fetching content from firebase --- src/components/ViewAds.jsx | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/components/ViewAds.jsx b/src/components/ViewAds.jsx index 0c5486c..e681989 100644 --- a/src/components/ViewAds.jsx +++ b/src/components/ViewAds.jsx @@ -1,7 +1,7 @@ import React, { useState, useEffect } from 'react'; -import './ViewAds.css'; import { getDownloadURL, listAll, ref } from 'firebase/storage'; import { storage } from '../firebase'; +import './ViewAds.css'; const ViewAds = () => { const [urls, setUrls] = useState([]); @@ -22,18 +22,33 @@ const ViewAds = () => { fetchUrls(); }, []); + const getFileType = (url) => { + const fileExtension = url.split('?')[0].split('.').pop().toLowerCase(); + const imageExtensions = ['jpeg', 'jpg', 'gif', 'png']; + const videoExtensions = ['mp4', 'mov', 'avi', 'mkv']; + + if (imageExtensions.includes(fileExtension)) { + return 'image'; + } else if (videoExtensions.includes(fileExtension)) { + return 'video'; + } else { + return 'unsupported'; + } + }; + return (

Uploaded Ads

{urls.map((url, index) => { - const isImage = url.match(/\.(jpeg|jpg|gif|png)$/); - const isVideo = url.match(/\.(mp4|mov|avi|mkv)$/); + const fileType = getFileType(url); + console.log(`URL: ${url}, fileType: ${fileType}`); + return (
- {isImage ? ( + {fileType === 'image' ? ( {`Ad - ) : isVideo ? ( + ) : fileType === 'video' ? (