Commit 03bb06b5 authored by Shpuld Shpludson's avatar Shpuld Shpludson

Merge branch 'fix/threadFetcher' into 'master'

Thread fetcher fix

Closes #96

See merge request !90
parents 776370bc aa968355
Pipeline #32027 passed with stages
in 31 minutes
......@@ -12,7 +12,7 @@ import {
} from '@ionic/react'
import { HomeTimeline } from '../timeline/home_timeline'
import Icons from '../common/icons/icons'
import { Thread } from '../thread/thread'
import { Thread } from '../thread/thread.tsx'
import { UserProfile } from '../user_profile/user_profile.tsx'
import { PublicTimeline } from '../timeline/public_timeline'
import { LocalTimeline } from '../timeline/local_timeline'
......
import React, { Component } from 'react'
import { connect } from 'react-redux'
import Pleroma from 'pleroma-api'
import { withRouter } from 'react-router-dom'
import { withRouter, RouteComponentProps } from 'react-router-dom'
import Icons from '../common/icons/icons'
import { Status } from '../status/status.tsx'
import { Status } from '../status/status'
import { IonPage, withIonLifeCycle, IonContent } from '@ionic/react'
import { notFoundErrorCatcher } from '../../utils/api'
import { injectIntl } from 'react-intl'
import StatusType from '../../entities/status'
class ThreadComponent extends Component {
componentDidMount () {
interface ThreadComponentInterface extends RouteComponentProps {
id?: string,
status: StatusType,
getStatusWithContext: Function
}
let updateThreadFetcher: any = null
class ThreadComponent extends Component<ThreadComponentInterface> {
async ionViewDidEnter() {
this.toggleUpdate()
}
ionViewWillLeave() {
async ionViewWillLeave() {
this.toggleUpdate()
}
async componentDidUpdate (previousProps) {
async componentDidUpdate (previousProps: ThreadComponentInterface) {
if (this.props.id !== previousProps.id) {
this.updateThreadFetcher = null
updateThreadFetcher = null
await this.toggleUpdate()
}
}
componentWillUnmount () {
this.toggleUpdate()
}
toggleUpdate = () => {
if (this.updateThreadFetcher) {
clearInterval(this.updateThreadFetcher)
this.updateThreadFetcher = null
if (updateThreadFetcher) {
clearInterval(updateThreadFetcher)
updateThreadFetcher = null
} else {
this.props.getStatusWithContext()
this.updateThreadFetcher = setInterval(this.props.getStatusWithContext, 5000)
const { getStatusWithContext } = this.props
getStatusWithContext()
updateThreadFetcher = setInterval(getStatusWithContext, 5000)
}
}
......@@ -49,11 +55,11 @@ class ThreadComponent extends Component {
<IonContent>
<div className='pt-4 pb-12 md:pb-0 px-6 md:pl-0 md:pr-4 overflow-y-auto overflow-x-hidden'>
{status && <div>
{status.context && status.context.ancestors.map((status) =>
{status.context && status.context.ancestors.map((status: StatusType) =>
<Status key={status.id} status={status} toggleThreadFetcher={this.toggleUpdate} />
)}
{!status.reblog && <Status status={status} toggleThreadFetcher={this.toggleUpdate} />}
{status.context && status.context.descendants.map((status) =>
{status.context && status.context.descendants.map((status: StatusType) =>
<Status key={status.id} status={status} toggleThreadFetcher={this.toggleUpdate} />
)}
</div>}
......@@ -64,12 +70,12 @@ class ThreadComponent extends Component {
}
}
const mapStateToProps = ({ api: { config }, statuses: { statusesByIds } }) => ({
const mapStateToProps = ({ api: { config }, statuses: { statusesByIds } }: { api: { config: any }, statuses: { statusesByIds: any } }) => ({
config,
statusesByIds
})
const mapDispatchToProps = dispatch => ({ dispatch })
const mergeProps = (stateProps, { dispatch }, ownProps) => {
const mapDispatchToProps = (dispatch: Function) => ({ dispatch })
const mergeProps = (stateProps: any, { dispatch }: { dispatch: Function }, ownProps: any) => {
const id = ownProps.match.params.id
const status = stateProps.statusesByIds[id]
......@@ -77,7 +83,7 @@ const mergeProps = (stateProps, { dispatch }, ownProps) => {
id,
status,
getStatusWithContext: () => dispatch(Pleroma.thunks.statuses.getStatusWithContext({ config: stateProps.config, params: { id } }))
.catch((e) => {
.catch((e: Error) => {
if (e.name === 'NotFoundError') {
dispatch(Pleroma.reducers.statuses.actions.deleteStatus({ statusId: id }))
}
......
......@@ -50,6 +50,10 @@ export default class Status {
summary: string = ''
favourited_by?: Account[]
reblogged_by?: Account[]
context?: {
ancestors: Status[]
descendants: Status[]
}
// for API requests
status?: string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment