feat: add frontend setup with Tailwind CSS

This commit is contained in:
eligrinfeld
2025-01-06 21:25:03 -07:00
parent 7fa0e9dd9d
commit 79f26fce25
28 changed files with 6724 additions and 520 deletions

View File

@ -1,557 +1,213 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" class="h-full bg-gray-50">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OffMarket Pro - Find Off-Market Property Services</title>
<style>
:root {
--primary-color: #2c3e50;
--secondary-color: #3498db;
--accent-color: #e74c3c;
--background-color: #f8f9fa;
--text-color: #2c3e50;
--border-radius: 8px;
--card-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
body {
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
margin: 0;
padding: 0;
background: var(--background-color);
color: var(--text-color);
}
.header {
background: white;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
padding: 1rem;
}
.logo {
font-size: 1.8rem;
font-weight: bold;
color: var(--primary-color);
text-decoration: none;
}
.search-container {
max-width: 1200px;
margin: 3rem auto;
padding: 2rem;
text-align: center;
}
.search-box {
display: flex;
gap: 1rem;
max-width: 800px;
margin: 2rem auto;
}
.search-input {
flex: 1;
padding: 1rem;
border: 2px solid #ddd;
border-radius: var(--border-radius);
font-size: 1rem;
}
.search-button {
padding: 1rem 2rem;
background: var(--secondary-color);
color: white;
border: none;
border-radius: var(--border-radius);
cursor: pointer;
font-size: 1rem;
transition: background 0.2s;
}
.search-button:hover {
background: #2980b9;
}
.categories-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1.5rem;
margin: 2rem auto;
max-width: 1200px;
padding: 0 1rem;
}
.category-card {
background: white;
border-radius: var(--border-radius);
padding: 1.5rem;
box-shadow: var(--card-shadow);
transition: transform 0.2s;
cursor: pointer;
}
.category-card:hover {
transform: translateY(-2px);
}
.category-icon {
font-size: 2rem;
margin-bottom: 1rem;
}
.subcategories {
margin-top: 1rem;
font-size: 0.9rem;
}
.subcategory {
color: var(--secondary-color);
cursor: pointer;
margin: 0.25rem 0;
}
.subcategory:hover {
text-decoration: underline;
}
.results-container {
max-width: 1200px;
margin: 2rem auto;
padding: 0 1rem;
}
.business-card {
background: white;
padding: 1.5rem;
margin-bottom: 1rem;
border-radius: var(--border-radius);
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
display: grid;
grid-template-columns: auto 1fr auto;
gap: 1.5rem;
align-items: start;
}
.business-logo {
width: 80px;
height: 80px;
object-fit: cover;
border-radius: var(--border-radius);
}
.business-info h3 {
margin: 0 0 0.5rem 0;
color: var(--primary-color);
}
.business-contact {
text-align: right;
}
.rating-stars {
color: #f1c40f;
margin-bottom: 0.5rem;
}
@media (max-width: 768px) {
.search-box {
flex-direction: column;
}
.business-card {
grid-template-columns: 1fr;
text-align: center;
}
.business-contact {
text-align: center;
}
.business-logo {
margin: 0 auto;
}
}
.loading {
text-align: center;
padding: 2rem;
color: var(--text-color);
}
.error-message {
background: #fee;
border: 1px solid #fcc;
padding: 1rem;
border-radius: var(--border-radius);
text-align: center;
}
.no-results {
background: #f8f9fa;
padding: 2rem;
border-radius: var(--border-radius);
text-align: center;
}
.no-results ul {
text-align: left;
display: inline-block;
margin: 1rem auto;
}
.results-table {
width: 100%;
border-collapse: collapse;
margin-top: 2rem;
background: white;
box-shadow: var(--card-shadow);
border-radius: var(--border-radius);
overflow: hidden;
}
.results-table th {
background: #f8f9fa;
padding: 1rem;
text-align: left;
font-weight: 600;
color: var(--primary-color);
border-bottom: 2px solid #eee;
}
.results-table td {
padding: 1rem;
border-bottom: 1px solid #eee;
vertical-align: top;
}
.business-icon {
width: 50px;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
background: #f0f0f0;
border-radius: var(--border-radius);
font-size: 1.5rem;
color: var(--primary-color);
}
.business-info {
display: flex;
gap: 1rem;
align-items: start;
}
.business-details h3 {
margin: 0 0 0.5rem 0;
color: var(--primary-color);
}
.business-meta {
font-size: 0.9rem;
color: #666;
}
.rating {
display: flex;
align-items: center;
gap: 0.25rem;
color: #f39c12;
}
.contact-info {
text-align: right;
white-space: nowrap;
}
.phone {
font-weight: 600;
color: var(--primary-color);
margin-bottom: 0.25rem;
}
.address {
color: #666;
font-size: 0.9rem;
}
.action-buttons {
display: flex;
gap: 0.5rem;
justify-content: flex-end;
}
.action-button {
padding: 0.5rem 1rem;
border: none;
border-radius: var(--border-radius);
cursor: pointer;
font-size: 0.9rem;
}
.primary-button {
background: var(--secondary-color);
color: white;
}
.secondary-button {
background: #eee;
color: var(--text-color);
}
</style>
<title>OffMarket Pro - Business Search</title>
<link href="/styles/output.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
</head>
<body>
<header class="header">
<a href="/" class="logo">OffMarket Pro</a>
</header>
<body class="min-h-full">
<div class="bg-white">
<!-- Navigation -->
<nav class="bg-white shadow-sm">
<div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
<div class="flex h-16 justify-between items-center">
<div class="flex-shrink-0 flex items-center">
<h1 class="text-xl font-bold text-gray-900">OffMarket Pro</h1>
</div>
</div>
</div>
</nav>
<div class="search-container">
<h1>Find Off-Market Property Services</h1>
<div class="search-box">
<input type="text" id="searchQuery" placeholder="What service are you looking for?">
<input type="text" id="searchLocation" placeholder="Location">
<button onclick="performSearch()">Search</button>
</div>
</div>
<!-- Main Content -->
<main class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8 py-8">
<!-- Search Form -->
<div class="mb-8">
<h2 class="text-2xl font-bold text-gray-900 mb-6">Find Off-Market Property Services</h2>
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
<div>
<label for="searchQuery" class="block text-sm font-medium text-gray-700">Service Type</label>
<input type="text" id="searchQuery" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-primary focus:ring-primary sm:text-sm" placeholder="e.g. plumber, electrician">
</div>
<div>
<label for="searchLocation" class="block text-sm font-medium text-gray-700">Location</label>
<input type="text" id="searchLocation" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-primary focus:ring-primary sm:text-sm" placeholder="e.g. Denver, CO">
</div>
</div>
<div class="mt-4">
<button onclick="performSearch()" class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-primary hover:bg-primary-hover focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary">
Search
</button>
</div>
</div>
<div class="categories-grid">
<!-- Categories will be dynamically inserted here -->
</div>
<!-- Progress Indicator -->
<div id="searchProgress" class="hidden mb-8">
<div class="bg-white shadow sm:rounded-lg">
<div class="px-4 py-5 sm:p-6">
<h3 class="text-lg font-medium leading-6 text-gray-900">Search Progress</h3>
<div class="mt-4">
<div class="relative pt-1">
<div class="overflow-hidden h-2 mb-4 text-xs flex rounded bg-gray-200">
<div id="progressBar" class="shadow-none flex flex-col text-center whitespace-nowrap text-white justify-center bg-primary transition-all duration-500" style="width: 0%"></div>
</div>
<div id="progressText" class="text-sm text-gray-600"></div>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<table class="results-table">
<thead>
<tr>
<th style="width: 50%">Business</th>
<th style="width: 30%">Contact</th>
<th style="width: 20%">Actions</th>
</tr>
</thead>
<tbody id="resultsBody">
<!-- Results will be populated here -->
</tbody>
</table>
<div id="searchProgress" class="search-progress"></div>
<!-- Error Display -->
<div id="errorDisplay" class="hidden mb-8">
<div class="rounded-md bg-red-50 p-4">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-red-400" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/>
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-red-800">Error</h3>
<div class="mt-2 text-sm text-red-700">
<p id="errorMessage"></p>
</div>
</div>
</div>
</div>
</div>
<!-- Results Table -->
<div id="resultsContainer" class="hidden">
<div class="bg-white shadow overflow-hidden sm:rounded-lg">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg leading-6 font-medium text-gray-900">Search Results</h3>
</div>
<div class="border-t border-gray-200">
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Business</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Contact</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody id="resultsBody" class="bg-white divide-y divide-gray-200">
<!-- Results will be inserted here -->
</tbody>
</table>
</div>
</div>
</div>
</div>
</main>
</div>
<script>
// Load categories
fetch('/api/categories')
.then(response => response.json())
.then(categories => {
const grid = document.querySelector('.categories-grid');
grid.innerHTML = categories.map(category => `
<div class="category-card" onclick="searchCategory('${category.name}')">
<div class="category-icon">${category.icon}</div>
<h3>${category.name}</h3>
<div class="subcategories">
${category.subcategories.map(sub =>
`<div class="subcategory" onclick="event.stopPropagation(); searchSubcategory('${sub.name}')">${sub.name}</div>`
).join('')}
</div>
</div>
`).join('');
});
class SearchProgress {
constructor() {
this.progressBar = document.getElementById('progressBar');
this.progressText = document.getElementById('progressText');
this.container = document.getElementById('searchProgress');
}
show() {
this.container.classList.remove('hidden');
this.setProgress(0, 'Starting search...');
}
hide() {
this.container.classList.add('hidden');
}
setProgress(percent, message) {
this.progressBar.style.width = `${percent}%`;
this.progressText.textContent = message;
}
showError(message) {
this.setProgress(100, `Error: ${message}`);
this.progressBar.classList.remove('bg-primary');
this.progressBar.classList.add('bg-red-500');
}
}
async function performSearch() {
const query = document.getElementById('searchQuery').value;
const location = document.getElementById('searchLocation').value;
if (!query || !location) {
alert('Please enter both search query and location');
showError('Please enter both search query and location');
return;
}
await doSearch(query, location);
}
const progress = new SearchProgress();
progress.show();
function searchCategory(category) {
const location = document.getElementById('searchLocation').value;
if (!location) {
alert('Please enter a location first');
return;
}
document.getElementById('searchQuery').value = category;
performSearch();
}
// Add searchSubcategory function
function searchSubcategory(subcategory) {
const location = document.getElementById('searchLocation').value;
if (!location) {
alert('Please enter a location first');
return;
}
document.getElementById('searchQuery').value = subcategory;
performSearch();
}
// Update doSearch function
async function doSearch(query, location) {
const searchTerm = `${query} in ${location}`;
const resultsBody = document.getElementById('resultsBody');
const progressDiv = document.getElementById('searchProgress');
try {
resultsBody.innerHTML = `
<tr>
<td colspan="3" class="loading">
<p>Searching for ${query} in ${location}...</p>
</td>
</tr>
`;
document.getElementById('errorDisplay').classList.add('hidden');
document.getElementById('resultsContainer').classList.add('hidden');
const response = await fetch(`/api/search?q=${encodeURIComponent(searchTerm)}`);
const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
let allResults = new Set(); // Use Set to avoid duplicates
const response = await fetch('/api/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query, location })
});
while (true) {
const { value, done } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
// Process complete chunks
const chunks = buffer.split('\n');
buffer = chunks.pop() || ''; // Keep the incomplete chunk
const data = await response.json();
for (const chunk of chunks) {
if (!chunk.trim()) continue;
try {
const data = JSON.parse(chunk);
console.log('Received chunk:', data);
if (data.source === 'database' || (data.source === 'search' && data.results)) {
// Add new results to our set
data.results.forEach(result => {
allResults.add(JSON.stringify(result)); // Convert to string for Set storage
});
// Display all current results
displayResults(Array.from(allResults).map(str => JSON.parse(str)));
} else if (data.status && data.progress) {
// Update progress
progressDiv.innerHTML = `
<p>${data.status} (${data.progress}% complete)</p>
`;
}
} catch (e) {
console.error('Error parsing chunk:', e);
}
}
if (!data.success) {
throw new Error(data.error || 'Search failed');
}
// Clear progress when done
progressDiv.innerHTML = '';
displayResults(data.results);
progress.hide();
} catch (error) {
console.error('Search error:', error);
resultsBody.innerHTML = `
<tr>
<td colspan="3" class="error-message">
<h3>Search Error</h3>
<p>Sorry, we encountered an error while searching. Please try again.</p>
<p>Error details: ${error.message}</p>
<button onclick="performSearch()" class="search-button">Try Again</button>
</td>
</tr>
`;
progress.showError(error.message);
showError(error.message);
}
}
function displayResults(businesses) {
const resultsBody = document.getElementById('resultsBody');
function showError(message) {
const errorDisplay = document.getElementById('errorDisplay');
const errorMessage = document.getElementById('errorMessage');
errorMessage.textContent = message;
errorDisplay.classList.remove('hidden');
}
function displayResults(results) {
const container = document.getElementById('resultsContainer');
const tbody = document.getElementById('resultsBody');
if (!businesses || businesses.length === 0) {
resultsBody.innerHTML = `
<tr>
<td colspan="3" style="text-align: center; padding: 2rem;">
<h3>No Results Found</h3>
<p>We couldn't find any businesses matching your search.</p>
</td>
</tr>
`;
return;
}
tbody.innerHTML = results.map(business => `
<tr>
<td class="px-6 py-4">
<div class="text-sm font-medium text-gray-900">${business.name}</div>
<div class="text-sm text-gray-500">${business.description}</div>
</td>
<td class="px-6 py-4">
<div class="text-sm text-gray-900">${business.address}</div>
<div class="text-sm text-gray-500">${business.phone}</div>
</td>
<td class="px-6 py-4">
${business.website ?
`<a href="${business.website}" target="_blank"
class="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-white bg-primary hover:bg-primary-hover focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary">
Visit Website
</a>` :
'<span class="text-sm text-gray-500">No website available</span>'
}
</td>
</tr>
`).join('');
resultsBody.innerHTML = businesses.map(business => {
const icon = getBusinessIcon(business.name);
const rating = business.rating ? (business.rating / 20).toFixed(1) : 0; // Convert to 5-star scale
return `
<tr>
<td>
<div class="business-info">
<div class="business-icon">${icon}</div>
<div class="business-details">
<h3>${business.name}</h3>
<div class="business-meta">
<div class="rating">
${getRatingStars(rating)}
<span>(${rating})</span>
</div>
<div class="description">${business.description || ''}</div>
</div>
</div>
</div>
</td>
<td>
<div class="contact-info">
<div class="phone">${business.phone || 'No phone available'}</div>
<div class="address">${business.address || 'Address not available'}</div>
</div>
</td>
<td>
<div class="action-buttons">
${business.website ?
`<a href="${business.website}" target="_blank" class="action-button primary-button">Visit Website</a>` :
'<button class="action-button secondary-button" disabled>No Website</button>'
}
<button onclick="contactBusiness('${business.id}')" class="action-button secondary-button">Contact</button>
</div>
</td>
</tr>
`;
}).join('');
}
// Helper function to get business icon
function getBusinessIcon(businessName) {
// Map of business types to icons
const icons = {
'real estate': '🏢',
'legal': '⚖️',
'financial': '💰',
'contractor': '🔨',
'property': '🏠',
'marketing': '📢',
'tech': '💻',
'default': '🏢'
};
// Determine business type from name
const businessType = Object.keys(icons).find(type =>
businessName.toLowerCase().includes(type)
) || 'default';
return icons[businessType];
}
// Helper function to generate rating stars
function getRatingStars(rating) {
const fullStars = Math.floor(rating);
const hasHalfStar = rating % 1 >= 0.5;
const emptyStars = 5 - fullStars - (hasHalfStar ? 1 : 0);
return `
${'★'.repeat(fullStars)}
${hasHalfStar ? '½' : ''}
${'☆'.repeat(emptyStars)}
`;
container.classList.remove('hidden');
}
</script>
</body>