mirror of https://github.com/tooot-app/app
Reply working for #638
This commit is contained in:
parent
ac9738d358
commit
ced71d6611
|
@ -552,6 +552,10 @@ declare namespace Mastodon {
|
|||
language?: string
|
||||
text?: string
|
||||
filtered?: FilterResult[]
|
||||
|
||||
// Internal
|
||||
_level?: number
|
||||
_remote?: boolean
|
||||
}
|
||||
|
||||
type StatusHistory = {
|
||||
|
|
|
@ -7,9 +7,11 @@ import ComposeRoot from '@screens/Compose/Root'
|
|||
import { formatText } from '@screens/Compose/utils/processText'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { handleError } from '@utils/api/helpers'
|
||||
import apiInstance from '@utils/api/instance'
|
||||
import { RootStackScreenProps } from '@utils/navigation/navigators'
|
||||
import { useInstanceQuery } from '@utils/queryHooks/instance'
|
||||
import { usePreferencesQuery } from '@utils/queryHooks/preferences'
|
||||
import { SearchResult } from '@utils/queryHooks/search'
|
||||
import { useTimelineMutation } from '@utils/queryHooks/timeline'
|
||||
import {
|
||||
getAccountStorage,
|
||||
|
@ -155,6 +157,23 @@ const ScreenCompose: React.FC<RootStackScreenProps<'Screen-Compose'>> = ({
|
|||
content: params.accts.map(acct => `@${acct}`).join(' ') + ' ',
|
||||
disableDebounce: true
|
||||
})
|
||||
apiInstance<SearchResult>({
|
||||
version: 'v2',
|
||||
method: 'get',
|
||||
url: 'search',
|
||||
params: {
|
||||
q: params.incomingStatus.uri,
|
||||
type: 'statuses',
|
||||
limit: 1,
|
||||
resolve: true
|
||||
}
|
||||
})
|
||||
.then(res => {
|
||||
if (res.body.statuses[0]?.uri === params.incomingStatus.uri) {
|
||||
composeDispatch({ type: 'updateReply', payload: res.body.statuses[0] })
|
||||
}
|
||||
})
|
||||
.catch(() => {})
|
||||
break
|
||||
case 'conversation':
|
||||
formatText({
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
import { ComposeAction, ComposeState } from './types'
|
||||
|
||||
const composeReducer = (
|
||||
state: ComposeState,
|
||||
action: ComposeAction
|
||||
): ComposeState => {
|
||||
const composeReducer = (state: ComposeState, action: ComposeAction): ComposeState => {
|
||||
switch (action.type) {
|
||||
case 'loadDraft':
|
||||
const draft = action.payload
|
||||
|
@ -67,9 +64,7 @@ const composeReducer = (
|
|||
...state,
|
||||
attachments: {
|
||||
...state.attachments,
|
||||
uploads: state.attachments.uploads.filter(
|
||||
upload => upload.local?.hash !== action.payload
|
||||
)
|
||||
uploads: state.attachments.uploads.filter(upload => upload.local?.hash !== action.payload)
|
||||
}
|
||||
}
|
||||
case 'attachment/delete':
|
||||
|
@ -77,9 +72,7 @@ const composeReducer = (
|
|||
...state,
|
||||
attachments: {
|
||||
...state.attachments,
|
||||
uploads: state.attachments.uploads.filter(
|
||||
upload => upload.remote?.id !== action.payload
|
||||
)
|
||||
uploads: state.attachments.uploads.filter(upload => upload.remote?.id !== action.payload)
|
||||
}
|
||||
}
|
||||
case 'attachment/edit':
|
||||
|
@ -101,6 +94,8 @@ const composeReducer = (
|
|||
...state,
|
||||
textInputFocus: { ...state.textInputFocus, ...action.payload }
|
||||
}
|
||||
case 'updateReply':
|
||||
return { ...state, replyToStatus: action.payload }
|
||||
case 'removeReply':
|
||||
return { ...state, replyToStatus: undefined }
|
||||
default:
|
||||
|
|
|
@ -126,6 +126,10 @@ export type ComposeAction =
|
|||
type: 'textInputFocus'
|
||||
payload: Partial<ComposeState['textInputFocus']>
|
||||
}
|
||||
| {
|
||||
type: 'updateReply'
|
||||
payload: Mastodon.Status
|
||||
}
|
||||
| {
|
||||
type: 'removeReply'
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import apiGeneral from '@utils/api/general'
|
|||
import apiInstance from '@utils/api/instance'
|
||||
import { getHost } from '@utils/helpers/urlMatcher'
|
||||
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
||||
import { StyleConstants } from '@utils/styles/constants'
|
||||
import { useTheme } from '@utils/styles/ThemeManager'
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
|
@ -56,12 +57,14 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
|||
const flRef = useRef<FlatList>(null)
|
||||
const scrolled = useRef(false)
|
||||
|
||||
const finalData = useRef<(Mastodon.Status & { _level?: number; _remote?: boolean })[]>([
|
||||
{ ...toot, _level: 0, _remote: false }
|
||||
])
|
||||
const finalData = useRef<Mastodon.Status[]>([{ ...toot, _level: 0, _remote: false }])
|
||||
const highlightIndex = useRef<number>(0)
|
||||
const queryKey: { [key: string]: QueryKeyTimeline } = {
|
||||
local: ['Timeline', { page: 'Toot', toot: toot.id, remote: false }],
|
||||
remote: ['Timeline', { page: 'Toot', toot: toot.id, remote: true }]
|
||||
}
|
||||
const queryLocal = useQuery(
|
||||
['Timeline', { page: 'Toot', toot: toot.id, remote: false }],
|
||||
queryKey.local,
|
||||
async () => {
|
||||
const context = await apiInstance<{
|
||||
ancestors: Mastodon.Status[]
|
||||
|
@ -129,7 +132,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
|||
}
|
||||
)
|
||||
useQuery(
|
||||
['Timeline', { page: 'Toot', toot: toot.id, remote: true }],
|
||||
queryKey.remote,
|
||||
async () => {
|
||||
let context:
|
||||
| {
|
||||
|
@ -196,7 +199,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
|||
if (finalData.current?.length < data.pages[0].body.length) {
|
||||
finalData.current = data.pages[0].body.map(remote => {
|
||||
const localMatch = finalData.current?.find(local => local.uri === remote.uri)
|
||||
return localMatch ? { ...localMatch, _remote: false } : { ...remote, _remote: true }
|
||||
return localMatch || { ...remote, _remote: true }
|
||||
})
|
||||
setHasRemoteContent(true)
|
||||
}
|
||||
|
@ -299,7 +302,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
|||
>
|
||||
<TimelineDefault
|
||||
item={item}
|
||||
queryKey={['Timeline', { page: 'Toot', toot: toot.id }]}
|
||||
queryKey={queryKey.local}
|
||||
rootQueryKey={rootQueryKey}
|
||||
highlighted={toot.id === item.id}
|
||||
isConversation={toot.id !== item.id}
|
||||
|
|
|
@ -47,6 +47,7 @@ export type QueryKeyTimeline = [
|
|||
| {
|
||||
page: 'Toot'
|
||||
toot: Mastodon.Status['id']
|
||||
remote: boolean
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
|
@ -19,7 +19,7 @@ const ManageThemeContext = createContext<ContextType>({
|
|||
|
||||
export const useTheme = () => useContext(ManageThemeContext)
|
||||
|
||||
const useColorSchemeDelay = (delay = 50) => {
|
||||
const useColorSchemeDelay = (delay = 250) => {
|
||||
const [colorScheme, setColorScheme] = React.useState(Appearance.getColorScheme())
|
||||
const onColorSchemeChange = React.useCallback(
|
||||
throttle(
|
||||
|
|
Loading…
Reference in New Issue