Spaces:
Running
Running
Generate two separate mobile-friendly HTML files for a job website using vanilla JavaScript and Firebase (Realtime Database + Authentication).
750c8a3 verified Download user.html from rkrishukumar/jobhive-buzz: direct link, hf CLI and curl.
- Browser
- Download file 33.3 kB
-
https://huggingface.co/spaces/rkrishukumar/jobhive-buzz/resolve/main/user.html
- Command line
-
hf download hf://spaces/rkrishukumar/jobhive-buzz/user.html
-
curl -L -o user.html https://huggingface.co/spaces/rkrishukumar/jobhive-buzz/resolve/main/user.html
33.3 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>JobHive - Find Your Dream Job</title> | |
| <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet"> | |
| <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script> | |
| <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-auth.js"></script> | |
| <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-database.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> | |
| <style> | |
| .banner-animation { | |
| animation: scrollBanner 20s linear infinite; | |
| } | |
| @keyframes scrollBanner { | |
| 0% { transform: translateX(0); } | |
| 100% { transform: translateX(-50%); } | |
| } | |
| .category-icon { | |
| transition: transform 0.3s ease; | |
| } | |
| .category-icon:hover { | |
| transform: scale(1.05); | |
| } | |
| .job-card:hover { | |
| transform: translateY(-5px); | |
| transition: all 0.3s ease; | |
| box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1); | |
| } | |
| .bookmark-btn:hover { | |
| transform: scale(1.2); | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50"> | |
| <!-- Header --> | |
| <header class="bg-white shadow-sm sticky top-0 z-10"> | |
| <div class="container mx-auto px-4 py-3 flex justify-between items-center"> | |
| <h1 class="text-xl font-bold text-indigo-700">JobHive</h1> | |
| <div class="flex items-center space-x-2"> | |
| <button id="authBtn" class="px-3 py-1.5 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 text-sm"> | |
| <span id="authText">Login</span> | |
| </button> | |
| <button id="profileBtn" class="hidden items-center justify-center w-8 h-8 rounded-full bg-indigo-100 text-indigo-700"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" /> | |
| </svg> | |
| </button> | |
| </div> | |
| </div> | |
| </header> | |
| <!-- Auth Modal --> | |
| <div id="authModal" class="fixed inset-0 bg-black bg-opacity-50 z-50 hidden flex items-center justify-center p-4"> | |
| <div class="bg-white rounded-lg p-6 w-full max-w-md"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="text-lg font-bold" id="authModalTitle">Login</h3> | |
| <button id="closeAuthModal" class="text-gray-500 hover:text-gray-700"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" /> | |
| </svg> | |
| </button> | |
| </div> | |
| <div id="authForm"> | |
| <div class="space-y-3" id="loginFormContainer"> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Email</label> | |
| <input type="email" id="userEmail" class="w-full p-2 border rounded-md"> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Password</label> | |
| <input type="password" id="userPassword" class="w-full p-2 border rounded-md"> | |
| </div> | |
| <button id="loginBtn" class="w-full py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700"> | |
| Login | |
| </button> | |
| <p class="text-center text-xs text-gray-600">Don't have an account? <button id="showSignup" class="text-indigo-600 hover:underline">Sign up</button></p> | |
| </div> | |
| <div class="space-y-3 hidden" id="signupFormContainer"> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Name</label> | |
| <input type="text" id="userName" class="w-full p-2 border rounded-md"> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Email</label> | |
| <input type="email" id="signupEmail" class="w-full p-2 border rounded-md"> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Password</label> | |
| <input type="password" id="signupPassword" class="w-full p-2 border rounded-md"> | |
| </div> | |
| <button id="signupBtn" class="w-full py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700"> | |
| Sign Up | |
| </button> | |
| <p class="text-center text-xs text-gray-600">Already have an account? <button id="showLogin" class="text-indigo-600 hover:underline">Login</button></p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Profile Modal --> | |
| <div id="profileModal" class="fixed inset-0 bg-black bg-opacity-50 z-50 hidden flex items-center justify-center p-4"> | |
| <div class="bg-white rounded-lg p-6 w-full max-w-md"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="text-lg font-bold">My Profile</h3> | |
| <button id="closeProfileModal" class="text-gray-500 hover:text-gray-700"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" /> | |
| </svg> | |
| </button> | |
| </div> | |
| <div id="profileInfo" class="space-y-3"> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Name</label> | |
| <p id="profileName" class="p-2 bg-gray-100 rounded-md text-sm"></p> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Email</label> | |
| <p id="profileEmail" class="p-2 bg-gray-100 rounded-md text-sm"></p> | |
| </div> | |
| <button id="logoutBtn" class="w-full py-2 bg-red-500 text-white rounded-md hover:bg-red-600 mt-2"> | |
| Logout | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Main Content --> | |
| <main class="container mx-auto px-4 py-6"> | |
| <!-- Banner --> | |
| <div class="relative overflow-hidden rounded-lg mb-6 h-32 bg-gradient-to-r from-indigo-500 to-purple-600 flex items-center justify-center"> | |
| <div class="absolute inset-0 flex items-center banner-animation whitespace-nowrap"> | |
| <div class="text-white text-lg font-bold mx-4">Find Your Dream Job Today!</div> | |
| <div class="text-white text-lg font-bold mx-4">Thousands of Opportunities Waiting</div> | |
| <div class="text-white text-lg font-bold mx-4">Apply Now and Start Your Journey</div> | |
| </div> | |
| </div> | |
| <!-- Search --> | |
| <div class="mb-6"> | |
| <div class="relative"> | |
| <input type="text" id="jobSearch" placeholder="Search for jobs..." | |
| class="w-full p-3 pl-10 rounded-lg border border-gray-300 shadow-sm"> | |
| <div class="absolute left-3 top-3 text-gray-400"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" /> | |
| </svg> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Categories --> | |
| <section class="mb-8"> | |
| <h2 class="text-lg font-bold mb-4 text-gray-800">Browse Categories</h2> | |
| <div id="categoriesGrid" class="grid grid-cols-3 gap-3"> | |
| <!-- Categories will be loaded here --> | |
| </div> | |
| </section> | |
| <!-- Recently Added Jobs --> | |
| <section class="mb-8"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h2 class="text-lg font-bold text-gray-800">Recently Added</h2> | |
| <button id="viewAllJobs" class="text-indigo-600 hover:underline text-sm">View All</button> | |
| </div> | |
| <div id="recentJobsSlider" class="space-y-4"> | |
| <!-- Recent jobs will be loaded here --> | |
| </div> | |
| </section> | |
| <!-- All Jobs --> | |
| <section id="allJobsSection" class="mb-8"> | |
| <h2 class="text-lg font-bold mb-4 text-gray-800">All Jobs</h2> | |
| <div id="jobsList" class="space-y-4"> | |
| <!-- All jobs will be loaded here --> | |
| </div> | |
| <div class="mt-6 flex justify-center"> | |
| <button id="loadMoreBtn" class="px-4 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 hidden"> | |
| Load More | |
| </button> | |
| </div> | |
| </section> | |
| <!-- Bookmarks (for logged in users) --> | |
| <section id="bookmarksSection" class="mb-8 hidden"> | |
| <h2 class="text-lg font-bold mb-4 text-gray-800">My Bookmarks</h2> | |
| <div id="bookmarksList" class="space-y-4"> | |
| <!-- Bookmarks will be loaded here --> | |
| </div> | |
| </section> | |
| </main> | |
| <!-- Footer --> | |
| <footer class="bg-gray-800 text-white py-6"> | |
| <div class="container mx-auto px-4"> | |
| <div class="flex flex-col md:flex-row justify-between items-center"> | |
| <div class="mb-4 md:mb-0"> | |
| <h2 class="text-xl font-bold">JobHive</h2> | |
| <p class="text-gray-400 text-sm">Find your dream job today</p> | |
| </div> | |
| <div class="flex space-x-4"> | |
| <a href="#" class="hover:text-indigo-400"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="currentColor" viewBox="0 0 24 24"> | |
| <path d="M22.675 0h-21.35c-.732 0-1.325.593-1.325 1.325v21.351c0 .731.593 1.324 1.325 1.324h11.495v-9.294h-3.128v-3.622h3.128v-2.671c0-3.1 1.893-4.788 4.659-4.788 1.325 0 2.463.099 2.795.143v3.24l-1.918.001c-1.504 0-1.795.715-1.795 1.763v2.313h3.587l-.467 3.622h-3.12v9.293h6.116c.73 0 1.323-.593 1.323-1.325v-21.35c0-.732-.593-1.325-1.325-1.325z"/> | |
| </svg> | |
| </a> | |
| <a href="#" class="hover:text-indigo-400"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="currentColor" viewBox="0 0 24 24"> | |
| <path d="M24 4.557c-.883.392-1.832.656-2.828.775 1.017-.609 1.798-1.574 2.165-2.724-.951.564-2.005.974-3.127 1.195-.897-.957-2.178-1.555-3.594-1.555-3.179 0-5.515 2.966-4.797 6.045-4.091-.205-7.719-2.165-10.148-5.144-1.29 2.213-.669 5.108 1.523 6.574-.806-.026-1.566-.247-2.229-.616-.054 2.281 1.581 4.415 3.949 4.89-.693.188-1.452.232-2.224.084.626 1.956 2.444 3.379 4.6 3.419-2.07 1.623-4.678 2.348-7.29 2.04 2.179 1.397 4.768 2.212 7.548 2.212 9.142 0 14.307-7.721 13.995-14.646.962-.695 1.797-1.562 2.457-2.549z"/> | |
| </svg> | |
| </a> | |
| <a href="#" class="hover:text-indigo-400"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="currentColor" viewBox="0 0 24 24"> | |
| <path d="M19 0h-14c-2.761 0-5 2.239-5 5v14c0 2.761 2.239 5 5 5h14c2.762 0 5-2.239 5-5v-14c0-2.761-2.238-5-5-5zm-11 19h-3v-11h3v11zm-1.5-12.268c-.966 0-1.75-.79-1.75-1.764s.784-1.764 1.75-1.764 1.75.79 1.75 1.764-.783 1.764-1.75 1.764zm13.5 12.268h-3v-5.604c0-3.368-4-3.113-4 0v5.604h-3v-11h3v1.765c1.396-2.586 7-2.777 7 2.476v6.759z"/> | |
| </svg> | |
| </a> | |
| </div> | |
| </div> | |
| <div class="mt-6 pt-4 border-t border-gray-700 text-center text-gray-400 text-sm"> | |
| <p>© 2023 JobNest. All rights reserved.</p> | |
| </div> | |
| </div> | |
| </footer> | |
| <script> | |
| // Firebase configuration | |
| const firebaseConfig = { | |
| apiKey: "AIzaSyDEXAMPLEEXAMPLEEXAMPLE", | |
| authDomain: "your-project.firebaseapp.com", | |
| databaseURL: "https://your-project.firebaseio.com", | |
| projectId: "your-project", | |
| storageBucket: "your-project.appspot.com", | |
| messagingSenderId: "1234567890", | |
| appId: "1:1234567890:web:abcdef1234567890" | |
| }; | |
| // Initialize Firebase | |
| firebase.initializeApp(firebaseConfig); | |
| const auth = firebase.auth(); | |
| const database = firebase.database(); | |
| // DOM Elements | |
| const authBtn = document.getElementById('authBtn'); | |
| const authText = document.getElementById('authText'); | |
| const profileBtn = document.getElementById('profileBtn'); | |
| const authModal = document.getElementById('authModal'); | |
| const closeAuthModal = document.getElementById('closeAuthModal'); | |
| const loginFormContainer = document.getElementById('loginFormContainer'); | |
| const signupFormContainer = document.getElementById('signupFormContainer'); | |
| const showSignup = document.getElementById('showSignup'); | |
| const showLogin = document.getElementById('showLogin'); | |
| const loginBtn = document.getElementById('loginBtn'); | |
| const signupBtn = document.getElementById('signupBtn'); | |
| const profileModal = document.getElementById('profileModal'); | |
| const closeProfileModal = document.getElementById('closeProfileModal'); | |
| const profileName = document.getElementById('profileName'); | |
| const profileEmail = document.getElementById('profileEmail'); | |
| const logoutBtn = document.getElementById('logoutBtn'); | |
| const jobSearch = document.getElementById('jobSearch'); | |
| const categoriesGrid = document.getElementById('categoriesGrid'); | |
| const recentJobsSlider = document.getElementById('recentJobsSlider'); | |
| const jobsList = document.getElementById('jobsList'); | |
| const loadMoreBtn = document.getElementById('loadMoreBtn'); | |
| const viewAllJobs = document.getElementById('viewAllJobs'); | |
| const bookmarksSection = document.getElementById('bookmarksSection'); | |
| const bookmarksList = document.getElementById('bookmarksList'); | |
| // Auth State Listener | |
| auth.onAuthStateChanged((user) => { | |
| if (user) { | |
| authBtn.classList.add('hidden'); | |
| profileBtn.classList.remove('hidden'); | |
| database.ref('users/' + user.uid).once('value').then((snapshot) => { | |
| const userData = snapshot.val(); | |
| if (userData) { | |
| profileName.textContent = userData.name; | |
| profileEmail.textContent = user.email; | |
| } | |
| }); | |
| bookmarksSection.classList.remove('hidden'); | |
| loadBookmarks(user.uid); | |
| } else { | |
| authBtn.classList.remove('hidden'); | |
| profileBtn.classList.add('hidden'); | |
| bookmarksSection.classList.add('hidden'); | |
| authText.textContent = 'Login'; | |
| } | |
| }); | |
| // Toggle Auth Modal | |
| authBtn.addEventListener('click', () => { | |
| authModal.classList.remove('hidden'); | |
| loginFormContainer.classList.remove('hidden'); | |
| signupFormContainer.classList.add('hidden'); | |
| document.getElementById('authModalTitle').textContent = 'Login'; | |
| }); | |
| closeAuthModal.addEventListener('click', () => { | |
| authModal.classList.add('hidden'); | |
| }); | |
| // Toggle Profile Modal | |
| profileBtn.addEventListener('click', () => { | |
| profileModal.classList.remove('hidden'); | |
| }); | |
| closeProfileModal.addEventListener('click', () => { | |
| profileModal.classList.add('hidden'); | |
| }); | |
| // Toggle between Login and Signup forms | |
| showSignup.addEventListener('click', () => { | |
| loginFormContainer.classList.add('hidden'); | |
| signupFormContainer.classList.remove('hidden'); | |
| document.getElementById('authModalTitle').textContent = 'Sign Up'; | |
| }); | |
| showLogin.addEventListener('click', () => { | |
| signupFormContainer.classList.add('hidden'); | |
| loginFormContainer.classList.remove('hidden'); | |
| document.getElementById('authModalTitle').textContent = 'Login'; | |
| }); | |
| // Login Functionality | |
| loginBtn.addEventListener('click', () => { | |
| const email = document.getElementById('userEmail').value; | |
| const password = document.getElementById('userPassword').value; | |
| auth.signInWithEmailAndPassword(email, password) | |
| .then(() => { | |
| authModal.classList.add('hidden'); | |
| Swal.fire({ | |
| icon: 'success', | |
| title: 'Welcome back!', | |
| showConfirmButton: false, | |
| timer: 1500 | |
| }); | |
| }) | |
| .catch((error) => { | |
| Swal.fire({ | |
| icon: 'error', | |
| title: 'Login Failed', | |
| text: error.message | |
| }); | |
| }); | |
| }); | |
| // Signup Functionality | |
| signupBtn.addEventListener('click', () => { | |
| const name = document.getElementById('userName').value; | |
| const email = document.getElementById('signupEmail').value; | |
| const password = document.getElementById('signupPassword').value; | |
| auth.createUserWithEmailAndPassword(email, password) | |
| .then((userCredential) => { | |
| return database.ref('users/' + userCredential.user.uid).set({ | |
| name: name, | |
| email: email, | |
| createdAt: firebase.database.ServerValue.TIMESTAMP | |
| }); | |
| }) | |
| .then(() => { | |
| authModal.classList.add('hidden'); | |
| Swal.fire({ | |
| icon: 'success', | |
| title: 'Account created!', | |
| showConfirmButton: false, | |
| timer: 1500 | |
| }); | |
| }) | |
| .catch((error) => { | |
| Swal.fire({ | |
| icon: 'error', | |
| title: 'Signup Failed', | |
| text: error.message | |
| }); | |
| }); | |
| }); | |
| // Logout Functionality | |
| logoutBtn.addEventListener('click', () => { | |
| auth.signOut().then(() => { | |
| profileModal.classList.add('hidden'); | |
| Swal.fire({ | |
| icon: 'success', | |
| title: 'Logged out successfully!', | |
| showConfirmButton: false, | |
| timer: 1500 | |
| }); | |
| }); | |
| }); | |
| // Load Categories | |
| function loadCategories() { | |
| database.ref('categories').on('value', (snapshot) => { | |
| categoriesGrid.innerHTML = ''; | |
| snapshot.forEach((childSnapshot) => { | |
| const category = childSnapshot.val(); | |
| const categoryElement = document.createElement('div'); | |
| categoryElement.className = 'flex flex-col items-center category-icon'; | |
| categoryElement.innerHTML = ` | |
| <div class="w-16 h-16 rounded-full bg-white shadow-md flex items-center justify-center mb-1 overflow-hidden"> | |
| <img src="http://static.photos/technology/200x200/${Math.floor(Math.random() * 100)}" alt="${category.name}" class="w-12 h-12 rounded-full object-cover"> | |
| </div> | |
| <span class="text-xs text-center">${category.name}</span> | |
| `; | |
| categoryElement.addEventListener('click', () => { | |
| filterJobsByCategory(childSnapshot.key); | |
| }); | |
| categoriesGrid.appendChild(categoryElement); | |
| }); | |
| }); | |
| } | |
| // Load Recent Jobs | |
| function loadRecentJobs() { | |
| database.ref('jobs').limitToLast(5).on('value', (snapshot) => { | |
| recentJobsSlider.innerHTML = ''; | |
| snapshot.forEach((categorySnapshot) => { | |
| categorySnapshot.forEach((jobSnapshot) => { | |
| const job = jobSnapshot.val(); | |
| if (job.status === 'published') { | |
| const jobElement = createJobElement(job, categorySnapshot.key, jobSnapshot.key); | |
| recentJobsSlider.appendChild(jobElement); | |
| } | |
| }); | |
| }); | |
| }); | |
| } | |
| // Load All Jobs | |
| let jobsLimit = 5; | |
| function loadAllJobs() { | |
| database.ref('jobs').limitToFirst(jobsLimit).on('value', (snapshot) => { | |
| jobsList.innerHTML = ''; | |
| let jobsCount = 0; | |
| snapshot.forEach((categorySnapshot) => { | |
| categorySnapshot.forEach((jobSnapshot) => { | |
| const job = jobSnapshot.val(); | |
| if (job.status === 'published') { | |
| jobsCount++; | |
| const jobElement = createJobElement(job, categorySnapshot.key, jobSnapshot.key); | |
| jobsList.appendChild(jobElement); | |
| } | |
| }); | |
| }); | |
| if (jobsCount >= jobsLimit) { | |
| loadMoreBtn.classList.remove('hidden'); | |
| } else { | |
| loadMoreBtn.classList.add('hidden'); | |
| } | |
| }); | |
| } | |
| // Load More Jobs | |
| loadMoreBtn.addEventListener('click', () => { | |
| jobsLimit += 5; | |
| loadAllJobs(); | |
| }); | |
| // View All Jobs | |
| viewAllJobs.addEventListener('click', () => { | |
| jobsLimit = 5; | |
| loadAllJobs(); | |
| window.scrollTo({ | |
| top: document.getElementById('allJobsSection').offsetTop - 20, | |
| behavior: 'smooth' | |
| }); | |
| }); | |
| // Filter Jobs by Category | |
| function filterJobsByCategory(categoryId) { | |
| database.ref('categories/' + categoryId).once('value').then((categorySnapshot) => { | |
| const category = categorySnapshot.val(); | |
| if (category) { | |
| database.ref('jobs/' + categoryId).on('value', (jobsSnapshot) => { | |
| jobsList.innerHTML = `<h3 class="text-md font-semibold mb-3">Jobs in ${category.name}</h3>`; | |
| jobsSnapshot.forEach((jobSnapshot) => { | |
| const job = jobSnapshot.val(); | |
| if (job.status === 'published') { | |
| const jobElement = createJobElement(job, categoryId, jobSnapshot.key); | |
| jobsList.appendChild(jobElement); | |
| } | |
| }); | |
| }); | |
| } | |
| }); | |
| } | |
| // Search Jobs | |
| jobSearch.addEventListener('input', (e) => { | |
| const searchTerm = e.target.value.toLowerCase(); | |
| if (searchTerm.length > 2) { | |
| database.ref('jobs').once('value').then((snapshot) => { | |
| jobsList.innerHTML = ''; | |
| snapshot.forEach((categorySnapshot) => { | |
| categorySnapshot.forEach((jobSnapshot) => { | |
| const job = jobSnapshot.val(); | |
| if (job.status === 'published' && | |
| (job.title.toLowerCase().includes(searchTerm) || | |
| job.description.toLowerCase().includes(searchTerm))) { | |
| const jobElement = createJobElement(job, categorySnapshot.key, jobSnapshot.key); | |
| jobsList.appendChild(jobElement); | |
| } | |
| }); | |
| }); | |
| }); | |
| } else if (searchTerm.length === 0) { | |
| loadAllJobs(); | |
| } | |
| }); | |
| // Create Job Element | |
| function createJobElement(job, categoryId, jobId) { | |
| const jobElement = document.createElement('div'); | |
| jobElement.className = 'bg-white rounded-lg shadow p-4 job-card transition'; | |
| jobElement.innerHTML = ` | |
| <div class="flex gap-4"> | |
| <div class="flex-shrink-0"> | |
| <img src="http://static.photos/office/100x100/${Math.floor(Math.random() * 100)}" alt="${job.title}" class="w-16 h-16 rounded-md object-cover"> | |
| </div> | |
| <div class="flex-1"> | |
| <div class="flex justify-between items-start"> | |
| <div> | |
| <h3 class="font-bold">${job.title}</h3> | |
| <p class="text-xs text-gray-500 mb-1">${job.category}</p> | |
| <p class="text-sm text-gray-700 mb-2">${job.description.substring(0, 100)}...</p> | |
| </div> | |
| <button class="bookmark-btn p-1 text-gray-400 hover:text-yellow-500 transition" data-id="${jobId}" data-cat="${categoryId}"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z" /> | |
| </svg> | |
| </button> | |
| </div> | |
| <div class="flex justify-between items-center"> | |
| <a href="${job.link}" target="_blank" class="px-3 py-1 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 text-sm"> | |
| Apply Now | |
| </a> | |
| <span class="text-xs text-gray-500">Posted ${formatDate(job.createdAt)}</span> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| if (auth.currentUser) { | |
| const bookmarkBtn = jobElement.querySelector('.bookmark-btn'); | |
| bookmarkBtn.addEventListener('click', (e) => { | |
| e.preventDefault(); | |
| toggleBookmark(auth.currentUser.uid, jobId, categoryId); | |
| }); | |
| } | |
| return jobElement; | |
| } | |
| // Toggle Bookmark | |
| function toggleBookmark(userId, jobId, categoryId) { | |
| const bookmarkRef = database.ref(`bookmarks/${userId}/${jobId}`); | |
| bookmarkRef.once('value').then((snapshot) => { | |
| if (snapshot.exists()) { | |
| bookmarkRef.remove() | |
| .then(() => { | |
| Swal.fire({ | |
| icon: 'success', | |
| title: 'Removed from bookmarks', | |
| showConfirmButton: false, | |
| timer: 1000 | |
| }); | |
| loadBookmarks(userId); | |
| }); | |
| } else { | |
| database.ref(`jobs/${categoryId}/${jobId}`).once('value').then((jobSnapshot) => { | |
| const job = jobSnapshot.val(); | |
| bookmarkRef.set({ | |
| ...job, | |
| bookmarkedAt: firebase.database.ServerValue.TIMESTAMP | |
| }) | |
| .then(() => { | |
| Swal.fire({ | |
| icon: 'success', | |
| title: 'Added to bookmarks', | |
| showConfirmButton: false, | |
| timer: 1000 | |
| }); | |
| loadBookmarks(userId); | |
| }); | |
| }); | |
| } | |
| }); | |
| } | |
| // Load Bookmarks | |
| function loadBookmarks(userId) { | |
| database.ref(`bookmarks/${userId}`).on('value', (snapshot) => { | |
| bookmarksList.innerHTML = ''; | |
| if (!snapshot.exists()) { | |
| bookmarksList.innerHTML = '<p class="text-gray-500 text-sm">No bookmarks yet. Click the bookmark icon on any job to save it here.</p>'; | |
| return; | |
| } | |
| snapshot.forEach((jobSnapshot) => { | |
| const job = jobSnapshot.val(); | |
| const bookmarkElement = document.createElement('div'); | |
| bookmarkElement.className = 'bg-white rounded-lg shadow p-4 job-card transition'; | |
| bookmarkElement.innerHTML = ` | |
| <div class="flex gap-4"> | |
| <div class="flex-shrink-0"> | |
| <img src="http://static.photos/office/200x200/${Math.floor(Math.random() * 100)}" alt="${job.title}" class="w-20 h-20 rounded-md object-cover"> | |
| </div> | |
| <div class="flex-1"> | |
| <div class="flex justify-between items-start"> | |
| <div> | |
| <h3 class="font-bold">${job.title}</h3> | |
| <p class="text-xs text-gray-500 mb-1">${job.category}</p> | |
| <p class="text-sm text-gray-700 mb-2">${job.description.substring(0, 100)}...</p> | |
| </div> | |
| <button class="remove-bookmark p-1 text-yellow-500 hover:text-yellow-600 transition" data-id="${jobSnapshot.key}"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="currentColor" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z" /> | |
| </svg> | |
| </button> | |
| </div> | |
| <div class="flex justify-between items-center"> | |
| <a href="${job.link}" target="_blank" class="px-3 py-1 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 text-sm"> | |
| Apply Now | |
| </a> | |
| <span class="text-xs text-gray-500">Bookmarked ${formatDate(job.bookmarkedAt || job.createdAt)}</span> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| const removeBtn = bookmarkElement.querySelector('.remove-bookmark'); | |
| removeBtn.addEventListener('click', (e) => { | |
| e.preventDefault(); | |
| database.ref(`bookmarks/${userId}/${jobSnapshot.key}`).remove() | |
| .then(() => { | |
| loadBookmarks(userId); | |
| }); | |
| }); | |
| bookmarksList.appendChild(bookmarkElement); | |
| }); | |
| }); | |
| } | |
| // Format Date | |
| function formatDate(timestamp) { | |
| if (!timestamp) return 'recently'; | |
| const date = new Date(timestamp); | |
| const now = new Date(); | |
| const diff = now - date; | |
| const minute = 60 * 1000; | |
| const hour = 60 * minute; | |
| const day = 24 * hour; | |
| if (diff < minute) return 'just now'; | |
| if (diff < hour) return `${Math.floor(diff / minute)} minutes ago`; | |
| if (diff < day) return `${Math.floor(diff / hour)} hours ago`; | |
| return `${Math.floor(diff / day)} days ago`; | |
| } | |
| // Initialize | |
| loadCategories(); | |
| loadRecentJobs(); | |
| loadAllJobs(); | |
| </script> | |
| </body> | |
| </html> |