[ABANDONED] React/Redux front end for the Flexor social network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

48 lines
1.5 KiB

import { apiFetch } from 'src/api'
import { setEntities } from 'src/actions/entities'
import { startRequest, finishRequest } from 'src/actions/requests'
import { objectToQuerystring } from 'src/utils'
import { normalize } from 'src/utils/normalization'
import { AppThunkAction, RequestKey, EntityType, App }from 'src/types'
interface AppsResponse {
apps: App[]
continuation?: string
}
export const fetchApps = (sort?: string, continuation?: string): AppThunkAction => async dispatch => {
dispatch(startRequest(RequestKey.FetchApps))
try {
const response = await apiFetch<AppsResponse>({
path: `/api/apps?${objectToQuerystring({ sort, continuation })}`,
})
const apps = normalize(response.apps, EntityType.App)
dispatch(setEntities(apps.entities))
dispatch(finishRequest(RequestKey.FetchApps, true))
} catch (err) {
dispatch(finishRequest(RequestKey.FetchApps, false))
throw err
}
}
export const fetchSelfApps = (sort?: string): AppThunkAction => async dispatch => {
dispatch(startRequest(RequestKey.FetchSelfApps))
try {
const response = await apiFetch<AppsResponse>({
path: `/api/self/apps?${objectToQuerystring({ sort })}`,
})
const apps = normalize(response.apps, EntityType.App)
dispatch(setEntities(apps.entities))
dispatch(finishRequest(RequestKey.FetchSelfApps, true))
} catch (err) {
dispatch(finishRequest(RequestKey.FetchSelfApps, false))
throw err
}
}