Added debouncing to markReadNotifications and fetchComments
• Added: - debouncing to markReadNotifications and fetchComments
This commit is contained in:
parent
1da4cb9f0f
commit
8c7a52065c
@ -1,4 +1,5 @@
|
|||||||
import api, { getLinks } from '../api'
|
import api, { getLinks } from '../api'
|
||||||
|
import debounce from 'lodash.debounce'
|
||||||
import IntlMessageFormat from 'intl-messageformat'
|
import IntlMessageFormat from 'intl-messageformat'
|
||||||
import noop from 'lodash.noop'
|
import noop from 'lodash.noop'
|
||||||
import { fetchRelationships } from './accounts'
|
import { fetchRelationships } from './accounts'
|
||||||
@ -262,9 +263,14 @@ export const setFilter = (path, value) => (dispatch) => {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const markReadNotifications = () => (dispatch, getState) => {
|
export const markReadNotifications = () => (dispatch, getState) => {
|
||||||
if (!me) return
|
if (!me) return
|
||||||
|
debouncedMarkReadNotifications(dispatch, getState)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const debouncedMarkReadNotifications = debounce((dispatch, getState) => {
|
||||||
|
if (!me) return
|
||||||
const topNotification = parseInt(getState().getIn(['notifications', 'items', 0, 'id']))
|
const topNotification = parseInt(getState().getIn(['notifications', 'items', 0, 'id']))
|
||||||
const lastReadId = getState().getIn(['notifications', 'lastReadId'])
|
const lastReadId = getState().getIn(['notifications', 'lastReadId'])
|
||||||
|
|
||||||
@ -278,4 +284,4 @@ export const markReadNotifications = () => (dispatch, getState) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}, 5000, { leading: true })
|
@ -1,3 +1,4 @@
|
|||||||
|
import debounce from 'lodash.debounce'
|
||||||
import api from '../api'
|
import api from '../api'
|
||||||
import openDB from '../storage/db'
|
import openDB from '../storage/db'
|
||||||
import { evictStatus } from '../storage/modifier'
|
import { evictStatus } from '../storage/modifier'
|
||||||
@ -141,7 +142,7 @@ export const editStatus = (status) => (dispatch) => {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export const deleteStatus = (id, routerHistory) => (dispatch, getState) => {
|
export const deleteStatus = (id, routerHistory) => (dispatch, getState) => {
|
||||||
if (!me) return
|
if (!me || !id) return
|
||||||
|
|
||||||
let status = getState().getIn(['statuses', id])
|
let status = getState().getIn(['statuses', id])
|
||||||
|
|
||||||
@ -180,6 +181,8 @@ const deleteStatusFail = (id, error) => ({
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export const fetchContext = (id, ensureIsReply) => (dispatch, getState) => {
|
export const fetchContext = (id, ensureIsReply) => (dispatch, getState) => {
|
||||||
|
if (!id) return
|
||||||
|
|
||||||
if (ensureIsReply) {
|
if (ensureIsReply) {
|
||||||
const isReply = !!getState().getIn(['statuses', id, 'in_reply_to_id'], null)
|
const isReply = !!getState().getIn(['statuses', id, 'in_reply_to_id'], null)
|
||||||
if (!isReply) return
|
if (!isReply) return
|
||||||
@ -225,6 +228,12 @@ const fetchContextFail = (id, error) => ({
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export const fetchComments = (id) => (dispatch, getState) => {
|
export const fetchComments = (id) => (dispatch, getState) => {
|
||||||
|
if (!id) return
|
||||||
|
debouncedFetchComments(id, dispatch, getState)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const debouncedFetchComments = debounce((id, dispatch, getState) => {
|
||||||
|
if (!id) return
|
||||||
dispatch(fetchCommentsRequest(id))
|
dispatch(fetchCommentsRequest(id))
|
||||||
|
|
||||||
api(getState).get(`/api/v1/statuses/${id}/comments`).then((response) => {
|
api(getState).get(`/api/v1/statuses/${id}/comments`).then((response) => {
|
||||||
@ -237,7 +246,8 @@ export const fetchComments = (id) => (dispatch, getState) => {
|
|||||||
|
|
||||||
dispatch(fetchCommentsFail(id, error))
|
dispatch(fetchCommentsFail(id, error))
|
||||||
})
|
})
|
||||||
}
|
}, 5000, { leading: true })
|
||||||
|
|
||||||
|
|
||||||
const fetchCommentsRequest = (id) => ({
|
const fetchCommentsRequest = (id) => ({
|
||||||
type: COMMENTS_FETCH_REQUEST,
|
type: COMMENTS_FETCH_REQUEST,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user