gab-social/app/javascript/gabsocial/actions/tenor.js

111 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-04-02 05:07:47 +01:00
import api from '../api';
2020-04-30 05:34:50 +01:00
import { me } from '../initial_state'
2020-04-02 04:17:21 +01:00
export const GIFS_CLEAR_RESULTS = 'GIFS_CLEAR_RESULTS'
export const GIF_SET_SELECTED = 'GIF_SET_SELECTED'
export const GIF_CHANGE_SEARCH_TEXT = 'GIF_CHANGE_SEARCH_TEXT'
2020-05-03 06:22:49 +01:00
export const GIF_CLEAR_SELECTED = 'GIF_CLEAR_SELECTED'
2020-04-02 04:17:21 +01:00
export const GIF_RESULTS_FETCH_REQUEST = 'GIF_RESULTS_FETCH_REQUEST'
export const GIF_RESULTS_FETCH_SUCCESS = 'GIF_RESULTS_FETCH_SUCCESS'
export const GIF_RESULTS_FETCH_FAIL = 'GIF_RESULTS_FETCH_FAIL'
export const GIF_CATEGORIES_FETCH_REQUEST = 'GIF_CATEGORIES_FETCH_REQUEST'
export const GIF_CATEGORIES_FETCH_SUCCESS = 'GIF_CATEGORIES_FETCH_SUCCESS'
export const GIF_CATEGORIES_FETCH_FAIL = 'GIF_CATEGORIES_FETCH_FAIL'
2020-04-04 00:18:26 +01:00
// : todo :
2020-04-02 04:17:21 +01:00
export const fetchGifCategories = () => {
2020-04-02 05:07:47 +01:00
return function (dispatch, getState) {
2020-04-02 04:17:21 +01:00
if (!me) return
dispatch(fetchGifCategoriesRequest())
2020-04-17 06:35:46 +01:00
api(getState).get('/api/v1/gifs/categories').then(response => {
2020-04-02 04:17:21 +01:00
dispatch(fetchGifCategoriesSuccess(response.data.tags))
}).catch(function (error) {
dispatch(fetchGifCategoriesFail(error))
})
}
}
2020-04-17 06:35:46 +01:00
export const fetchGifResults = (expand) => {
2020-04-02 04:17:21 +01:00
return function (dispatch, getState) {
if (!me) return
dispatch(fetchGifResultsRequest())
2020-04-17 06:35:46 +01:00
const search = getState().getIn(['tenor', 'searchText'], '');
const pos = 0 //expand ? getState().getIn(['tenor', 'results'], []).length
2020-04-02 04:17:21 +01:00
2020-04-17 06:35:46 +01:00
api(getState).get('/api/v1/gifs/search', { search, pos }).then((response) => {
dispatch(fetchGifResultsSuccess(response.data))
}).catch(function (error) {
dispatch(fetchGifResultsFail(error))
})
2020-04-02 04:17:21 +01:00
}
}
2020-04-17 06:35:46 +01:00
2020-04-02 04:17:21 +01:00
export const clearGifResults = () => ({
type: GIFS_CLEAR_RESULTS,
})
2020-05-02 07:25:55 +01:00
export const clearSelectedGif = () => ({
type: GIF_CLEAR_SELECTED,
result,
})
export const setSelectedGif = (result) => ({
2020-04-02 04:17:21 +01:00
type: GIF_SET_SELECTED,
2020-05-02 07:25:55 +01:00
result,
2020-04-02 04:17:21 +01:00
})
export function changeGifSearchText(text) {
return {
type: GIF_CHANGE_SEARCH_TEXT,
text,
}
}
function fetchGifResultsRequest() {
return {
type: GIF_RESULTS_FETCH_REQUEST,
}
}
2020-04-17 06:35:46 +01:00
function fetchGifResultsSuccess(data) {
2020-04-02 04:17:21 +01:00
return {
type: GIF_RESULTS_FETCH_SUCCESS,
2020-04-17 06:35:46 +01:00
data,
2020-04-02 04:17:21 +01:00
}
}
function fetchGifResultsFail(error) {
return {
type: GIF_RESULTS_FETCH_FAIL,
error,
}
}
function fetchGifCategoriesRequest() {
return {
type: GIF_CATEGORIES_FETCH_REQUEST,
}
}
function fetchGifCategoriesSuccess(categories) {
return {
type: GIF_CATEGORIES_FETCH_SUCCESS,
categories,
}
}
function fetchGifCategoriesFail(error) {
return {
type: GIF_CATEGORIES_FETCH_FAIL,
error,
}
}