Added link/PreviewCard search to search
• Added: - link/PreviewCard search to search
This commit is contained in:
@@ -4,6 +4,8 @@ export const LINK_FETCH_REQUEST = 'LINK_FETCH_REQUEST'
|
||||
export const LINK_FETCH_SUCCESS = 'LINK_FETCH_SUCCESS'
|
||||
export const LINK_FETCH_FAIL = 'LINK_FETCH_FAIL'
|
||||
|
||||
export const IMPORT_LINK_CARDS = 'IMPORT_LINK_CARDS'
|
||||
|
||||
export const fetchLinkCard = (cardId) => (dispatch, getState) => {
|
||||
dispatch(fetchLinkCardRequest(cardId))
|
||||
|
||||
@@ -27,4 +29,9 @@ export const fetchLinkCardFail = (error, cardId) => ({
|
||||
type: LINK_FETCH_FAIL,
|
||||
error,
|
||||
cardId,
|
||||
})
|
||||
|
||||
export const importLinkCards = (cards) => ({
|
||||
type: IMPORT_LINK_CARDS,
|
||||
cards,
|
||||
})
|
||||
@@ -1,7 +1,11 @@
|
||||
import api from '../api';
|
||||
import { fetchRelationships } from './accounts';
|
||||
import { fetchGroupsSuccess, fetchGroupRelationships } from './groups'
|
||||
import { importFetchedAccounts, importFetchedStatuses } from './importer';
|
||||
import {
|
||||
importFetchedAccounts,
|
||||
importFetchedStatuses,
|
||||
} from './importer';
|
||||
import { importLinkCards } from './links'
|
||||
import { SEARCH_FILTERS } from '../constants'
|
||||
|
||||
export const SEARCH_CHANGE = 'SEARCH_CHANGE';
|
||||
@@ -52,6 +56,10 @@ export function submitSearch() {
|
||||
dispatch(importFetchedStatuses(response.data.statuses));
|
||||
}
|
||||
|
||||
if (response.data.links) {
|
||||
dispatch(importLinkCards(response.data.links));
|
||||
}
|
||||
|
||||
if (response.data.groups) {
|
||||
dispatch(fetchGroupsSuccess(response.data.groups))
|
||||
dispatch(fetchGroupRelationships(response.data.groups.map(item => item.id)))
|
||||
@@ -99,4 +107,4 @@ export function setFilter(path, value, shouldSubmit) {
|
||||
})
|
||||
if (shouldSubmit) dispatch(submitSearch())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
LINK_FETCH_REQUEST,
|
||||
LINK_FETCH_SUCCESS,
|
||||
LINK_FETCH_FAIL,
|
||||
IMPORT_LINK_CARDS,
|
||||
} from '../actions/links'
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
@@ -27,6 +28,13 @@ export default function links(state = initialState, action) {
|
||||
mutable.set('isFetched', false)
|
||||
mutable.set('isError', false)
|
||||
})
|
||||
case IMPORT_LINK_CARDS:
|
||||
return state.withMutations((mutable) => {
|
||||
action.cards.forEach((card) => mutable.setIn(['items', `${card.id}`], fromJS(card)))
|
||||
mutable.set('isLoading', false)
|
||||
mutable.set('isFetched', false)
|
||||
mutable.set('isError', false)
|
||||
})
|
||||
case LINK_FETCH_FAIL:
|
||||
return state.withMutations((mutable) => {
|
||||
mutable.set('isLoading', false)
|
||||
|
||||
@@ -60,6 +60,7 @@ export default function search(state = initialState, action) {
|
||||
return state.set('results', ImmutableMap({
|
||||
accounts: ImmutableList(action.results.accounts.map(item => item.id)),
|
||||
statuses: ImmutableList(action.results.statuses.map(item => item.id)),
|
||||
links: ImmutableList(action.results.links.map(item => item.id)),
|
||||
hashtags: fromJS(action.results.hashtags),
|
||||
groups: fromJS(action.results.groups),
|
||||
})).set('submitted', true).set('isLoading', false).set('isError', false);
|
||||
|
||||
Reference in New Issue
Block a user