Spaces:
Build error
Build error
Upload src/App.svelte with huggingface_hub
Browse files- src/App.svelte +134 -41
src/App.svelte
CHANGED
@@ -1,47 +1,140 @@
|
|
|
|
1 |
<script lang="ts">
|
2 |
-
import
|
3 |
-
import
|
4 |
-
import
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
</a>
|
15 |
-
</div>
|
16 |
-
<h1>Vite + Svelte</h1>
|
17 |
-
|
18 |
-
<div class="card">
|
19 |
-
<Counter />
|
20 |
-
</div>
|
21 |
-
|
22 |
-
<p>
|
23 |
-
Check out <a href="https://github.com/sveltejs/kit#readme" target="_blank" rel="noreferrer">SvelteKit</a>, the official Svelte app framework powered by Vite!
|
24 |
-
</p>
|
25 |
-
|
26 |
-
<p class="read-the-docs">
|
27 |
-
Click on the Vite and Svelte logos to learn more
|
28 |
-
</p>
|
29 |
-
</main>
|
30 |
-
|
31 |
-
<style>
|
32 |
-
.logo {
|
33 |
-
height: 6em;
|
34 |
-
padding: 1.5em;
|
35 |
-
will-change: filter;
|
36 |
-
transition: filter 300ms;
|
37 |
}
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
43 |
}
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
46 |
}
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!-- src/App.svelte -->
|
2 |
<script lang="ts">
|
3 |
+
import { onMount } from 'svelte';
|
4 |
+
import EmailCard from './lib/EmailCard.svelte';
|
5 |
+
import LoadingSpinner from './lib/LoadingSpinner.svelte';
|
6 |
+
import ErrorMessage from './lib/ErrorMessage.svelte';
|
7 |
|
8 |
+
interface Email {
|
9 |
+
id: string;
|
10 |
+
from: string;
|
11 |
+
subject: string;
|
12 |
+
body: string;
|
13 |
+
date: string;
|
14 |
+
snippet: string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
}
|
16 |
+
|
17 |
+
let emails: Email[] = [];
|
18 |
+
let currentIndex = 0;
|
19 |
+
let loading = true;
|
20 |
+
let error: string | null = null;
|
21 |
+
|
22 |
+
async function fetchEmails() {
|
23 |
+
try {
|
24 |
+
loading = true;
|
25 |
+
error = null;
|
26 |
+
|
27 |
+
// Simulated Gmail API response
|
28 |
+
// In a real app, you would use Google's Gmail API
|
29 |
+
const mockEmails: Email[] = [
|
30 |
+
{
|
31 |
+
id: '1',
|
32 |
+
from: 'GitHub <[email protected]>',
|
33 |
+
subject: 'New pull request created',
|
34 |
+
body: 'A new pull request has been created in the repository. Please review the changes and provide feedback.',
|
35 |
+
date: '2024-01-15 10:30 AM',
|
36 |
+
snippet: 'A new pull request has been created...'
|
37 |
+
},
|
38 |
+
{
|
39 |
+
id: '2',
|
40 |
+
from: 'Netflix <[email protected]>',
|
41 |
+
subject: 'New releases this week',
|
42 |
+
body: 'Discover the latest movies and TV shows added to Netflix this week. Don\'t miss out on the trending titles!',
|
43 |
+
date: '2024-01-15 9:15 AM',
|
44 |
+
snippet: 'Discover the latest movies and TV shows...'
|
45 |
+
},
|
46 |
+
{
|
47 |
+
id: '3',
|
48 |
+
from: 'Amazon <[email protected]>',
|
49 |
+
subject: 'Your order has been shipped',
|
50 |
+
body: 'Your package is on the way! Track your order #12345-ABCD-67890 and see the estimated delivery date.',
|
51 |
+
date: '2024-01-15 8:45 AM',
|
52 |
+
snippet: 'Your package is on the way! Track your order...'
|
53 |
+
},
|
54 |
+
{
|
55 |
+
id: '4',
|
56 |
+
from: 'LinkedIn <[email protected]>',
|
57 |
+
subject: 'You have 3 new connection requests',
|
58 |
+
body: 'Expand your professional network by connecting with these 3 people who have requested to connect with you.',
|
59 |
+
date: '2024-01-14 6:20 PM',
|
60 |
+
snippet: 'Expand your professional network...'
|
61 |
+
}
|
62 |
+
];
|
63 |
+
|
64 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
65 |
+
emails = mockEmails;
|
66 |
+
|
67 |
+
} catch (err) {
|
68 |
+
error = 'Failed to load emails. Please check your connection and try again.';
|
69 |
+
} finally {
|
70 |
+
loading = false;
|
71 |
+
}
|
72 |
}
|
73 |
+
|
74 |
+
function nextEmail() {
|
75 |
+
if (currentIndex < emails.length - 1) {
|
76 |
+
currentIndex++;
|
77 |
+
}
|
78 |
}
|
79 |
+
|
80 |
+
function previousEmail() {
|
81 |
+
if (currentIndex > 0) {
|
82 |
+
currentIndex--;
|
83 |
+
}
|
84 |
}
|
85 |
+
|
86 |
+
onMount(() => {
|
87 |
+
fetchEmails();
|
88 |
+
});
|
89 |
+
</script>
|
90 |
+
|
91 |
+
<main>
|
92 |
+
<header>
|
93 |
+
<h1>Gmail Reader</h1>
|
94 |
+
<button
|
95 |
+
class="refresh-btn"
|
96 |
+
on:click={fetchEmails}
|
97 |
+
disabled={loading}
|
98 |
+
aria-label="Refresh emails"
|
99 |
+
>
|
100 |
+
↻ Refresh
|
101 |
+
</button>
|
102 |
+
</header>
|
103 |
+
|
104 |
+
{#if loading}
|
105 |
+
<LoadingSpinner />
|
106 |
+
{:else if error}
|
107 |
+
<ErrorMessage {error} onRetry={fetchEmails} />
|
108 |
+
{:else if emails.length === 0}
|
109 |
+
<div class="empty-state">
|
110 |
+
<h2>No emails found</h2>
|
111 |
+
<p>Your inbox is empty. Check back later!</p>
|
112 |
+
</div>
|
113 |
+
{:else}
|
114 |
+
<div class="email-container">
|
115 |
+
<EmailCard email={emails[currentIndex]} />
|
116 |
+
|
117 |
+
<div class="navigation">
|
118 |
+
<button
|
119 |
+
on:click={previousEmail}
|
120 |
+
disabled={currentIndex === 0}
|
121 |
+
aria-label="Previous email"
|
122 |
+
>
|
123 |
+
← Previous
|
124 |
+
</button>
|
125 |
+
|
126 |
+
<span class="counter">
|
127 |
+
{currentIndex + 1} of {emails.length}
|
128 |
+
</span>
|
129 |
+
|
130 |
+
<button
|
131 |
+
on:click={nextEmail}
|
132 |
+
disabled={currentIndex === emails.length - 1}
|
133 |
+
aria-label="Next email"
|
134 |
+
>
|
135 |
+
Next →
|
136 |
+
</button>
|
137 |
+
</div>
|
138 |
+
</div>
|
139 |
+
{/if}
|
140 |
+
</main>
|