s3si.ts/gui/src/pages/Home.tsx

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-03-04 08:10:30 -05:00
import React from 'react'
2023-03-04 06:19:24 -05:00
import { WebviewWindow } from '@tauri-apps/api/window'
2023-03-03 09:29:46 -05:00
import { Loading } from 'components/Loading'
2023-03-05 12:56:07 -05:00
import { JSONRPCClient, S3SIService, StdioTransport } from 'jsonrpc';
2023-03-05 14:38:10 -05:00
import { invoke } from '@tauri-apps/api';
import { emit } from '@tauri-apps/api/event';
2023-03-04 08:10:30 -05:00
2023-03-05 12:56:07 -05:00
const client = new JSONRPCClient<S3SIService>({
transport: new StdioTransport()
}).getProxy();
2023-03-03 09:06:14 -05:00
export const Home: React.FC = ({ }) => {
2023-03-05 12:56:07 -05:00
const onHello = async () => {
const result = await client.loginSteps();
console.log(result)
if (result.error) {
throw new Error(result.error.message);
}
2023-03-05 14:50:29 -05:00
const login: string | null = await invoke('open_login_window', {
2023-03-05 14:38:10 -05:00
url: result.result.url
})
2023-03-05 14:50:29 -05:00
if (login === null || login === '') {
console.log('user cancel login');
return;
}
const loginResult: { url: string } = JSON.parse(login);
const sessionToken = await client.loginSteps({
authCodeVerifier: result.result.authCodeVerifier,
login: loginResult.url,
})
if (sessionToken.error) {
throw new Error(sessionToken.error.message);
}
console.log('sessionToken', sessionToken.result);
2023-03-04 08:10:30 -05:00
}
2023-03-03 09:06:14 -05:00
return <>
2023-03-03 09:29:46 -05:00
Hello world! <Loading />
2023-03-04 08:10:30 -05:00
<button onClick={onHello}>Hello</button>
2023-03-05 12:56:07 -05:00
2023-03-03 09:06:14 -05:00
</>
2023-03-04 06:19:24 -05:00
}