-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFirstView.js
94 lines (86 loc) · 2.21 KB
/
FirstView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/** @jsxImportSource https://esm.sh/[email protected] */
import React, { useState, useEffect } from "https://esm.sh/[email protected]";
import { createRoot } from "https://esm.sh/[email protected]/client";
function FirstVisitComponent() {
const [isFirstVisit, setIsFirstVisit] = useState(true);
useEffect(() => {
const hasVisited = localStorage.getItem('firstVisitDismissed');
if (hasVisited) {
setIsFirstVisit(false);
}
}, []);
const handleDismiss = () => {
localStorage.setItem('firstVisitDismissed', 'true');
setIsFirstVisit(false);
};
if (!isFirstVisit) return null;
return (
<div style={{
position: 'fixed',
top: 0,
left: 0,
width: '100%',
backgroundColor: '#f0f0f0',
padding: '20px',
textAlign: 'center',
zIndex: 1000
}}>
<h2>Welcome to our site! 👋</h2>
<p>This is a special message for first-time visitors.</p>
<button
onClick={handleDismiss}
style={{
backgroundColor: '#007bff',
color: 'white',
border: 'none',
padding: '10px 20px',
borderRadius: '5px',
cursor: 'pointer'
}}
>
Dismiss
</button>
</div>
);
}
function App() {
return (
<div>
<FirstVisitComponent />
<main>
<h1>Main Site Content</h1>
<p>Your regular site content goes here.</p>
</main>
</div>
);
}
function client() {
createRoot(document.getElementById("root")).render(<App />);
}
if (typeof document !== "undefined") { client(); }
export default async function server(request: Request): Promise<Response> {
return new Response(`
<html>
<head>
<title>First Visit Component</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: system-ui, sans-serif;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="root"></div>
<script src="https://esm.town/v/std/catch"></script>
<script type="module" src="${import.meta.url}"></script>
</body>
</html>
`, {
headers: {
"content-type": "text/html",
},
});
}