`;
};
// State for Jobs View
const jobsState = {
filter: 'All',
search: ''
};
// Global handlers for filter updates
window.updateJobFilter = (value) => {
jobsState.filter = value;
// Trigger re-render of current page
window.dispatchEvent(new Event('hashchange'));
};
window.updateJobSearch = (value) => {
jobsState.search = value.toLowerCase();
// Debounce re-render could be better, but simple re-render works for now
// We'll just re-render the table body via DOM manipulation ideally,
// but for simplicity with this router, we can re-trigger route or just rely on input keeping focus if we are careful.
// Re-rendering whole page loses focus.
// Better strategy: Store the value, but let the user press enter or wait.
// For now, let's just make the search work on 'onchange' or 'onkeyup' with a small re-render hack
// Actually, to avoid losing focus on every keystroke, let's just use the router re-render
// but we need to manage focus.
// Simplified approach: Just update state. The user has to trigger search?
// Or simpler: Just re-render. To keep input focus, we can select it after render.
const contentArea = document.getElementById('content-area');
// For this prototype, a full re-render is jarring.
// But let's stick to the request pattern.
window.dispatchEvent(new Event('hashchange'));
};
// Helper to keep focus helper (hacky but works for simple vanilla js SPA)
const restoreFocus = () => {
const searchInput = document.querySelector('#job-search-input');
if (searchInput) {
searchInput.focus();
// Move cursor to end
const val = searchInput.value;
searchInput.value = '';
searchInput.value = val;
}
}
const renderJobs = async () => {
const jobs = await Api.getRecentJobs();
const allJobs = [...jobs, ...jobs, ...jobs]; // Demo duplication
// Apply Filters
const filteredJobs = allJobs.filter(job => {
const matchesStatus = jobsState.filter === 'All' || job.status === jobsState.filter;
const matchesSearch = jobsState.search === '' ||
job.name.toLowerCase().includes(jobsState.search) ||
job.client.toLowerCase().includes(jobsState.search);
return matchesStatus && matchesSearch;
});
// Schedule focus restore after render
setTimeout(restoreFocus, 0);
return `