Spaces:
Build error
Build error
Update src/App.svelte
Browse files- src/App.svelte +180 -37
src/App.svelte
CHANGED
@@ -1,8 +1,5 @@
|
|
1 |
-
<!-- src/App.svelte -->
|
2 |
<script lang="ts">
|
3 |
import { onMount } from 'svelte';
|
4 |
-
import Card from './lib/Card.svelte';
|
5 |
-
import Chart from './lib/Chart.svelte';
|
6 |
|
7 |
let loading = true;
|
8 |
let error: string | null = null;
|
@@ -15,16 +12,13 @@
|
|
15 |
|
16 |
onMount(async () => {
|
17 |
try {
|
18 |
-
// Simulate API call
|
19 |
await new Promise(resolve => setTimeout(resolve, 1000));
|
20 |
-
|
21 |
stats = {
|
22 |
revenue: 124500,
|
23 |
users: 2341,
|
24 |
orders: 342,
|
25 |
conversion: 3.2
|
26 |
};
|
27 |
-
|
28 |
loading = false;
|
29 |
} catch (err) {
|
30 |
error = 'Failed to load dashboard data';
|
@@ -32,20 +26,170 @@
|
|
32 |
}
|
33 |
});
|
34 |
|
35 |
-
const formatCurrency = (amount: number) =>
|
36 |
-
|
37 |
style: 'currency',
|
38 |
currency: 'USD',
|
39 |
minimumFractionDigits: 0,
|
40 |
maximumFractionDigits: 0
|
41 |
}).format(amount);
|
42 |
-
};
|
43 |
|
44 |
-
const formatNumber = (num: number) =>
|
45 |
-
|
46 |
-
};
|
47 |
</script>
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
<main class="container">
|
50 |
<header>
|
51 |
<h1>Dashboard</h1>
|
@@ -63,35 +207,34 @@
|
|
63 |
</div>
|
64 |
{:else}
|
65 |
<section class="grid">
|
66 |
-
<
|
67 |
-
|
68 |
-
value
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
<
|
73 |
-
|
74 |
-
value
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
<
|
79 |
-
|
80 |
-
value
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
<
|
85 |
-
|
86 |
-
value
|
87 |
-
|
88 |
-
|
89 |
-
/>
|
90 |
</section>
|
91 |
|
92 |
<section class="chart-section">
|
93 |
<h2>Revenue Trend</h2>
|
94 |
-
<Chart
|
95 |
</section>
|
96 |
{/if}
|
97 |
</main>
|
|
|
|
|
1 |
<script lang="ts">
|
2 |
import { onMount } from 'svelte';
|
|
|
|
|
3 |
|
4 |
let loading = true;
|
5 |
let error: string | null = null;
|
|
|
12 |
|
13 |
onMount(async () => {
|
14 |
try {
|
|
|
15 |
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
16 |
stats = {
|
17 |
revenue: 124500,
|
18 |
users: 2341,
|
19 |
orders: 342,
|
20 |
conversion: 3.2
|
21 |
};
|
|
|
22 |
loading = false;
|
23 |
} catch (err) {
|
24 |
error = 'Failed to load dashboard data';
|
|
|
26 |
}
|
27 |
});
|
28 |
|
29 |
+
const formatCurrency = (amount: number) =>
|
30 |
+
new Intl.NumberFormat('en-US', {
|
31 |
style: 'currency',
|
32 |
currency: 'USD',
|
33 |
minimumFractionDigits: 0,
|
34 |
maximumFractionDigits: 0
|
35 |
}).format(amount);
|
|
|
36 |
|
37 |
+
const formatNumber = (num: number) =>
|
38 |
+
new Intl.NumberFormat('en-US').format(num);
|
|
|
39 |
</script>
|
40 |
|
41 |
+
<svelte:head>
|
42 |
+
<style>
|
43 |
+
:root {
|
44 |
+
--primary: #3b82f6;
|
45 |
+
--success: #10b981;
|
46 |
+
--danger: #ef4444;
|
47 |
+
--gray-50: #f9fafb;
|
48 |
+
--gray-100: #f3f4f6;
|
49 |
+
--gray-200: #e5e7eb;
|
50 |
+
--gray-300: #d1d5db;
|
51 |
+
--gray-400: #9ca3af;
|
52 |
+
--gray-500: #6b7280;
|
53 |
+
--gray-600: #4b5563;
|
54 |
+
--gray-700: #374151;
|
55 |
+
--gray-800: #1f2937;
|
56 |
+
--gray-900: #111827;
|
57 |
+
}
|
58 |
+
|
59 |
+
* { box-sizing: border-box; }
|
60 |
+
|
61 |
+
body {
|
62 |
+
margin: 0;
|
63 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
64 |
+
background-color: var(--gray-50);
|
65 |
+
color: var(--gray-900);
|
66 |
+
line-height: 1.5;
|
67 |
+
}
|
68 |
+
|
69 |
+
.container {
|
70 |
+
max-width: 1200px;
|
71 |
+
margin: 0 auto;
|
72 |
+
padding: 2rem 1rem;
|
73 |
+
}
|
74 |
+
|
75 |
+
header { margin-bottom: 2rem; }
|
76 |
+
|
77 |
+
h1 {
|
78 |
+
margin: 0;
|
79 |
+
font-size: 2rem;
|
80 |
+
font-weight: 700;
|
81 |
+
color: var(--gray-900);
|
82 |
+
}
|
83 |
+
|
84 |
+
.subtitle {
|
85 |
+
margin: 0.25rem 0 0;
|
86 |
+
color: var(--gray-600);
|
87 |
+
}
|
88 |
+
|
89 |
+
.grid {
|
90 |
+
display: grid;
|
91 |
+
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
92 |
+
gap: 1.5rem;
|
93 |
+
margin-bottom: 2rem;
|
94 |
+
}
|
95 |
+
|
96 |
+
.loading, .error {
|
97 |
+
display: flex;
|
98 |
+
flex-direction: column;
|
99 |
+
align-items: center;
|
100 |
+
justify-content: center;
|
101 |
+
min-height: 400px;
|
102 |
+
color: var(--gray-500);
|
103 |
+
}
|
104 |
+
|
105 |
+
.spinner {
|
106 |
+
width: 40px;
|
107 |
+
height: 40px;
|
108 |
+
border: 4px solid var(--gray-200);
|
109 |
+
border-top: 4px solid var(--primary);
|
110 |
+
border-radius: 50%;
|
111 |
+
animation: spin 1s linear infinite;
|
112 |
+
}
|
113 |
+
|
114 |
+
@keyframes spin {
|
115 |
+
0% { transform: rotate(0deg); }
|
116 |
+
100% { transform: rotate(360deg); }
|
117 |
+
}
|
118 |
+
|
119 |
+
.error { color: var(--danger); }
|
120 |
+
|
121 |
+
.card {
|
122 |
+
background: white;
|
123 |
+
border-radius: 0.5rem;
|
124 |
+
padding: 1.5rem;
|
125 |
+
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
|
126 |
+
transition: box-shadow 0.15s;
|
127 |
+
}
|
128 |
+
|
129 |
+
.card:hover {
|
130 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
131 |
+
}
|
132 |
+
|
133 |
+
.card-title {
|
134 |
+
margin: 0 0 0.5rem;
|
135 |
+
font-size: 0.875rem;
|
136 |
+
font-weight: 500;
|
137 |
+
color: var(--gray-600);
|
138 |
+
text-transform: uppercase;
|
139 |
+
letter-spacing: 0.05em;
|
140 |
+
}
|
141 |
+
|
142 |
+
.card-value {
|
143 |
+
margin: 0;
|
144 |
+
font-size: 1.875rem;
|
145 |
+
font-weight: 700;
|
146 |
+
color: var(--gray-900);
|
147 |
+
}
|
148 |
+
|
149 |
+
.card-change {
|
150 |
+
margin-top: 0.5rem;
|
151 |
+
font-size: 0.875rem;
|
152 |
+
font-weight: 500;
|
153 |
+
}
|
154 |
+
|
155 |
+
.positive { color: var(--success); }
|
156 |
+
.negative { color: var(--danger); }
|
157 |
+
|
158 |
+
.chart-section {
|
159 |
+
background: white;
|
160 |
+
border-radius: 0.5rem;
|
161 |
+
padding: 1.5rem;
|
162 |
+
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
|
163 |
+
}
|
164 |
+
|
165 |
+
.chart-section h2 {
|
166 |
+
margin: 0 0 1rem;
|
167 |
+
font-size: 1.25rem;
|
168 |
+
font-weight: 600;
|
169 |
+
color: var(--gray-900);
|
170 |
+
}
|
171 |
+
|
172 |
+
.chart-placeholder {
|
173 |
+
width: 100%;
|
174 |
+
height: 200px;
|
175 |
+
background: var(--gray-100);
|
176 |
+
border: 2px dashed var(--gray-300);
|
177 |
+
border-radius: 0.5rem;
|
178 |
+
display: flex;
|
179 |
+
align-items: center;
|
180 |
+
justify-content: center;
|
181 |
+
color: var(--gray-500);
|
182 |
+
font-size: 1rem;
|
183 |
+
}
|
184 |
+
|
185 |
+
@media (max-width: 640px) {
|
186 |
+
.container { padding: 1rem; }
|
187 |
+
h1 { font-size: 1.5rem; }
|
188 |
+
.grid { grid-template-columns: 1fr; }
|
189 |
+
}
|
190 |
+
</style>
|
191 |
+
</svelte:head>
|
192 |
+
|
193 |
<main class="container">
|
194 |
<header>
|
195 |
<h1>Dashboard</h1>
|
|
|
207 |
</div>
|
208 |
{:else}
|
209 |
<section class="grid">
|
210 |
+
<div class="card">
|
211 |
+
<h3 class="card-title">Revenue</h3>
|
212 |
+
<p class="card-value">{formatCurrency(stats.revenue)}</p>
|
213 |
+
<p class="card-change positive">+12.5%</p>
|
214 |
+
</div>
|
215 |
+
|
216 |
+
<div class="card">
|
217 |
+
<h3 class="card-title">Active Users</h3>
|
218 |
+
<p class="card-value">{formatNumber(stats.users)}</p>
|
219 |
+
<p class="card-change positive">+5.2%</p>
|
220 |
+
</div>
|
221 |
+
|
222 |
+
<div class="card">
|
223 |
+
<h3 class="card-title">Orders</h3>
|
224 |
+
<p class="card-value">{formatNumber(stats.orders)}</p>
|
225 |
+
<p class="card-change negative">-2.4%</p>
|
226 |
+
</div>
|
227 |
+
|
228 |
+
<div class="card">
|
229 |
+
<h3 class="card-title">Conversion</h3>
|
230 |
+
<p class="card-value">{stats.conversion}%</p>
|
231 |
+
<p class="card-change positive">+0.3%</p>
|
232 |
+
</div>
|
|
|
233 |
</section>
|
234 |
|
235 |
<section class="chart-section">
|
236 |
<h2>Revenue Trend</h2>
|
237 |
+
<div class="chart-placeholder">Chart placeholder</div>
|
238 |
</section>
|
239 |
{/if}
|
240 |
</main>
|