From 56250de84db2b86da29783c2b1cfdf94c45dd3ac Mon Sep 17 00:00:00 2001 From: Raunakbansal12 Date: Sun, 27 Jul 2025 10:08:40 +0530 Subject: [PATCH 1/9] Update index.html --- frontend/index.html | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/index.html b/frontend/index.html index e39820a..d98364d 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -26,6 +26,11 @@ background-repeat: no-repeat; background-position: 1rem center; } + .rajasthan-banner img { + height: 2.5rem; + vertical-align: middle; + margin: 0 1rem; + } .navbar { background: #ffd54f !important; } @@ -49,9 +54,9 @@
- + Camel Icon Welcome to Rajasthan’s e-ठेला! - + Camel Icon
- - + +

Marketplace

+
- - - @@ -74,9 +53,10 @@ if (!token) window.location.href = 'login.html'; let userRole = null; let myUserId = null; - let reviewRating = 0; + let allItems = []; + let currentLanguage = 'en'; + document.addEventListener('DOMContentLoaded', async function() { - // Get user role try { const res = await fetch('http://localhost:5000/profile', { headers: { 'Authorization': 'Bearer ' + token } @@ -85,109 +65,109 @@ if (res.ok) { userRole = data.user.role; myUserId = data.user._id; - if (userRole === 'STREET_VENDOR') { - document.getElementById('marketTitle').innerText = 'Raw Materials Marketplace'; - loadProducts(); - } else { - document.getElementById('marketTitle').innerText = 'Street Vendor Listings'; - loadListings(); - } - } else { - alert('Failed to load user profile'); + document.getElementById('marketTitle').innerText = userRole === 'STREET_VENDOR' ? 'Raw Materials Marketplace' : 'Street Vendor Listings'; + userRole === 'STREET_VENDOR' ? loadProducts() : loadListings(); } } catch (err) { alert('Server error'); } }); + async function loadProducts() { const res = await fetch('http://localhost:5000/products'); const products = await res.json(); - const feed = document.getElementById('marketFeed'); - feed.innerHTML = ''; - products.forEach(prod => { - feed.innerHTML += ` -
-
- ${prod.image ? `` : ''} -
-
${prod.name}
-

Price: ₹${prod.price} per ${prod.unit}

-

Supplier: ${prod.supplierId?.fullName || 'N/A'}

-

Phone: ${prod.supplierId?.phone || ''}

- ${prod.supplierId?.phone ? `` : ''} - ${prod.supplierId?._id && prod.supplierId._id !== myUserId ? `` : ''} - ${prod.supplierId?._id ? `` : ''} -
-
-
- `; - }); + allItems = products; + renderFeed(products); } + async function loadListings() { const res = await fetch('http://localhost:5000/listings'); const listings = await res.json(); + allItems = listings; + renderFeed(listings); + } + + function renderFeed(items) { const feed = document.getElementById('marketFeed'); feed.innerHTML = ''; - listings.forEach(list => { + items.forEach(item => { + const title = item.name || item.title; + const user = item.vendorId || item.supplierId; + const image = item.image ? `` : ''; feed.innerHTML += `
- ${list.image ? `` : ''} + ${image}
-
${list.title}
-

Price: ₹${list.price}

-

Vendor: ${list.vendorId?.fullName || 'N/A'}

-

Phone: ${list.vendorId?.phone || ''}

-

${list.description || ''}

- ${list.vendorId?._id && list.vendorId._id !== myUserId ? `` : ''} - ${list.vendorId?._id ? `` : ''} -
+
${translateText(title)}
+

${translateText('Price')}: ₹${item.price} ${item.unit ? translateText('per') + ' ' + item.unit : ''}

+

${translateText(user ? (item.vendorId ? 'Vendor' : 'Supplier') : 'User')}: ${user?.fullName || 'N/A'}

+

${translateText('Phone')}: ${user?.phone || 'Not Available'}

+ ${user?.phone ? `` : ''} +${user?._id && user._id !== myUserId ? ` + + +` : ''} + + +
- - `; + `; }); } - // Review Modal Logic - window.openReviewModal = function(subjectId) { - reviewRating = 0; - document.getElementById('reviewSubjectId').value = subjectId; - document.getElementById('reviewComment').value = ''; - renderStarRating(); - var reviewModal = new bootstrap.Modal(document.getElementById('reviewModal')); - reviewModal.show(); - } - function renderStarRating() { - const starDiv = document.getElementById('starRating'); - starDiv.innerHTML = ''; - for (let i = 1; i <= 5; i++) { - starDiv.innerHTML += ``; + function startVoiceSearch() { + if (!('webkitSpeechRecognition' in window)) { + alert('Voice recognition not supported in this browser.'); + return; } + const recognition = new webkitSpeechRecognition(); + recognition.lang = currentLanguage === 'hi' ? 'hi-IN' : 'en-IN'; + recognition.start(); + recognition.onresult = function(event) { + const spokenText = event.results[0][0].transcript.toLowerCase(); + document.getElementById('searchInput').value = spokenText; + filterItems(spokenText); + }; + recognition.onerror = function() { + alert('Could not recognize speech. Please try again.'); + }; } - window.setReviewRating = function(r) { - reviewRating = r; - renderStarRating(); - } - document.getElementById('reviewForm').onsubmit = async function(e) { - e.preventDefault(); - const subjectId = document.getElementById('reviewSubjectId').value; - const comment = document.getElementById('reviewComment').value; - if (!reviewRating) return alert('Please select a rating.'); - const res = await fetch('http://localhost:5000/reviews', { - method: 'POST', - headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token }, - body: JSON.stringify({ subjectId, rating: reviewRating, comment }) + + document.getElementById('searchInput').addEventListener('input', function() { + filterItems(this.value); + }); + + function filterItems(query) { + const filtered = allItems.filter(item => { + const name = (item.name || item.title || '').toLowerCase(); + return name.includes(query.toLowerCase()); }); - if (res.ok) { - alert('Review submitted!'); - bootstrap.Modal.getInstance(document.getElementById('reviewModal')).hide(); - } else { - alert('Failed to submit review'); - } + renderFeed(filtered); + } + + function toggleLanguage() { + currentLanguage = currentLanguage === 'en' ? 'hi' : 'en'; + document.getElementById('langToggle').innerText = currentLanguage === 'en' ? 'Switch to Hindi' : 'English को चुनें'; + renderFeed(allItems); + } + + function translateText(text) { + if (currentLanguage === 'en') return text; + const dict = { + 'Marketplace': 'बाजार', + 'Raw Materials Marketplace': 'कच्चे माल की बाजार', + 'Street Vendor Listings': 'स्ट्रीट वेंडर की सूची', + 'Price': 'मूल्य', + 'per': 'प्रति', + 'Vendor': 'विक्रेता', + 'Supplier': 'आपूर्तिकर्ता', + 'Phone': 'फोन' + }; + return dict[text] || text; } - // Reviews List Modal Logic - window.openReviewsListModal = async function(userId, userName) { + async function openReviewsListModal(userId, userName) { document.getElementById('reviewsListModalLabel').innerText = `Reviews for ${userName}`; const res = await fetch(`http://localhost:5000/reviews/${userId}`); const reviews = await res.json(); @@ -204,14 +184,12 @@
${list.title}
${r.comment || ''}
${new Date(r.createdAt).toLocaleString()}
- - `).join('')}`; + `).join('')}`; } else { body.innerHTML = '
No reviews yet.
'; } - var reviewsModal = new bootstrap.Modal(document.getElementById('reviewsListModal')); - reviewsModal.show(); + new bootstrap.Modal(document.getElementById('reviewsListModal')).show(); } - \ No newline at end of file + From 828f51ea051f2c7ba4987dd474261618b44d9ccd Mon Sep 17 00:00:00 2001 From: Raunakbansal12 Date: Sun, 27 Jul 2025 12:46:33 +0530 Subject: [PATCH 5/9] Update dashboard.html --- frontend/dashboard.html | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/frontend/dashboard.html b/frontend/dashboard.html index d10aa1a..4038d3c 100644 --- a/frontend/dashboard.html +++ b/frontend/dashboard.html @@ -26,6 +26,11 @@ background-repeat: no-repeat; background-position: 1rem center; } + .rajasthan-banner img { + height: 2.5rem; + vertical-align: middle; + margin: 0 1rem; + } .navbar { background: #ffd54f !important; } @@ -45,14 +50,22 @@ .btn-primary:hover, .btn-success:hover { background: linear-gradient(90deg, #e65100 0%, #ff9800 100%); } + + .rajasthan-banner { + + color: #333333; + + }
- - Welcome to Rajasthan’s e-ठेला! - -
+ Camel Icon + Welcome to Rajasthan’s e-ठेला! + Camel Icon + + +