From bd933a5aace3ac4944bfe7f4b58b4908978b4950 Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Thu, 1 Aug 2024 17:49:26 +0530 Subject: merge --- src/components/ViewAds.jsx | 67 ---------------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 src/components/ViewAds.jsx (limited to 'src/components/ViewAds.jsx') diff --git a/src/components/ViewAds.jsx b/src/components/ViewAds.jsx deleted file mode 100644 index e681989..0000000 --- a/src/components/ViewAds.jsx +++ /dev/null @@ -1,67 +0,0 @@ -import React, { useState, useEffect } from 'react'; -import { getDownloadURL, listAll, ref } from 'firebase/storage'; -import { storage } from '../firebase'; -import './ViewAds.css'; - -const ViewAds = () => { - const [urls, setUrls] = useState([]); - - useEffect(() => { - const fetchUrls = async () => { - const listRef = ref(storage, 'ads/'); - try { - const res = await listAll(listRef); - const urlsPromises = res.items.map(itemRef => getDownloadURL(itemRef)); - const urls = await Promise.all(urlsPromises); - setUrls(urls); - } catch (error) { - console.error('Error fetching URLs:', error); - } - }; - - 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 fileType = getFileType(url); - console.log(`URL: ${url}, fileType: ${fileType}`); - - return ( -
- {fileType === 'image' ? ( - {`Ad - ) : fileType === 'video' ? ( - - ) : ( -

Unsupported file type

- )} -
- ); - })} -
-
- ); -}; - -export default ViewAds; -- cgit v1.2.3-59-g8ed1b