File tree Expand file tree Collapse file tree 3 files changed +61
-3
lines changed
Expand file tree Collapse file tree 3 files changed +61
-3
lines changed Original file line number Diff line number Diff line change 7575 Hello, World!
7676 </ h1 >
7777 < p class ="text-lg md:text-xl text-white opacity-90 ">
78- Built with Preact & HTM
78+ Welcome to my beautiful web creation
7979 </ p >
8080 </ div >
8181 `
Original file line number Diff line number Diff line change @@ -143,7 +143,7 @@ <h2 class="text-2xl font-bold mb-4">Error</h2>
143143 </ div >
144144
145145 < footer class ="mt-16 text-gray-500 text-sm ">
146- Built with Preact and HTM
146+ Crafted with ❤️ for web enthusiasts
147147 </ footer >
148148 </ div >
149149 `
Original file line number Diff line number Diff line change @@ -7,17 +7,75 @@ const html = htm.bind(h);
77
88// Navbar component
99class Navbar extends Component {
10+ constructor ( ) {
11+ super ( ) ;
12+ this . state = {
13+ isLoggedIn : false ,
14+ publicKey : ''
15+ } ;
16+ this . loginWithNostr = this . loginWithNostr . bind ( this ) ;
17+ this . logout = this . logout . bind ( this ) ;
18+ }
19+
20+ async loginWithNostr ( ) {
21+ try {
22+ // Check if nostr is available in window
23+ if ( ! window . nostr ) {
24+ alert ( 'Nostr extension not found. Please install a Nostr extension.' ) ;
25+ return ;
26+ }
27+
28+ // Request public key from nostr
29+ const publicKey = await window . nostr . getPublicKey ( ) ;
30+
31+ this . setState ( {
32+ isLoggedIn : true ,
33+ publicKey : publicKey
34+ } ) ;
35+ } catch ( error ) {
36+ console . error ( 'Error logging in with Nostr:' , error ) ;
37+ alert ( 'Failed to login with Nostr. Please try again.' ) ;
38+ }
39+ }
40+
41+ logout ( ) {
42+ this . setState ( {
43+ isLoggedIn : false ,
44+ publicKey : ''
45+ } ) ;
46+ }
47+
1048 render ( ) {
49+ const { isLoggedIn, publicKey } = this . state ;
50+ const truncatedKey = publicKey ? publicKey . substring ( 0 , 8 ) + '...' : '' ;
51+
1152 return html `
1253 < nav class ="w-full bg-gradient-to-r from-blue-100 to-purple-100 shadow-md transition-all duration-300 hover:shadow-lg ">
1354 < div class ="container mx-auto px-4 py-3 ">
14- < div class ="flex justify-center items-center ">
55+ < div class ="flex justify-between items-center ">
1556 < a
1657 href ="index.html "
1758 class ="text-blue-600 font-bold text-xl transition-all duration-300 hover:scale-105 hover:text-purple-600 "
1859 >
1960 Home
2061 </ a >
62+
63+ < div >
64+ ${ isLoggedIn
65+ ? html `< button
66+ onClick =${ this . logout }
67+ class ="text-gray-700 font-medium px-4 py-2 rounded-lg transition-all duration-300 hover:bg-gray-200"
68+ >
69+ ${ truncatedKey }
70+ </ button > `
71+ : html `< button
72+ onClick =${ this . loginWithNostr }
73+ class ="bg-purple-600 text-white px-4 py-2 rounded-lg transition-all duration-300 hover:bg-blue-600"
74+ >
75+ Login with Nostr
76+ </ button > `
77+ }
78+ </ div >
2179 </ div >
2280 </ div >
2381 </ nav >
You can’t perform that action at this time.
0 commit comments