UNPKG

frc-ui

Version:

React Web UI

138 lines (137 loc) 4.82 kB
import { LocalStorageKey } from '../interfaces'; import { getLocalStorageItem } from '../common'; import { chat, chatGag, tender } from './urls'; export default (prefix) => [ { key: 'chat', initialState: { channel: 'credBChat', isOpen: false, showSetting: false, isAnonymous: getLocalStorageItem(LocalStorageKey.isAnonymous, 'false') === 'true', fontSize: getLocalStorageItem(LocalStorageKey.danmakuFontSize, 12) || 12, colorIndex: '#FFFFFF', history: false, emo: undefined, selectMessageId: null }, loading: (state, action) => { return Object.assign({}, state, Object.assign({}, action.payload)); } }, { key: 'chatMessage.clientCount', method: 'get', url: (code) => `${prefix}${chat}clients/count?chatRoomCode=${code}` }, { key: 'chatMessage.history', initialState: { pageInfo: { startIndex: 0, totalSize: 0, endIndex: 0 }, result: [], enableLoad: true }, method: 'post', url: () => `${prefix}${chat}chat/messages/query`, loading: (state) => { const h = Object.assign({}, state.history); h.pageInfo = { startIndex: 0, totalSize: 0, endIndex: 0 }; h.result = []; h.loading = true; h.success = false; h.enableLoad = true; return h; }, success: (state, action) => { const h = Object.assign({}, state.history); const { pageInfo, result } = action.result; h.pageInfo = Object.assign(Object.assign({}, h.pageInfo), pageInfo); h.result = [...(result || []), ...(h.result || [])]; h.result.sort(function (a, b) { return a.time - b.time; }); h.loading = false; h.success = true; h.enableLoad = (result || []).length >= action.payload.pageSize; h.status = action.status; return h; } }, { key: 'chatMessage.histories', initialState: { pageInfo: { startIndex: 0, totalSize: 0, endIndex: 0 }, result: [], enableLoad: true }, method: 'post', url: () => `${prefix}${chat}chat/messages/query`, loading: (state, action) => { const h = Object.assign({}, state.histories); if (action.payload.startIndex === 0) { h.pageInfo = { startIndex: 0, totalSize: 0, endIndex: 0 }; h.result = []; } h.loading = true; h.success = false; h.enableLoad = true; return h; }, success: (state, action) => { const h = Object.assign({}, state.histories); const { pageInfo, result } = action.result || {}; if (action.payload === 'clear') { h.pageInfo = { startIndex: 0, totalSize: 0, endIndex: 0 }; h.result = []; h.enableLoad = true; } else { h.pageInfo = Object.assign(Object.assign({}, h.pageInfo), pageInfo); h.result = [...(result || []), ...(h.result || [])]; h.result.sort(function (a, b) { return a.time - b.time; }); h.enableLoad = (result || []).length >= action.payload.pageSize; } h.loading = false; h.success = true; return h; } }, { key: 'chatMessage.anonymousName', method: 'get', url: (code) => `${prefix}${chat}anonnames/anonname?chatRoomCode=${code}` }, { key: 'chatGag.gag', method: 'post', url: ({ userId, chatRoomCode }) => `${prefix}${chatGag}gaguser?userId=${userId}&chatRoomCode=${chatRoomCode}` }, { key: 'chatGag.isGag', method: 'get', url: ({ userId, chatRoomCode }) => `${prefix}${chatGag}isag?userId=${userId}&chatRoomCode=${chatRoomCode}` }, { key: 'chatGag.ungag', method: 'delete', url: ({ userId, chatRoomCode }) => `${prefix}${chatGag}gaguser?userId=${userId}&chatRoomCode=${chatRoomCode}` }, { key: 'chatPermission', method: 'get', url: (code) => `${prefix}${chat}chatrooms/users/user/permissions?chatRoomCode=${code}` }, { key: 'chatTrend.type', method: 'get', url: () => `${prefix}${tender}market/trend/vote` }, { key: 'chatTrend.change', method: 'put', url: (trendType) => `${prefix}${tender}market/trend/vote?trend=${trendType}`, body: () => null } ];