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 (
Unsupported file type
)}