Spaces:
Sleeping
Sleeping
Update static/ui/index.html
Browse files- static/ui/index.html +12 -5
static/ui/index.html
CHANGED
@@ -5,10 +5,10 @@
|
|
5 |
<meta charset="UTF-8">
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
<title>Electronics Store</title>
|
8 |
-
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
9 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
|
10 |
-
<link href="https://cdn.jsdelivr.net/npm/@tailwindcss/typography/dist/typography.min.css" rel="stylesheet">
|
11 |
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
|
|
|
12 |
</head>
|
13 |
<body class="bg-gray-100">
|
14 |
<div id="app" class="container mx-auto px-4 py-8">
|
@@ -18,7 +18,7 @@
|
|
18 |
<div class="mb-6 flex gap-4">
|
19 |
<select v-model="selectedCategory" class="p-2 border rounded-lg">
|
20 |
<option value="">All Categories</option>
|
21 |
-
<option v-for="category in categories" :value="category">{{ category }}</option>
|
22 |
</select>
|
23 |
|
24 |
<select v-model="sortBy" class="p-2 border rounded-lg">
|
@@ -31,6 +31,7 @@
|
|
31 |
<!-- Products Grid -->
|
32 |
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
33 |
<div v-for="product in filteredProducts"
|
|
|
34 |
class="bg-white rounded-lg shadow-md p-6 hover:shadow-lg transition-shadow">
|
35 |
<h2 class="text-xl font-semibold mb-2">{{ product.name }}</h2>
|
36 |
<div class="text-sm text-gray-600 mb-4">Category: {{ product.category }}</div>
|
@@ -38,7 +39,7 @@
|
|
38 |
<div class="mb-4">
|
39 |
<h3 class="font-semibold mb-2">Specifications:</h3>
|
40 |
<ul class="text-sm">
|
41 |
-
<li v-for="(value, key) in product.specs" class="mb-1">
|
42 |
{{ key }}: {{ value }}
|
43 |
</li>
|
44 |
</ul>
|
@@ -71,13 +72,19 @@
|
|
71 |
// Fetch products from API
|
72 |
fetch('/api/electronics/products')
|
73 |
.then(response => response.json())
|
74 |
-
.then(data =>
|
|
|
|
|
|
|
75 |
|
76 |
const categories = computed(() => {
|
|
|
77 |
return [...new Set(products.value.map(p => p.category))]
|
78 |
})
|
79 |
|
80 |
const filteredProducts = computed(() => {
|
|
|
|
|
81 |
let filtered = [...products.value]
|
82 |
|
83 |
if (selectedCategory.value) {
|
|
|
5 |
<meta charset="UTF-8">
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
<title>Electronics Store</title>
|
8 |
+
<script src="https://unpkg.com/vue@3.3.4/dist/vue.global.prod.js"></script>
|
9 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
|
|
|
10 |
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
|
11 |
+
<link href="https://cdn.jsdelivr.net/npm/@tailwindcss/typography/dist/typography.min.css" rel="stylesheet">
|
12 |
</head>
|
13 |
<body class="bg-gray-100">
|
14 |
<div id="app" class="container mx-auto px-4 py-8">
|
|
|
18 |
<div class="mb-6 flex gap-4">
|
19 |
<select v-model="selectedCategory" class="p-2 border rounded-lg">
|
20 |
<option value="">All Categories</option>
|
21 |
+
<option v-for="category in categories" :key="category" :value="category">{{ category }}</option>
|
22 |
</select>
|
23 |
|
24 |
<select v-model="sortBy" class="p-2 border rounded-lg">
|
|
|
31 |
<!-- Products Grid -->
|
32 |
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
33 |
<div v-for="product in filteredProducts"
|
34 |
+
:key="product.id"
|
35 |
class="bg-white rounded-lg shadow-md p-6 hover:shadow-lg transition-shadow">
|
36 |
<h2 class="text-xl font-semibold mb-2">{{ product.name }}</h2>
|
37 |
<div class="text-sm text-gray-600 mb-4">Category: {{ product.category }}</div>
|
|
|
39 |
<div class="mb-4">
|
40 |
<h3 class="font-semibold mb-2">Specifications:</h3>
|
41 |
<ul class="text-sm">
|
42 |
+
<li v-for="(value, key) in product.specs" :key="key" class="mb-1">
|
43 |
{{ key }}: {{ value }}
|
44 |
</li>
|
45 |
</ul>
|
|
|
72 |
// Fetch products from API
|
73 |
fetch('/api/electronics/products')
|
74 |
.then(response => response.json())
|
75 |
+
.then(data => {
|
76 |
+
products.value = data.products || []
|
77 |
+
})
|
78 |
+
.catch(error => console.error('Error fetching products:', error))
|
79 |
|
80 |
const categories = computed(() => {
|
81 |
+
if (!products.value || !products.value.length) return []
|
82 |
return [...new Set(products.value.map(p => p.category))]
|
83 |
})
|
84 |
|
85 |
const filteredProducts = computed(() => {
|
86 |
+
if (!products.value || !products.value.length) return []
|
87 |
+
|
88 |
let filtered = [...products.value]
|
89 |
|
90 |
if (selectedCategory.value) {
|