|
1 | 1 | <template> |
2 | | - <div> |
3 | | - hello world |
4 | | - </div> |
5 | | - <button @click="login">login</button> |
6 | | - <button @click="listQuery">list</button> |
| 2 | + <LoginScreen v-if="!accessToken" v-model:access-token="accessToken"/> |
| 3 | + <WorkScreen v-else></WorkScreen> |
7 | 4 | </template> |
8 | 5 |
|
9 | 6 | <script setup lang="ts"> |
10 | | -import {ref, computed} from 'vue'; |
11 | | -import {auth} from './auth'; |
12 | | -import listGql from './List.gql'; |
13 | | -import { graphql } from '@octokit/graphql'; |
| 7 | +import {ref, watch} from 'vue'; |
| 8 | +import {setAccessToken} from "@/useGraphQlClient"; |
14 | 9 |
|
15 | | -const accessToken = ref<string | null>(null); |
| 10 | +export {default as LoginScreen} from './LoginScreen.vue'; |
| 11 | +export {default as WorkScreen} from './WorkScreen.vue'; |
16 | 12 |
|
17 | | -const graphQlClient = computed(() => { |
18 | | - const headers = accessToken.value ? {authorization: `token ${accessToken.value}`}: {}; |
19 | | - alert(headers); |
20 | | - return graphql.defaults({ |
21 | | - headers |
22 | | - }); |
23 | | -}); |
24 | | -
|
25 | | -export const login = async () => { |
26 | | - const {access_token} = await auth(); |
27 | | - accessToken.value = access_token; |
28 | | - alert('logged in'); |
29 | | -}; |
30 | | -
|
31 | | -export const listQuery = async () => { |
32 | | - if(!graphQlClient.value){ |
33 | | - return; |
34 | | - } |
35 | | - const result = await graphQlClient.value(listGql); |
36 | | - alert(JSON.stringify(result, null, 2)); |
37 | | -}; |
| 13 | +export const accessToken = ref<string | null>(null); |
| 14 | +watch(() => accessToken.value, (accessToken) => setAccessToken(accessToken)); |
38 | 15 |
|
39 | 16 | </script> |
40 | 17 |
|
41 | | -<style scoped> |
42 | | -#app { |
| 18 | +<style> |
| 19 | +body { |
43 | 20 | font-family: Avenir, Helvetica, Arial, sans-serif; |
44 | 21 | -webkit-font-smoothing: antialiased; |
45 | 22 | -moz-osx-font-smoothing: grayscale; |
|
0 commit comments