tangled
alpha
login
or
join now
bad-example.com
/
spacedust-utils
demos for spacedust
6
fork
atom
overview
issues
pulls
pipelines
whoami component
somehow not the worst
bad-example.com
7 months ago
f32459f6
ad41f174
+53
-21
4 changed files
expand all
collapse all
unified
split
atproto-notifications
index.html
src
App.tsx
components
Hello.tsx
WhoAmI.tsx
+1
-2
atproto-notifications/index.html
···
2
2
<html lang="en">
3
3
<head>
4
4
<meta charset="UTF-8" />
5
5
-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
5
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
-
<title>Vite + React + TS</title>
6
6
+
<title>atproto notifications</title>
8
7
</head>
9
8
<body>
10
9
<div id="root"></div>
+11
-4
atproto-notifications/src/App.tsx
···
1
1
import { useLocalStorage } from "@uidotdev/usehooks";
2
2
import { HostContext } from './context'
3
3
-
import { Hello } from './components/Hello';
3
3
+
import { WhoAmI } from './components/WhoAmI';
4
4
import './App.css'
5
5
6
6
function App() {
···
11
11
<HostContext.Provider value={host}>
12
12
<h1>🎇 atproto notifications demo</h1>
13
13
14
14
-
{user === null && (
15
15
-
<Hello onSetUser={setUser} />
16
16
-
)}
14
14
+
{user === null
15
15
+
? (
16
16
+
<WhoAmI onSetUser={setUser} />
17
17
+
)
18
18
+
: (
19
19
+
<>
20
20
+
<p>hi {user.handle}</p>
21
21
+
<button onClick={() => setUser(null)}>clear</button>
22
22
+
</>
23
23
+
)}
17
24
</HostContext.Provider>
18
25
)
19
26
}
-15
atproto-notifications/src/components/Hello.tsx
···
1
1
-
import { useState } from 'react';
2
2
-
3
3
-
export function Hello({ onSetUser }) {
4
4
-
const [userVal, setUserVal] = useState('');
5
5
-
return (
6
6
-
<div className="hello card">
7
7
-
<label>
8
8
-
<input />
9
9
-
</label>
10
10
-
<button onClick={() => {}}>
11
11
-
count is
12
12
-
</button>
13
13
-
</div>
14
14
-
);
15
15
-
}
+41
atproto-notifications/src/components/WhoAmI.tsx
···
1
1
+
import { useRef, useEffect } from 'react';
2
2
+
3
3
+
export function WhoAmI({ onSetUser, origin = 'http://127.0.0.1:9997' }) {
4
4
+
const frameRef = useRef(null);
5
5
+
6
6
+
useEffect(() => {
7
7
+
function handleMessage(ev) {
8
8
+
if (
9
9
+
ev.source !== frameRef.current?.contentWindow ||
10
10
+
ev.origin !== origin
11
11
+
) return;
12
12
+
onSetUser(ev.data);
13
13
+
}
14
14
+
15
15
+
console.log('ready');
16
16
+
window.addEventListener('message', handleMessage);
17
17
+
return () => {
18
18
+
console.log('byeeeeeeeeeeeee');
19
19
+
window.removeEventListener('message', handleMessage);
20
20
+
}
21
21
+
}, []);
22
22
+
23
23
+
return (
24
24
+
<iframe
25
25
+
src={`${origin}/prompt`}
26
26
+
ref={frameRef}
27
27
+
id="whoami"
28
28
+
style={{
29
29
+
border: 'none',
30
30
+
boxSizing: 'border-box',
31
31
+
display: 'block',
32
32
+
colorScheme: 'none',
33
33
+
}}
34
34
+
allowtransparency="true"
35
35
+
height="160"
36
36
+
width="320"
37
37
+
>
38
38
+
Ooops, failed to load the login helper
39
39
+
</iframe>
40
40
+
);
41
41
+
}