1
- import { useState } from "preact/hooks" ;
1
+ // deno-lint-ignore-file
2
+ import { useEffect , useState } from "preact/hooks" ;
2
3
import { PageProps } from "@app/mod.ts" ;
3
4
import Header from "./header.tsx" ;
4
5
import { JSX } from "preact/jsx-runtime" ;
@@ -25,6 +26,18 @@ export default function Home({ data }: PageProps<{
25
26
const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
26
27
const [ submitSuccess , setSubmitSuccess ] = useState ( false ) ;
27
28
const [ isDark , setIsDark ] = useState ( true ) ;
29
+ const [ isMobile , setIsMobile ] = useState ( false ) ;
30
+
31
+ // Detect mobile devices
32
+ useEffect ( ( ) => {
33
+ const checkMobile = ( ) => {
34
+ setIsMobile ( window . innerWidth < 768 ) ;
35
+ } ;
36
+
37
+ checkMobile ( ) ;
38
+ window . addEventListener ( "resize" , checkMobile ) ;
39
+ return ( ) => window . removeEventListener ( "resize" , checkMobile ) ;
40
+ } , [ ] ) ;
28
41
29
42
// Handle post submission
30
43
const handleSubmit = async ( e : JSX . TargetedEvent < HTMLFormElement , Event > ) => {
@@ -94,11 +107,9 @@ export default function Home({ data }: PageProps<{
94
107
setIsDark ( ! isDark ) ;
95
108
} ;
96
109
97
- // Theme styles with solid colors
110
+ // Theme styles with performance optimizations
98
111
const themeStyles = {
99
- background : isDark
100
- ? "#0f172a" /* Slate 900 - solid dark background */
101
- : "#f8fafc" , /* Very light gray - solid light background */
112
+ background : isDark ? "#0f172a" : "#f8fafc" ,
102
113
cardBg : isDark ? "bg-gray-800/90" : "bg-white/90" ,
103
114
text : isDark ? "text-gray-100" : "text-gray-800" ,
104
115
input : isDark
@@ -112,40 +123,45 @@ export default function Home({ data }: PageProps<{
112
123
? "text-purple-400 hover:text-purple-300"
113
124
: "text-purple-600 hover:text-purple-500" ,
114
125
cardBorder : isDark ? "border-gray-700" : "border-gray-200" ,
115
- cardGlow : isDark
116
- ? "shadow-[0_0_35px_rgba(147,51,234,0.3)]" /* Enhanced purple glow for dark theme */
117
- : "shadow-[0_0_20px_rgba(147,51,234,0.15)]" , /* Light purple glow */
126
+ // Simplified shadows for mobile
127
+ cardGlow : isMobile
128
+ ? isDark ? "shadow-md" : "shadow-sm"
129
+ : isDark
130
+ ? "shadow-[0_0_35px_rgba(147,51,234,0.3)]"
131
+ : "shadow-[0_0_20px_rgba(147,51,234,0.15)]" ,
118
132
} ;
119
133
120
134
return (
121
135
< div className = "relative min-h-screen" >
122
- { /* Background Layer */ }
136
+ { /* Background Layer - simplified for mobile */ }
123
137
< div className = "fixed inset-0 z-0" >
124
138
{ /* Solid Background */ }
125
139
< div
126
140
className = "absolute inset-0"
127
141
style = { { backgroundColor : themeStyles . background } }
128
142
/>
129
143
130
- { /* Subtle Dot Pattern (optional - much simpler than gradient) */ }
131
- < div className = "absolute inset-0 z-[1]" >
132
- < div
133
- className = "absolute inset-0"
134
- style = { {
135
- backgroundImage : `
136
- radial-gradient(${
137
- isDark ? "rgba(255,255,255,0.03)" : "rgba(0,0,0,0.03)"
138
- } 1px, transparent 1px)
139
- ` ,
140
- backgroundSize : "20px 20px" ,
141
- } }
142
- />
143
- </ div >
144
+ { /* Dot pattern only on non-mobile */ }
145
+ { ! isMobile && (
146
+ < div className = "absolute inset-0 z-[1]" >
147
+ < div
148
+ className = "absolute inset-0"
149
+ style = { {
150
+ backgroundImage : `
151
+ radial-gradient(${
152
+ isDark ? "rgba(255,255,255,0.03)" : "rgba(0,0,0,0.03)"
153
+ } 1px, transparent 1px)
154
+ ` ,
155
+ backgroundSize : "20px 20px" ,
156
+ } }
157
+ />
158
+ </ div >
159
+ ) }
144
160
</ div >
145
161
146
162
{ /* Content Layer */ }
147
163
< div className = "relative z-10 min-h-screen" >
148
- { /* Theme toggle button - moved to bottom-right corner */ }
164
+ { /* Theme toggle button */ }
149
165
< button
150
166
type = "button"
151
167
onClick = { toggleTheme }
@@ -159,7 +175,7 @@ export default function Home({ data }: PageProps<{
159
175
{ isDark ? "☀️" : "🌙" }
160
176
</ button >
161
177
162
- < div className = "max-w-xl mx-auto backdrop-blur-lg " >
178
+ < div className = "max-w-xl mx-auto" >
163
179
< Header
164
180
isLogin = { data . isLogin }
165
181
avatar_url = { data . avatar_url }
@@ -168,14 +184,12 @@ export default function Home({ data }: PageProps<{
168
184
/>
169
185
170
186
< main className = "max-w-2xl mx-auto px-4" >
171
- { /* Post creation card */ }
187
+ { /* Post creation card - reduced blur effects */ }
172
188
< div
173
- className = { `${ themeStyles . cardBg } rounded-lg ${ themeStyles . cardGlow } p-6 mb-4 border ${ themeStyles . cardBorder } backdrop-blur-lg` }
189
+ className = { `${ themeStyles . cardBg } rounded-lg ${ themeStyles . cardGlow } p-6 mb-4 border ${ themeStyles . cardBorder } ${
190
+ ! isMobile ? "backdrop-blur-lg" : ""
191
+ } `}
174
192
>
175
- < h2 className = { `text-2xl font-bold mb-4 ${ themeStyles . text } ` } >
176
- Create a Post
177
- </ h2 >
178
-
179
193
< form onSubmit = { handleSubmit } className = "space-y-4" >
180
194
< div >
181
195
< textarea
@@ -189,9 +203,6 @@ export default function Home({ data }: PageProps<{
189
203
</ div >
190
204
191
205
< div className = "flex justify-between items-center" >
192
- {
193
- /* */
194
- }
195
206
< div className = "flex justify-start w-full" >
196
207
{ submitSuccess && (
197
208
< div className = "min-w-10 bg-green-500/20 text-green-500 px-4 py-2 rounded-lg mr-2" >
@@ -211,14 +222,20 @@ export default function Home({ data }: PageProps<{
211
222
</ form >
212
223
</ div >
213
224
214
- { /* Posts list */ }
225
+ { /* Posts list - performance optimized */ }
215
226
< div className = "space-y-4 mb-8" >
216
227
{ posts . length > 0
217
228
? (
218
229
posts . map ( ( post ) => (
219
230
< div
220
231
key = { post . id }
221
- className = { `${ themeStyles . cardBg } rounded-lg ${ themeStyles . cardGlow } p-6 border ${ themeStyles . cardBorder } relative backdrop-blur-lg transition-all duration-300 hover:scale-[1.01]` }
232
+ className = { `${ themeStyles . cardBg } rounded-lg ${ themeStyles . cardGlow } p-6 border ${ themeStyles . cardBorder } relative ${
233
+ ! isMobile ? "backdrop-blur-lg" : ""
234
+ } ${
235
+ ! isMobile
236
+ ? "transition-all duration-300 hover:scale-[1.01]"
237
+ : ""
238
+ } `}
222
239
>
223
240
{ /* Delete button */ }
224
241
< button
@@ -238,9 +255,9 @@ export default function Home({ data }: PageProps<{
238
255
viewBox = "0 0 24 24"
239
256
fill = "none"
240
257
stroke = "currentColor"
241
- stroke-width = "2"
242
- stroke-linecap = "round"
243
- stroke-linejoin = "round"
258
+ strokeWidth = "2"
259
+ strokeLinecap = "round"
260
+ strokeLinejoin = "round"
244
261
>
245
262
< path d = "M3 6h18" > </ path >
246
263
< path d = "M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6" >
@@ -262,15 +279,23 @@ export default function Home({ data }: PageProps<{
262
279
</ p >
263
280
</ div >
264
281
</ div >
265
- < p className = { `${ themeStyles . text } whitespace-pre-wrap` } >
266
- { post . content }
267
- </ p >
282
+
283
+ { /* Make the content clickable to view details */ }
284
+ < a href = { `/post/${ post . id } ` } className = "block" >
285
+ < p
286
+ className = { `${ themeStyles . text } whitespace-pre-wrap` }
287
+ >
288
+ { post . content }
289
+ </ p >
290
+ </ a >
268
291
</ div >
269
292
) )
270
293
)
271
294
: (
272
295
< div
273
- className = { `${ themeStyles . cardBg } rounded-lg ${ themeStyles . cardGlow } p-6 border ${ themeStyles . cardBorder } text-center ${ themeStyles . text } backdrop-blur-lg` }
296
+ className = { `${ themeStyles . cardBg } rounded-lg ${ themeStyles . cardGlow } p-6 border ${ themeStyles . cardBorder } text-center ${ themeStyles . text } ${
297
+ ! isMobile ? "backdrop-blur-lg" : ""
298
+ } `}
274
299
>
275
300
< p > No posts yet. Be the first to post something!</ p >
276
301
</ div >
0 commit comments