1
0
mirror of https://github.com/tooot-app/app synced 2025-03-12 01:20:06 +01:00

Reply working for #638

This commit is contained in:
xmflsct 2023-01-01 16:44:55 +01:00
parent ac9738d358
commit ced71d6611
7 changed files with 44 additions and 18 deletions

View File

@ -552,6 +552,10 @@ declare namespace Mastodon {
language?: string language?: string
text?: string text?: string
filtered?: FilterResult[] filtered?: FilterResult[]
// Internal
_level?: number
_remote?: boolean
} }
type StatusHistory = { type StatusHistory = {

View File

@ -7,9 +7,11 @@ import ComposeRoot from '@screens/Compose/Root'
import { formatText } from '@screens/Compose/utils/processText' import { formatText } from '@screens/Compose/utils/processText'
import { useQueryClient } from '@tanstack/react-query' import { useQueryClient } from '@tanstack/react-query'
import { handleError } from '@utils/api/helpers' import { handleError } from '@utils/api/helpers'
import apiInstance from '@utils/api/instance'
import { RootStackScreenProps } from '@utils/navigation/navigators' import { RootStackScreenProps } from '@utils/navigation/navigators'
import { useInstanceQuery } from '@utils/queryHooks/instance' import { useInstanceQuery } from '@utils/queryHooks/instance'
import { usePreferencesQuery } from '@utils/queryHooks/preferences' import { usePreferencesQuery } from '@utils/queryHooks/preferences'
import { SearchResult } from '@utils/queryHooks/search'
import { useTimelineMutation } from '@utils/queryHooks/timeline' import { useTimelineMutation } from '@utils/queryHooks/timeline'
import { import {
getAccountStorage, getAccountStorage,
@ -155,6 +157,23 @@ const ScreenCompose: React.FC<RootStackScreenProps<'Screen-Compose'>> = ({
content: params.accts.map(acct => `@${acct}`).join(' ') + ' ', content: params.accts.map(acct => `@${acct}`).join(' ') + ' ',
disableDebounce: true 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 break
case 'conversation': case 'conversation':
formatText({ formatText({

View File

@ -1,9 +1,6 @@
import { ComposeAction, ComposeState } from './types' import { ComposeAction, ComposeState } from './types'
const composeReducer = ( const composeReducer = (state: ComposeState, action: ComposeAction): ComposeState => {
state: ComposeState,
action: ComposeAction
): ComposeState => {
switch (action.type) { switch (action.type) {
case 'loadDraft': case 'loadDraft':
const draft = action.payload const draft = action.payload
@ -67,9 +64,7 @@ const composeReducer = (
...state, ...state,
attachments: { attachments: {
...state.attachments, ...state.attachments,
uploads: state.attachments.uploads.filter( uploads: state.attachments.uploads.filter(upload => upload.local?.hash !== action.payload)
upload => upload.local?.hash !== action.payload
)
} }
} }
case 'attachment/delete': case 'attachment/delete':
@ -77,9 +72,7 @@ const composeReducer = (
...state, ...state,
attachments: { attachments: {
...state.attachments, ...state.attachments,
uploads: state.attachments.uploads.filter( uploads: state.attachments.uploads.filter(upload => upload.remote?.id !== action.payload)
upload => upload.remote?.id !== action.payload
)
} }
} }
case 'attachment/edit': case 'attachment/edit':
@ -101,6 +94,8 @@ const composeReducer = (
...state, ...state,
textInputFocus: { ...state.textInputFocus, ...action.payload } textInputFocus: { ...state.textInputFocus, ...action.payload }
} }
case 'updateReply':
return { ...state, replyToStatus: action.payload }
case 'removeReply': case 'removeReply':
return { ...state, replyToStatus: undefined } return { ...state, replyToStatus: undefined }
default: default:

View File

@ -126,6 +126,10 @@ export type ComposeAction =
type: 'textInputFocus' type: 'textInputFocus'
payload: Partial<ComposeState['textInputFocus']> payload: Partial<ComposeState['textInputFocus']>
} }
| {
type: 'updateReply'
payload: Mastodon.Status
}
| { | {
type: 'removeReply' type: 'removeReply'
} }

View File

@ -9,6 +9,7 @@ import apiGeneral from '@utils/api/general'
import apiInstance from '@utils/api/instance' import apiInstance from '@utils/api/instance'
import { getHost } from '@utils/helpers/urlMatcher' import { getHost } from '@utils/helpers/urlMatcher'
import { TabSharedStackScreenProps } from '@utils/navigation/navigators' import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
import { StyleConstants } from '@utils/styles/constants' import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager' import { useTheme } from '@utils/styles/ThemeManager'
import React, { useEffect, useRef, useState } from 'react' 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 flRef = useRef<FlatList>(null)
const scrolled = useRef(false) const scrolled = useRef(false)
const finalData = useRef<(Mastodon.Status & { _level?: number; _remote?: boolean })[]>([ const finalData = useRef<Mastodon.Status[]>([{ ...toot, _level: 0, _remote: false }])
{ ...toot, _level: 0, _remote: false }
])
const highlightIndex = useRef<number>(0) 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( const queryLocal = useQuery(
['Timeline', { page: 'Toot', toot: toot.id, remote: false }], queryKey.local,
async () => { async () => {
const context = await apiInstance<{ const context = await apiInstance<{
ancestors: Mastodon.Status[] ancestors: Mastodon.Status[]
@ -129,7 +132,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
} }
) )
useQuery( useQuery(
['Timeline', { page: 'Toot', toot: toot.id, remote: true }], queryKey.remote,
async () => { async () => {
let context: let context:
| { | {
@ -196,7 +199,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
if (finalData.current?.length < data.pages[0].body.length) { if (finalData.current?.length < data.pages[0].body.length) {
finalData.current = data.pages[0].body.map(remote => { finalData.current = data.pages[0].body.map(remote => {
const localMatch = finalData.current?.find(local => local.uri === remote.uri) 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) setHasRemoteContent(true)
} }
@ -299,7 +302,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
> >
<TimelineDefault <TimelineDefault
item={item} item={item}
queryKey={['Timeline', { page: 'Toot', toot: toot.id }]} queryKey={queryKey.local}
rootQueryKey={rootQueryKey} rootQueryKey={rootQueryKey}
highlighted={toot.id === item.id} highlighted={toot.id === item.id}
isConversation={toot.id !== item.id} isConversation={toot.id !== item.id}

View File

@ -47,6 +47,7 @@ export type QueryKeyTimeline = [
| { | {
page: 'Toot' page: 'Toot'
toot: Mastodon.Status['id'] toot: Mastodon.Status['id']
remote: boolean
} }
) )
] ]

View File

@ -19,7 +19,7 @@ const ManageThemeContext = createContext<ContextType>({
export const useTheme = () => useContext(ManageThemeContext) export const useTheme = () => useContext(ManageThemeContext)
const useColorSchemeDelay = (delay = 50) => { const useColorSchemeDelay = (delay = 250) => {
const [colorScheme, setColorScheme] = React.useState(Appearance.getColorScheme()) const [colorScheme, setColorScheme] = React.useState(Appearance.getColorScheme())
const onColorSchemeChange = React.useCallback( const onColorSchemeChange = React.useCallback(
throttle( throttle(