mirror of
https://github.com/tooot-app/app
synced 2025-02-25 08:07:57 +01:00
Full login flow working
Refresh can be faster
This commit is contained in:
parent
ab0062e73c
commit
3280663144
@ -18,7 +18,7 @@
|
||||
"@react-navigation/stack": "^5.12.3",
|
||||
"@reduxjs/toolkit": "^1.4.0",
|
||||
"expo": "~39.0.4",
|
||||
"expo-app-auth": "~9.2.0",
|
||||
"expo-auth-session": "~2.0.0",
|
||||
"expo-av": "~8.6.0",
|
||||
"expo-image-picker": "~9.1.1",
|
||||
"expo-secure-store": "~9.2.0",
|
||||
|
8
src/@types/store.d.ts → src/@types/app.d.ts
vendored
8
src/@types/store.d.ts → src/@types/app.d.ts
vendored
@ -1,10 +1,4 @@
|
||||
declare namespace store {
|
||||
type InstanceInfoState = {
|
||||
local: string
|
||||
localToken: string
|
||||
remote: string
|
||||
}
|
||||
|
||||
declare namespace App {
|
||||
type Pages =
|
||||
| 'Following'
|
||||
| 'Local'
|
10
src/@types/mastodon.d.ts
vendored
10
src/@types/mastodon.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
declare namespace mastodon {
|
||||
declare namespace Mastodon {
|
||||
type Account = {
|
||||
// Base
|
||||
id: string
|
||||
@ -184,6 +184,14 @@ declare namespace mastodon {
|
||||
emojis: Emoji[]
|
||||
}
|
||||
|
||||
type Preferences = {
|
||||
'posting:default:visibility'?: 'public' | 'unlisted' | 'private' | 'direct'
|
||||
'posting:default:sensitive'?: boolean
|
||||
'posting:default:language'?: string
|
||||
'reading:expand:media'?: 'default' | 'show_all' | 'hide_all'
|
||||
'reading:expand:spoilers'?: boolean
|
||||
}
|
||||
|
||||
type Status = {
|
||||
// Base
|
||||
id: string
|
||||
|
@ -22,8 +22,9 @@ const client = async ({
|
||||
}
|
||||
body?: FormData
|
||||
}): Promise<any> => {
|
||||
const state: RootState['instanceInfo'] = store.getState().instanceInfo
|
||||
const url = instanceUrl || store.getState().instanceInfo[instance]
|
||||
const state: RootState['instances'] = store.getState().instances
|
||||
const url =
|
||||
instance === 'remote' ? instanceUrl || state.remote.url : state.local.url
|
||||
|
||||
let response
|
||||
// try {
|
||||
@ -35,7 +36,7 @@ const client = async ({
|
||||
'Content-Type': 'application/json',
|
||||
...headers,
|
||||
...(instance === 'local' && {
|
||||
Authorization: `Bearer ${state.localToken}`
|
||||
Authorization: `Bearer ${state.local.token}`
|
||||
})
|
||||
},
|
||||
...(body && { body: body }),
|
||||
|
@ -15,7 +15,7 @@ const renderNode = ({
|
||||
node: HTMLViewNode
|
||||
index: number
|
||||
navigation: any
|
||||
mentions?: mastodon.Mention[]
|
||||
mentions?: Mastodon.Mention[]
|
||||
showFullLink: boolean
|
||||
}) => {
|
||||
if (node.name == 'a') {
|
||||
@ -80,9 +80,9 @@ const renderNode = ({
|
||||
|
||||
export interface Props {
|
||||
content: string
|
||||
emojis?: mastodon.Emoji[]
|
||||
emojis?: Mastodon.Emoji[]
|
||||
emojiSize?: number
|
||||
mentions?: mastodon.Mention[]
|
||||
mentions?: Mastodon.Mention[]
|
||||
showFullLink?: boolean
|
||||
linesTruncated?: number
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import Emojis from './Emojis'
|
||||
export interface Props {
|
||||
action: 'favourite' | 'follow' | 'mention' | 'poll' | 'reblog'
|
||||
name?: string
|
||||
emojis?: mastodon.Emoji[]
|
||||
emojis?: Mastodon.Emoji[]
|
||||
notification?: boolean
|
||||
}
|
||||
|
||||
|
@ -10,10 +10,11 @@ import {
|
||||
} from 'react-native'
|
||||
import Toast from 'react-native-toast-message'
|
||||
import { useMutation, useQueryCache } from 'react-query'
|
||||
import { useSelector } from 'react-redux'
|
||||
import { Feather } from '@expo/vector-icons'
|
||||
|
||||
import client from 'src/api/client'
|
||||
import { getLocalAccountId } from 'src/stacks/common/instancesSlice'
|
||||
import store from 'src/stacks/common/store'
|
||||
|
||||
const fireMutation = async ({
|
||||
id,
|
||||
@ -106,12 +107,12 @@ const fireMutation = async ({
|
||||
}
|
||||
|
||||
export interface Props {
|
||||
queryKey: store.QueryKey
|
||||
status: mastodon.Status
|
||||
queryKey: App.QueryKey
|
||||
status: Mastodon.Status
|
||||
}
|
||||
|
||||
const ActionsStatus: React.FC<Props> = ({ queryKey, status }) => {
|
||||
const localAccountId = useSelector(state => state.instanceInfo.localAccountId)
|
||||
const localAccountId = getLocalAccountId(store.getState())
|
||||
const [modalVisible, setModalVisible] = useState(false)
|
||||
|
||||
const queryCache = useQueryCache()
|
||||
@ -129,7 +130,7 @@ const ActionsStatus: React.FC<Props> = ({ queryKey, status }) => {
|
||||
// oldData &&
|
||||
// oldData.map((paging: any) => {
|
||||
// paging.toots.map(
|
||||
// (status: mastodon.Status | mastodon.Notification, i: number) => {
|
||||
// (status: Mastodon.Status | Mastodon.Notification, i: number) => {
|
||||
// if (status.id === newData.id) {
|
||||
// paging.toots[i] = newData
|
||||
// }
|
||||
|
@ -5,7 +5,7 @@ import AttachmentImage from './Attachment/AttachmentImage'
|
||||
import AttachmentVideo from './Attachment/AttachmentVideo'
|
||||
|
||||
export interface Props {
|
||||
media_attachments: mastodon.Attachment[]
|
||||
media_attachments: Mastodon.Attachment[]
|
||||
sensitive: boolean
|
||||
width: number
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import { Button, Image, Modal, StyleSheet, Pressable, View } from 'react-native'
|
||||
import ImageViewer from 'react-native-image-zoom-viewer'
|
||||
|
||||
export interface Props {
|
||||
media_attachments: mastodon.Attachment[]
|
||||
media_attachments: Mastodon.Attachment[]
|
||||
sensitive: boolean
|
||||
width: number
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import { Video } from 'expo-av'
|
||||
import { Feather } from '@expo/vector-icons'
|
||||
|
||||
export interface Props {
|
||||
media_attachments: mastodon.Attachment[]
|
||||
media_attachments: Mastodon.Attachment[]
|
||||
sensitive: boolean
|
||||
width: number
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import { Image, Pressable, StyleSheet, Text, View } from 'react-native'
|
||||
import { useNavigation } from '@react-navigation/native'
|
||||
|
||||
export interface Props {
|
||||
card: mastodon.Card
|
||||
card: Mastodon.Card
|
||||
}
|
||||
|
||||
const Card: React.FC<Props> = ({ card }) => {
|
||||
|
@ -6,8 +6,8 @@ import ParseContent from 'src/components/ParseContent'
|
||||
|
||||
export interface Props {
|
||||
content: string
|
||||
emojis: mastodon.Emoji[]
|
||||
mentions: mastodon.Mention[]
|
||||
emojis: Mastodon.Emoji[]
|
||||
mentions: Mastodon.Mention[]
|
||||
spoiler_text?: string
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ const regexEmoji = new RegExp(/(:[a-z0-9_]+:)/)
|
||||
|
||||
export interface Props {
|
||||
content: string
|
||||
emojis: mastodon.Emoji[]
|
||||
emojis: Mastodon.Emoji[]
|
||||
dimension: number
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,11 @@ import Emojis from './Emojis'
|
||||
import relativeTime from 'src/utils/relativeTime'
|
||||
import client from 'src/api/client'
|
||||
import { useSelector } from 'react-redux'
|
||||
import {
|
||||
getLocalAccountId,
|
||||
getLocalUrl
|
||||
} from 'src/stacks/common/instancesSlice'
|
||||
import store from 'src/stacks/common/store'
|
||||
|
||||
const fireMutation = async ({
|
||||
id,
|
||||
@ -116,14 +121,14 @@ const fireMutation = async ({
|
||||
}
|
||||
|
||||
export interface Props {
|
||||
queryKey: store.QueryKey
|
||||
queryKey: App.QueryKey
|
||||
accountId: string
|
||||
domain: string
|
||||
name: string
|
||||
emojis?: mastodon.Emoji[]
|
||||
emojis?: Mastodon.Emoji[]
|
||||
account: string
|
||||
created_at: string
|
||||
application?: mastodon.Application
|
||||
application?: Mastodon.Application
|
||||
}
|
||||
|
||||
const Header: React.FC<Props> = ({
|
||||
@ -137,8 +142,8 @@ const Header: React.FC<Props> = ({
|
||||
application
|
||||
}) => {
|
||||
const navigation = useNavigation()
|
||||
const localAccountId = useSelector(state => state.instanceInfo.localAccountId)
|
||||
const localDomain = useSelector(state => state.instanceInfo.local)
|
||||
const localAccountId = getLocalAccountId(store.getState())
|
||||
const localDomain = getLocalUrl(store.getState())
|
||||
const [since, setSince] = useState(relativeTime(created_at))
|
||||
const [modalVisible, setModalVisible] = useState(false)
|
||||
|
||||
@ -158,7 +163,7 @@ const Header: React.FC<Props> = ({
|
||||
// oldData &&
|
||||
// oldData.map((paging: any) => {
|
||||
// paging.toots.map(
|
||||
// (status: mastodon.Status | mastodon.Notification, i: number) => {
|
||||
// (status: Mastodon.Status | Mastodon.Notification, i: number) => {
|
||||
// if (status.id === newData.id) {
|
||||
// paging.toots[i] = newData
|
||||
// }
|
||||
|
@ -4,7 +4,7 @@ import { StyleSheet, Text, View } from 'react-native'
|
||||
import Emojis from './Emojis'
|
||||
|
||||
export interface Props {
|
||||
poll: mastodon.Poll
|
||||
poll: Mastodon.Poll
|
||||
}
|
||||
// When haven't voted, result should not be shown but intead let people vote
|
||||
const Poll: React.FC<Props> = ({ poll }) => {
|
||||
|
@ -12,8 +12,8 @@ import Card from './Status/Card'
|
||||
import ActionsStatus from './Status/ActionsStatus'
|
||||
|
||||
export interface Props {
|
||||
notification: mastodon.Notification
|
||||
queryKey: store.QueryKey
|
||||
notification: Mastodon.Notification
|
||||
queryKey: App.QueryKey
|
||||
}
|
||||
|
||||
const TootNotification: React.FC<Props> = ({ notification, queryKey }) => {
|
||||
|
@ -12,8 +12,8 @@ import Card from './Status/Card'
|
||||
import ActionsStatus from './Status/ActionsStatus'
|
||||
|
||||
export interface Props {
|
||||
status: mastodon.Status
|
||||
queryKey: store.QueryKey
|
||||
status: Mastodon.Status
|
||||
queryKey: App.QueryKey
|
||||
}
|
||||
|
||||
const StatusInTimeline: React.FC<Props> = ({ status, queryKey }) => {
|
||||
|
@ -1,16 +1,23 @@
|
||||
import React, { useCallback, useState } from 'react'
|
||||
import React, { useCallback, useEffect, useState } from 'react'
|
||||
import { Button, Text, TextInput, View } from 'react-native'
|
||||
import { StackNavigationProp } from '@react-navigation/stack'
|
||||
import { useQuery } from 'react-query'
|
||||
import { debounce } from 'lodash'
|
||||
|
||||
import { instanceFetch } from 'src/stacks/common/instanceFetch'
|
||||
import { ScreenMeAuthentication } from '../Authentication'
|
||||
import client from 'src/api/client'
|
||||
import * as AppAuth from 'expo-app-auth'
|
||||
import * as AuthSession from 'expo-auth-session'
|
||||
import { useDispatch } from 'react-redux'
|
||||
import { updateLocal } from 'src/stacks/common/instancesSlice'
|
||||
import { useNavigation } from '@react-navigation/native'
|
||||
|
||||
const Instance: React.FC = () => {
|
||||
const navigation = useNavigation()
|
||||
const dispatch = useDispatch()
|
||||
const [instance, setInstance] = useState('')
|
||||
const [applicationData, setApplicationData] = useState<{
|
||||
clientId: string
|
||||
clientSecret: string
|
||||
}>()
|
||||
|
||||
const { isSuccess, refetch, data } = useQuery(
|
||||
['Instance', { instance }],
|
||||
@ -25,6 +32,7 @@ const Instance: React.FC = () => {
|
||||
debounce(
|
||||
text => {
|
||||
setInstance(text)
|
||||
setApplicationData(undefined)
|
||||
refetch()
|
||||
},
|
||||
1000,
|
||||
@ -35,26 +43,10 @@ const Instance: React.FC = () => {
|
||||
[]
|
||||
)
|
||||
|
||||
const signInAsync = async (id: string) => {
|
||||
let authState = await AppAuth.authAsync({
|
||||
issuer: `https://${instance}`,
|
||||
scopes: ['read', 'write', 'follow', 'push'],
|
||||
clientId: id,
|
||||
redirectUrl: 'exp://127.0.0.1:19000',
|
||||
serviceConfiguration: {
|
||||
authorizationEndpoint: `https://${instance}/oauth/authorize`,
|
||||
revocationEndpoint: `https://${instance}/oauth/revoke`,
|
||||
tokenEndpoint: `https://${instance}/oauth/token`
|
||||
},
|
||||
additionalParameters: {
|
||||
response_type: 'code'
|
||||
}
|
||||
})
|
||||
console.log(authState)
|
||||
return authState
|
||||
}
|
||||
|
||||
const oauthCreateApplication = async () => {
|
||||
const createApplication = async () => {
|
||||
if (applicationData) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
const formData = new FormData()
|
||||
formData.append('client_name', 'test_dudu')
|
||||
formData.append('redirect_uris', 'exp://127.0.0.1:19000')
|
||||
@ -68,20 +60,60 @@ const Instance: React.FC = () => {
|
||||
body: formData
|
||||
})
|
||||
if (res.body?.client_id.length > 0) {
|
||||
return Promise.resolve(res.body)
|
||||
setApplicationData({
|
||||
clientId: res.body.client_id,
|
||||
clientSecret: res.body.client_secret
|
||||
})
|
||||
return Promise.resolve()
|
||||
} else {
|
||||
return Promise.reject()
|
||||
}
|
||||
}
|
||||
|
||||
const oauthFlow = async () => {
|
||||
const applicationData = await oauthCreateApplication()
|
||||
if (applicationData.client_id.length > 0) {
|
||||
await signInAsync(applicationData.client_id)
|
||||
} else {
|
||||
console.error('Application data error')
|
||||
const [request, response, promptAsync] = AuthSession.useAuthRequest(
|
||||
{
|
||||
clientId: applicationData?.clientId!,
|
||||
clientSecret: applicationData?.clientSecret,
|
||||
scopes: ['read', 'write', 'follow', 'push'],
|
||||
redirectUri: 'exp://127.0.0.1:19000'
|
||||
// usePKCE: false
|
||||
},
|
||||
{
|
||||
authorizationEndpoint: `https://${instance}/oauth/authorize`
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
;(async () => {
|
||||
if (request?.clientId) {
|
||||
await promptAsync()
|
||||
}
|
||||
})()
|
||||
}, [request])
|
||||
|
||||
useEffect(() => {
|
||||
;(async () => {
|
||||
if (response?.type === 'success') {
|
||||
const { accessToken } = await AuthSession.exchangeCodeAsync(
|
||||
{
|
||||
clientId: applicationData?.clientId!,
|
||||
clientSecret: applicationData?.clientSecret,
|
||||
scopes: ['read', 'write', 'follow', 'push'],
|
||||
redirectUri: 'exp://127.0.0.1:19000',
|
||||
code: response.params.code,
|
||||
extraParams: {
|
||||
grant_type: 'authorization_code'
|
||||
}
|
||||
},
|
||||
{
|
||||
tokenEndpoint: `https://${instance}/oauth/token`
|
||||
}
|
||||
)
|
||||
dispatch(updateLocal({ url: instance, token: accessToken }))
|
||||
navigation.navigate('Local')
|
||||
}
|
||||
})()
|
||||
}, [response])
|
||||
|
||||
return (
|
||||
<View>
|
||||
@ -99,7 +131,7 @@ const Instance: React.FC = () => {
|
||||
<Button
|
||||
title='登录'
|
||||
disabled={!data?.uri}
|
||||
onPress={async () => await oauthFlow()}
|
||||
onPress={async () => await createApplication()}
|
||||
/>
|
||||
{isSuccess && data && data.uri && (
|
||||
<View>
|
||||
|
@ -58,8 +58,8 @@ const Information = ({
|
||||
account,
|
||||
emojis
|
||||
}: {
|
||||
account: mastodon.Account
|
||||
emojis: mastodon.Emoji[]
|
||||
account: Mastodon.Account
|
||||
emojis: Mastodon.Emoji[]
|
||||
}) => {
|
||||
return (
|
||||
<View style={styles.information}>
|
||||
|
@ -13,6 +13,7 @@ import { useNavigation } from '@react-navigation/native'
|
||||
import store from 'src/stacks/common/store'
|
||||
import PostMain from './PostToot/PostMain'
|
||||
import client from 'src/api/client'
|
||||
import { getLocalAccountPreferences } from '../common/instancesSlice'
|
||||
|
||||
const Stack = createNativeStackNavigator()
|
||||
|
||||
@ -31,7 +32,7 @@ export type PostState = {
|
||||
offset: number
|
||||
}
|
||||
| undefined
|
||||
emojis: mastodon.Emoji[] | undefined
|
||||
emojis: Mastodon.Emoji[] | undefined
|
||||
poll: {
|
||||
active: boolean
|
||||
total: number
|
||||
@ -130,9 +131,10 @@ const postInitialState: PostState = {
|
||||
expire: '86400'
|
||||
},
|
||||
attachments: [],
|
||||
visibility: store.getState().instanceInfo.localAccount.locked
|
||||
? 'private'
|
||||
: 'public'
|
||||
visibility:
|
||||
getLocalAccountPreferences(store.getState())[
|
||||
'posting:default:visibility'
|
||||
] || 'public'
|
||||
}
|
||||
const postReducer = (state: PostState, action: PostAction): PostState => {
|
||||
switch (action.type) {
|
||||
|
@ -4,13 +4,12 @@ import { setFocusHandler, useInfiniteQuery } from 'react-query'
|
||||
|
||||
import StatusInNotifications from 'src/components/StatusInNotifications'
|
||||
import StatusInTimeline from 'src/components/StatusInTimeline'
|
||||
import store from './store'
|
||||
import { timelineFetch } from './timelineFetch'
|
||||
|
||||
// Opening nesting hashtag pages
|
||||
|
||||
export interface Props {
|
||||
page: store.Pages
|
||||
page: App.Pages
|
||||
hashtag?: string
|
||||
list?: string
|
||||
toot?: string
|
||||
@ -38,7 +37,7 @@ const Timeline: React.FC<Props> = ({
|
||||
return () => AppState.removeEventListener('change', handleAppStateChange)
|
||||
})
|
||||
|
||||
const queryKey: store.QueryKey = [
|
||||
const queryKey: App.QueryKey = [
|
||||
page,
|
||||
{ page, hashtag, list, toot, account }
|
||||
]
|
||||
|
@ -1,15 +1,17 @@
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import { Dimensions, FlatList, View } from 'react-native'
|
||||
import { Dimensions, FlatList, Text, View } from 'react-native'
|
||||
import { createNativeStackNavigator } from 'react-native-screens/native-stack'
|
||||
import SegmentedControl from '@react-native-community/segmented-control'
|
||||
import { Feather } from '@expo/vector-icons'
|
||||
|
||||
import Timeline from './Timeline'
|
||||
import sharedScreens from 'src/stacks/Shared/sharedScreens'
|
||||
import { getLocalRegistered } from './instancesSlice'
|
||||
import store from './store'
|
||||
|
||||
const Stack = createNativeStackNavigator()
|
||||
|
||||
const Page = ({ item: { page } }: { item: { page: store.TimelinePage } }) => {
|
||||
const Page = ({ item: { page } }: { item: { page: App.Pages } }) => {
|
||||
return (
|
||||
<View style={{ width: Dimensions.get('window').width }}>
|
||||
<Timeline page={page} />
|
||||
@ -19,10 +21,11 @@ const Page = ({ item: { page } }: { item: { page: store.TimelinePage } }) => {
|
||||
|
||||
export interface Props {
|
||||
name: string
|
||||
content: { title: string; page: string }[]
|
||||
content: { title: string; page: App.Pages }[]
|
||||
}
|
||||
|
||||
const TimelinesCombined: React.FC<Props> = ({ name, content }) => {
|
||||
const localRegistered = getLocalRegistered(store.getState())
|
||||
const [segment, setSegment] = useState(0)
|
||||
const [renderHeader, setRenderHeader] = useState(false)
|
||||
const [segmentManuallyTriggered, setSegmentManuallyTriggered] = useState(
|
||||
@ -68,7 +71,13 @@ const TimelinesCombined: React.FC<Props> = ({ name, content }) => {
|
||||
data={content}
|
||||
keyExtractor={({ page }) => page}
|
||||
renderItem={({ item, index }) => {
|
||||
return <Page key={index} item={item} />
|
||||
return localRegistered || item.page === 'RemotePublic' ? (
|
||||
<Page key={index} item={item} />
|
||||
) : (
|
||||
<View style={{ width: Dimensions.get('window').width }}>
|
||||
<Text>请先登录</Text>
|
||||
</View>
|
||||
)
|
||||
}}
|
||||
ref={horizontalPaging}
|
||||
bounces={false}
|
||||
|
@ -1,24 +0,0 @@
|
||||
import { createSlice } from '@reduxjs/toolkit'
|
||||
|
||||
const instanceInfoSlice = createSlice({
|
||||
name: 'instanceInfo',
|
||||
initialState: {},
|
||||
reducers: {
|
||||
// increment (state) {
|
||||
// state.value++
|
||||
// },
|
||||
// decrement (state) {
|
||||
// state.value--
|
||||
// },
|
||||
// incrementByAmount (state, action) {
|
||||
// state.value += action.payload
|
||||
// }
|
||||
}
|
||||
})
|
||||
|
||||
// export const getCurrent = state => state.current
|
||||
// export const getCurrentToken = state => state.currentToken
|
||||
// export const getRemote = state => state.remote
|
||||
|
||||
// export const { increment, decrement, incrementByAmount } = counterSlice.actions
|
||||
export default instanceInfoSlice.reducer
|
99
src/stacks/common/instancesSlice.ts
Normal file
99
src/stacks/common/instancesSlice.ts
Normal file
@ -0,0 +1,99 @@
|
||||
import { createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import client from 'src/api/client'
|
||||
import { RootState } from './store'
|
||||
|
||||
type InstancesState = {
|
||||
local: {
|
||||
url: string | undefined
|
||||
token: string | undefined
|
||||
account: {
|
||||
id: Mastodon.Account['id'] | undefined
|
||||
preferences: Mastodon.Preferences
|
||||
}
|
||||
}
|
||||
remote: {
|
||||
url: string
|
||||
}
|
||||
}
|
||||
|
||||
export const updateLocal = createAsyncThunk(
|
||||
'instances/updateLocal',
|
||||
async ({
|
||||
url,
|
||||
token
|
||||
}: {
|
||||
url: InstancesState['local']['url']
|
||||
token: InstancesState['local']['token']
|
||||
}) => {
|
||||
const {
|
||||
body: { id }
|
||||
} = await client({
|
||||
method: 'get',
|
||||
instance: 'remote',
|
||||
instanceUrl: url,
|
||||
endpoint: `accounts/verify_credentials`,
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
})
|
||||
|
||||
const { body: preferences } = await client({
|
||||
method: 'get',
|
||||
instance: 'remote',
|
||||
instanceUrl: url,
|
||||
endpoint: `preferences`,
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
})
|
||||
|
||||
return {
|
||||
url,
|
||||
token,
|
||||
account: {
|
||||
id,
|
||||
preferences
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const instancesSlice = createSlice({
|
||||
name: 'instances',
|
||||
initialState: {
|
||||
local: {
|
||||
url: undefined,
|
||||
token: undefined,
|
||||
account: {
|
||||
id: undefined,
|
||||
preferences: {
|
||||
'posting:default:visibility': undefined,
|
||||
'posting:default:sensitive': undefined,
|
||||
'posting:default:language': undefined,
|
||||
'reading:expand:media': undefined,
|
||||
'reading:expand:spoilers': undefined
|
||||
}
|
||||
}
|
||||
},
|
||||
remote: {
|
||||
url: 'mastodon.social'
|
||||
}
|
||||
} as InstancesState,
|
||||
reducers: {},
|
||||
extraReducers: builder => {
|
||||
builder.addCase(updateLocal.fulfilled, (state, action) => {
|
||||
state.local = action.payload
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
export const getLocalRegistered = (state: RootState) =>
|
||||
state.instances.local.url !== undefined &&
|
||||
state.instances.local.token !== undefined
|
||||
export const getLocalUrl = (state: RootState) => state.instances.local.url
|
||||
export const getLocalAccountId = (state: RootState) =>
|
||||
state.instances.local.account.id
|
||||
export const getLocalAccountPreferences = (state: RootState) =>
|
||||
state.instances.local.account.preferences
|
||||
|
||||
// export const {
|
||||
// updateLocalInstance,
|
||||
// updateLocalAccount
|
||||
// } = instancesSlice.actions
|
||||
export default instancesSlice.reducer
|
@ -1,27 +1,11 @@
|
||||
import { configureStore } from '@reduxjs/toolkit'
|
||||
|
||||
import instanceInfoSlice from 'src/stacks/common/instanceInfoSlice'
|
||||
|
||||
// get site information from local storage and pass to reducers
|
||||
const preloadedState = {
|
||||
instanceInfo: {
|
||||
local: 'social.xmflsct.com',
|
||||
localToken: 'qjzJ0IjvZ1apsn0_wBkGcdjKgX7Dao9KEPhGwggPwAo',
|
||||
localAccountId: '1',
|
||||
localAccount: {
|
||||
locked: false
|
||||
},
|
||||
remote: 'mastodon.social'
|
||||
}
|
||||
}
|
||||
|
||||
const reducer = {
|
||||
instanceInfo: instanceInfoSlice
|
||||
}
|
||||
import instancesSlice from 'src/stacks/common/instancesSlice'
|
||||
|
||||
const store = configureStore({
|
||||
preloadedState,
|
||||
reducer
|
||||
reducer: {
|
||||
instances: instancesSlice
|
||||
}
|
||||
})
|
||||
|
||||
export default store
|
||||
|
@ -95,7 +95,7 @@ export const timelineFetch = async (
|
||||
pinned: 'true'
|
||||
}
|
||||
})
|
||||
let toots: mastodon.Status[] = res.body
|
||||
let toots: Mastodon.Status[] = res.body
|
||||
res = await client({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
|
98
yarn.lock
98
yarn.lock
@ -1797,6 +1797,11 @@ base64-js@^1.0.2, base64-js@^1.1.2, base64-js@^1.2.3:
|
||||
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1"
|
||||
integrity sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==
|
||||
|
||||
base64-js@^1.3.0:
|
||||
version "1.5.1"
|
||||
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
|
||||
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
|
||||
|
||||
base@^0.11.1:
|
||||
version "0.11.2"
|
||||
resolved "https://registry.yarnpkg.com/base/-/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f"
|
||||
@ -2148,6 +2153,13 @@ commondir@^1.0.1:
|
||||
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
|
||||
integrity sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=
|
||||
|
||||
compare-urls@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/compare-urls/-/compare-urls-2.0.0.tgz#9b378c4abd43980a8700fffec9afb85de4df9075"
|
||||
integrity sha512-eCJcWn2OYFEIqbm70ta7LQowJOOZZqq1a2YbbFCFI1uwSvj+TWMwXVn7vPR1ceFNcAIt5RSTDbwdlX82gYLTkA==
|
||||
dependencies:
|
||||
normalize-url "^2.0.1"
|
||||
|
||||
compare-versions@^3.4.0:
|
||||
version "3.6.0"
|
||||
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-3.6.0.tgz#1a5689913685e5a87637b8d3ffca75514ec41d62"
|
||||
@ -2656,13 +2668,6 @@ expand-brackets@^2.1.4:
|
||||
snapdragon "^0.8.1"
|
||||
to-regex "^3.0.1"
|
||||
|
||||
expo-app-auth@~9.2.0:
|
||||
version "9.2.0"
|
||||
resolved "https://registry.yarnpkg.com/expo-app-auth/-/expo-app-auth-9.2.0.tgz#88868639f96c4fae973b86bd8712477e2db9dc2c"
|
||||
integrity sha512-aRsRTfCfpuR8n8nO22WwwwTB7JhhJv7T9ZB5f68u6NN/FTF5CnhI3m5t0lawmirNSdmK+mGL0L+gvRyVyt1WLQ==
|
||||
dependencies:
|
||||
invariant "^2.2.4"
|
||||
|
||||
expo-asset@~8.2.0:
|
||||
version "8.2.0"
|
||||
resolved "https://registry.yarnpkg.com/expo-asset/-/expo-asset-8.2.0.tgz#2f72491064c02d4de32e9187d474deb9cec33003"
|
||||
@ -2674,6 +2679,19 @@ expo-asset@~8.2.0:
|
||||
path-browserify "^1.0.0"
|
||||
url-parse "^1.4.4"
|
||||
|
||||
expo-auth-session@~2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/expo-auth-session/-/expo-auth-session-2.0.0.tgz#513cabd7f0ae090b2fe6ceb6cde7362f269b6a85"
|
||||
integrity sha512-B+Wu9t4aUxman9WD0abBCjhj3rXmnoei2TcEyBSGT5q/buJEFC7opwppm+g92RL37dx+uDaSPBaVZW4jbehyVw==
|
||||
dependencies:
|
||||
expo-constants "^9.2.0"
|
||||
expo-crypto "^8.3.0"
|
||||
expo-linking "~1.0.4"
|
||||
expo-random "^9.0.0"
|
||||
expo-web-browser "^8.5.0"
|
||||
invariant "^2.2.4"
|
||||
qs "6.9.1"
|
||||
|
||||
expo-av@~8.6.0:
|
||||
version "8.6.0"
|
||||
resolved "https://registry.yarnpkg.com/expo-av/-/expo-av-8.6.0.tgz#ab434c05241c1dcdca0edd57acb03aa21a3e46cc"
|
||||
@ -2682,7 +2700,7 @@ expo-av@~8.6.0:
|
||||
lodash "^4.17.15"
|
||||
nullthrows "^1.1.0"
|
||||
|
||||
expo-constants@~9.2.0:
|
||||
expo-constants@^9.2.0, expo-constants@~9.2.0:
|
||||
version "9.2.0"
|
||||
resolved "https://registry.yarnpkg.com/expo-constants/-/expo-constants-9.2.0.tgz#e86a38793deaff9018878afac65bce2543c80a4c"
|
||||
integrity sha512-WKwiEMvBgPrEPEyZKm21UUB2KWQux9OCWf6ZDORLTln7kO3rsbaJEprfWUWTP7AxyaLMYfN+/0WFHjZc25SZWQ==
|
||||
@ -2690,6 +2708,11 @@ expo-constants@~9.2.0:
|
||||
fbjs "1.0.0"
|
||||
uuid "^3.3.2"
|
||||
|
||||
expo-crypto@^8.3.0:
|
||||
version "8.3.0"
|
||||
resolved "https://registry.yarnpkg.com/expo-crypto/-/expo-crypto-8.3.0.tgz#b46f09dd813f24b77edb367520b69149496db86e"
|
||||
integrity sha512-PbfxihKJsAkAy5M6jfv5Eiv9pRHU1BjBa7jLcwKDH6aUiWiJNjUvfdwku/Odt/lpXDuNcyDASy4WrD/PZDHtLA==
|
||||
|
||||
expo-error-recovery@~1.3.0:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/expo-error-recovery/-/expo-error-recovery-1.3.0.tgz#8f4ba957c766e4b9279493eee042d37a562fb3ea"
|
||||
@ -2749,6 +2772,13 @@ expo-permissions@~9.3.0:
|
||||
resolved "https://registry.yarnpkg.com/expo-permissions/-/expo-permissions-9.3.0.tgz#b90c7e9e411d306c1c7ba2bae18d5c53c201affd"
|
||||
integrity sha512-ylSJZVvEGJVFTKsFrUL2S6gCvFt+/o8TJ3xT4WaMjHe2/2Z7R8ng6NR47Kt54t7XBIV/SZ7DIY9uRiR7TPuNYA==
|
||||
|
||||
expo-random@^9.0.0:
|
||||
version "9.0.1"
|
||||
resolved "https://registry.yarnpkg.com/expo-random/-/expo-random-9.0.1.tgz#8bea5ed7fce3d7d622bee04e1ec59415b00c9726"
|
||||
integrity sha512-IIxFUpu2wLRbrWeMR74sJjDDxjXk7+hY8DAxnkW6aBgK405BctT6SxXebzpYRTx9IlQ5Drf93Gdz9xMTEDWGlg==
|
||||
dependencies:
|
||||
base64-js "^1.3.0"
|
||||
|
||||
expo-secure-store@~9.2.0:
|
||||
version "9.2.0"
|
||||
resolved "https://registry.yarnpkg.com/expo-secure-store/-/expo-secure-store-9.2.0.tgz#5c7072058f9d0dd80dd9f17732a8512a2a30c52c"
|
||||
@ -2774,6 +2804,13 @@ expo-status-bar@~1.0.2:
|
||||
resolved "https://registry.yarnpkg.com/expo-status-bar/-/expo-status-bar-1.0.2.tgz#2441a77c56be31597898337b0d086981f2adefd8"
|
||||
integrity sha512-5313u744GcLzCadxIPXyTkYw77++UXv1dXCuhYDxDbtsEf93iMra7WSvzyE8a7mRQLIIPRuGnBOdrL/V1C7EOQ==
|
||||
|
||||
expo-web-browser@^8.5.0:
|
||||
version "8.5.0"
|
||||
resolved "https://registry.yarnpkg.com/expo-web-browser/-/expo-web-browser-8.5.0.tgz#294fac01d9d7c8e496fddeb0ca7cf58d96a1f159"
|
||||
integrity sha512-ysfGgTd16gjTAcxbywR/07Pye6XUZDoQsfeo+BEzP2kRgCWGJ5ll5WfCVNxcHInp9eo8G+n5nKqhd7Fv4gX7rg==
|
||||
dependencies:
|
||||
compare-urls "^2.0.0"
|
||||
|
||||
expo@~39.0.4:
|
||||
version "39.0.4"
|
||||
resolved "https://registry.yarnpkg.com/expo/-/expo-39.0.4.tgz#320b7453ac055fc37c64942d5ba442f4e2781993"
|
||||
@ -3512,6 +3549,11 @@ is-obj@^1.0.0:
|
||||
resolved "https://registry.yarnpkg.com/is-obj/-/is-obj-1.0.1.tgz#3e4729ac1f5fde025cd7d83a896dab9f4f67db0f"
|
||||
integrity sha1-PkcprB9f3gJc19g6iW2rn09n2w8=
|
||||
|
||||
is-plain-obj@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"
|
||||
integrity sha1-caUMhCnfync8kqOQpKA7OfzVHT4=
|
||||
|
||||
is-plain-object@^2.0.3, is-plain-object@^2.0.4:
|
||||
version "2.0.4"
|
||||
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-2.0.4.tgz#2c163b3fafb1b606d9d17928f05c2a1c38e07677"
|
||||
@ -4466,6 +4508,15 @@ normalize-path@^2.1.1:
|
||||
dependencies:
|
||||
remove-trailing-separator "^1.0.1"
|
||||
|
||||
normalize-url@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-2.0.1.tgz#835a9da1551fa26f70e92329069a23aa6574d7e6"
|
||||
integrity sha512-D6MUW4K/VzoJ4rJ01JFKxDrtY1v9wrgzCX5f2qj/lzH1m/lW6MhUZFKerVsnyjOhOsYzI9Kqqak+10l4LvLpMw==
|
||||
dependencies:
|
||||
prepend-http "^2.0.0"
|
||||
query-string "^5.0.1"
|
||||
sort-keys "^2.0.0"
|
||||
|
||||
npm-run-path@^2.0.0:
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f"
|
||||
@ -4777,6 +4828,11 @@ pouchdb-collections@^1.0.1:
|
||||
resolved "https://registry.yarnpkg.com/pouchdb-collections/-/pouchdb-collections-1.0.1.tgz#fe63a17da977611abef7cb8026cb1a9553fd8359"
|
||||
integrity sha1-/mOhfal3YRq+98uAJssalVP9g1k=
|
||||
|
||||
prepend-http@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
|
||||
integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=
|
||||
|
||||
pretty-format@^23.6.0:
|
||||
version "23.6.0"
|
||||
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-23.6.0.tgz#5eaac8eeb6b33b987b7fe6097ea6a8a146ab5760"
|
||||
@ -4846,11 +4902,25 @@ pump@^3.0.0:
|
||||
end-of-stream "^1.1.0"
|
||||
once "^1.3.1"
|
||||
|
||||
qs@6.9.1:
|
||||
version "6.9.1"
|
||||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.1.tgz#20082c65cb78223635ab1a9eaca8875a29bf8ec9"
|
||||
integrity sha512-Cxm7/SS/y/Z3MHWSxXb8lIFqgqBowP5JMlTUFyJN88y0SGQhVmZnqFK/PeuMX9LzUyWsqqhNxIyg0jlzq946yA==
|
||||
|
||||
qs@^6.5.0:
|
||||
version "6.9.4"
|
||||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.4.tgz#9090b290d1f91728d3c22e54843ca44aea5ab687"
|
||||
integrity sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ==
|
||||
|
||||
query-string@^5.0.1:
|
||||
version "5.1.1"
|
||||
resolved "https://registry.yarnpkg.com/query-string/-/query-string-5.1.1.tgz#a78c012b71c17e05f2e3fa2319dd330682efb3cb"
|
||||
integrity sha512-gjWOsm2SoGlgLEdAGt7a6slVOk9mGiXmPFMqrEhLQ68rhQuBnpfs3+EmlvqKyxnCo9/PPlF+9MtY02S1aFg+Jw==
|
||||
dependencies:
|
||||
decode-uri-component "^0.2.0"
|
||||
object-assign "^4.1.0"
|
||||
strict-uri-encode "^1.0.0"
|
||||
|
||||
query-string@^6.13.6:
|
||||
version "6.13.6"
|
||||
resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.13.6.tgz#e5ac7c74f2a5da43fbca0b883b4f0bafba439966"
|
||||
@ -5519,6 +5589,13 @@ snapdragon@^0.8.1:
|
||||
source-map-resolve "^0.5.0"
|
||||
use "^3.1.0"
|
||||
|
||||
sort-keys@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/sort-keys/-/sort-keys-2.0.0.tgz#658535584861ec97d730d6cf41822e1f56684128"
|
||||
integrity sha1-ZYU1WEhh7JfXMNbPQYIuH1ZoQSg=
|
||||
dependencies:
|
||||
is-plain-obj "^1.0.0"
|
||||
|
||||
source-map-resolve@^0.5.0:
|
||||
version "0.5.3"
|
||||
resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.5.3.tgz#190866bece7553e1f8f267a2ee82c606b5509a1a"
|
||||
@ -5605,6 +5682,11 @@ stream-buffers@~2.2.0:
|
||||
resolved "https://registry.yarnpkg.com/stream-buffers/-/stream-buffers-2.2.0.tgz#91d5f5130d1cef96dcfa7f726945188741d09ee4"
|
||||
integrity sha1-kdX1Ew0c75bc+n9yaUUYh0HQnuQ=
|
||||
|
||||
strict-uri-encode@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713"
|
||||
integrity sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=
|
||||
|
||||
strict-uri-encode@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
|
||||
|
Loading…
x
Reference in New Issue
Block a user