blob: bb4b7631041433719aee58bb02ee2dab2b6a3d9a (
plain)
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
|
import { useState } from 'react';
import { invoke } from '@tauri-apps/api/core';
export default function Root() {
const [signedIn, setSignedIn] = useState<{serverDomain: string, username: string} | null>(null)
const [accountData, setAccountData] = useState('')
async function signIn() {
let [serverDomain, username] = await invoke('start_account_auth', {instanceDomain: 'social.tempest.dev'}) as string[]
setSignedIn({serverDomain, username})
}
async function getSelf() {
if (!signedIn) throw new Error("Not signed in")
const {serverDomain, username} = signedIn;
let result = await invoke('get_self', {serverDomain, username}) as string
setAccountData(JSON.parse(result))
}
return (
<>
{!signedIn ? (
<button onClick={signIn}>Sign in</button>
) : (!accountData ? (
<button onClick={getSelf}>Retrieve account data</button>
):(
<p>Result from rust: <pre style={{whiteSpace:'pre'}}>{JSON.stringify(accountData, null, 2)}</pre></p>
))}
</>
)
}
|