mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-13 17:27:37 -05:00
cleaned things up
This commit is contained in:
@@ -10,7 +10,6 @@ import {
|
|||||||
Dropdown
|
Dropdown
|
||||||
} from "semantic-ui-react";
|
} from "semantic-ui-react";
|
||||||
import "./FilterModal.css";
|
import "./FilterModal.css";
|
||||||
import * as types from "./call-constants";
|
|
||||||
|
|
||||||
function GroupModal (props) {
|
function GroupModal (props) {
|
||||||
const shortName = useSelector((state) => state.callPlayer.shortName);
|
const shortName = useSelector((state) => state.callPlayer.shortName);
|
||||||
|
|||||||
@@ -1,358 +0,0 @@
|
|||||||
import axios from "axios";
|
|
||||||
|
|
||||||
import * as types from "./call-constants";
|
|
||||||
import { push } from 'connected-react-router';
|
|
||||||
|
|
||||||
function beginFetchCallInfo() {
|
|
||||||
return { type: types.FETCH_CALL_INFO };
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchCallInfoSuccess(data) {
|
|
||||||
return { type: types.FETCH_SUCCESS_CALL_INFO,
|
|
||||||
data };
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchCallInfoError(data) {
|
|
||||||
return { type: types.FETCH_ERROR_CALL_INFO,
|
|
||||||
data };
|
|
||||||
}
|
|
||||||
|
|
||||||
function prependCall() {
|
|
||||||
return { type: types.PREPEND_CALL };
|
|
||||||
}
|
|
||||||
|
|
||||||
function beginAddStar() {
|
|
||||||
return { type: types.ADD_STAR };
|
|
||||||
}
|
|
||||||
|
|
||||||
function addStarSuccess(data) {
|
|
||||||
return { type: types.ADD_STAR_SUCCESS, data };
|
|
||||||
}
|
|
||||||
|
|
||||||
function addStarError(data) {
|
|
||||||
return { type: types.ADD_STAR_ERROR, data };
|
|
||||||
}
|
|
||||||
|
|
||||||
function beginFetchCall() {
|
|
||||||
return { type: types.FETCH_CALL };
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchCallSuccess(data) {
|
|
||||||
return { type: types.FETCH_SUCCESS_CALL,
|
|
||||||
data };
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function fetchOlderCallSuccess(data) {
|
|
||||||
return { type: types.FETCH_SUCCESS_OLDER_CALL,
|
|
||||||
data };
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchNewerCallSuccess(data) {
|
|
||||||
return { type: types.FETCH_SUCCESS_NEWER_CALL,
|
|
||||||
data };
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchCallError(data) {
|
|
||||||
return { type: types.FETCH_ERROR_CALL,
|
|
||||||
data };
|
|
||||||
}
|
|
||||||
|
|
||||||
// The data field should be a JS date object
|
|
||||||
export function setCallTime(data) {
|
|
||||||
return {type: types.SET_CALL_TIME, data};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function changeUrl(url) {
|
|
||||||
return dispatch => {
|
|
||||||
dispatch(push(url));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Example of an Async Action Creator
|
|
||||||
// http://redux.js.org/docs/advanced/AsyncActions.html
|
|
||||||
|
|
||||||
function shouldFetchCalls(state, subreddit) {
|
|
||||||
return true;
|
|
||||||
if ((!state.call.items) || (state.call.items.length <1)) {
|
|
||||||
return true
|
|
||||||
} else if (state.call.isWaiting) {
|
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function buildUrlParams(a) {
|
|
||||||
return Object.keys(a).map(function(k) {
|
|
||||||
return encodeURIComponent(k) + '=' + encodeURIComponent(a[k])
|
|
||||||
}).join('&')
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildCallUrl(state, date, direction) {
|
|
||||||
var params = {};
|
|
||||||
var url = "";
|
|
||||||
|
|
||||||
|
|
||||||
if ((typeof direction === 'string') && (typeof date === 'number')) {
|
|
||||||
url = url + '/' + direction;
|
|
||||||
params["time"] = date;
|
|
||||||
} else {
|
|
||||||
if (state.call.filterDate){
|
|
||||||
url = url + '/older'
|
|
||||||
params["time"] = state.call.filterDate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (state.call.filterStarred) {
|
|
||||||
params["filter-starred"] = true;
|
|
||||||
}
|
|
||||||
switch(state.call.filterType) {
|
|
||||||
case 1:
|
|
||||||
params["filter-type"] = "group";
|
|
||||||
params["filter-code"] = state.call.filterGroupId;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
params["filter-type"] = "talkgroup";
|
|
||||||
params["filter-code"] = state.call.filterTalkgroups;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
case 0:
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
|
|
||||||
if (this.filterCode != "") {
|
|
||||||
params["filter-code"] = this.filterCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.filterType == this.FilterType.Group) {
|
|
||||||
params["filter-type"] = "group";
|
|
||||||
params["filter-name"] = this.filterName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.filterType == this.FilterType.Talkgroup) {
|
|
||||||
params["filter-type"] = "talkgroup";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.filterType == this.FilterType.Unit) {
|
|
||||||
params["filter-type"] = "unit";
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
// url = startUp.backend_server + "/" + startUp.shortName.toLowerCase() + "/calls" + url + '?' + buildUrlParams(params);
|
|
||||||
url = process.env.REACT_APP_BACKEND_SERVER + "/" + state.call.shortName + "/calls" + url + '?' + buildUrlParams(params);
|
|
||||||
console.log("Trying to fetch data from this url: " + url);
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function fetchNewerCalls(timestamp) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
const state = getState();
|
|
||||||
if (shouldFetchCalls(state)) {
|
|
||||||
dispatch(beginFetchCall());
|
|
||||||
const url = buildCallUrl(state, timestamp, "newer")
|
|
||||||
return axios
|
|
||||||
.get(url)
|
|
||||||
.then(response => {
|
|
||||||
if ((response.data) && (response.data.calls.length >0)) {
|
|
||||||
var data = {shortName: state.call.shortName, calls: response.data.calls}
|
|
||||||
dispatch(fetchNewerCallSuccess(data));
|
|
||||||
} else {
|
|
||||||
dispatch(fetchCallError());
|
|
||||||
let registerMessage = response.data.message;
|
|
||||||
return registerMessage;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(response => {
|
|
||||||
if (response instanceof Error) {
|
|
||||||
// Something happened in setting up the request that triggered an Error
|
|
||||||
console.log("Error", response.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function fetchOlderCalls( timestamp) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
const state = getState();
|
|
||||||
if (shouldFetchCalls(state)) {
|
|
||||||
dispatch(beginFetchCall());
|
|
||||||
const url = buildCallUrl(state, timestamp, "older")
|
|
||||||
return axios
|
|
||||||
.get(url)
|
|
||||||
.then(response => {
|
|
||||||
if (response.data) {
|
|
||||||
var data = {shortName: state.call.shortName, calls: response.data.calls}
|
|
||||||
dispatch(fetchOlderCallSuccess(data));
|
|
||||||
} else {
|
|
||||||
dispatch(fetchCallError());
|
|
||||||
let registerMessage = response.data.message;
|
|
||||||
return registerMessage;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(response => {
|
|
||||||
if (response instanceof Error) {
|
|
||||||
// Something happened in setting up the request that triggered an Error
|
|
||||||
console.log("Error", response.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function addStar( callId) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
const state = getState();
|
|
||||||
dispatch(beginAddStar());
|
|
||||||
|
|
||||||
const url = process.env.REACT_APP_BACKEND_SERVER + "/" + state.call.shortName.toLowerCase() + "/star/" + callId
|
|
||||||
return axios
|
|
||||||
.post(url,{}, {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
|
||||||
}
|
|
||||||
}).then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
dispatch(addStarSuccess(response.data.call));
|
|
||||||
} else {
|
|
||||||
dispatch(addStarError());
|
|
||||||
let registerMessage = response.data.message;
|
|
||||||
return registerMessage;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(response => {
|
|
||||||
if (response instanceof Error) {
|
|
||||||
// Something happened in setting up the request that triggered an Error
|
|
||||||
console.log("Error", response.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function fetchCallInfo( callId) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
const state = getState();
|
|
||||||
dispatch(beginFetchCallInfo());
|
|
||||||
|
|
||||||
const url = process.env.REACT_APP_BACKEND_SERVER + "/" + state.call.shortName.toLowerCase() + "/call/" + callId
|
|
||||||
return axios
|
|
||||||
.get(url)
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
dispatch(fetchCallInfoSuccess(response.data.call));
|
|
||||||
} else {
|
|
||||||
dispatch(fetchCallInfoError());
|
|
||||||
let registerMessage = response.data.message;
|
|
||||||
return registerMessage;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(response => {
|
|
||||||
if (response instanceof Error) {
|
|
||||||
// Something happened in setting up the request that triggered an Error
|
|
||||||
console.log("Error", response.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export function fetchCalls() {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
const state = getState();
|
|
||||||
if (shouldFetchCalls(state)) {
|
|
||||||
dispatch(beginFetchCall());
|
|
||||||
const url=buildCallUrl(state);
|
|
||||||
return axios
|
|
||||||
.get(url)
|
|
||||||
.then(response => {
|
|
||||||
if (response.data) {
|
|
||||||
// check to make sure you actually got some calls back.
|
|
||||||
if (response.data.calls.length > 0) {
|
|
||||||
var data = {shortName: state.call.shortName, calls: response.data.calls}
|
|
||||||
dispatch(fetchCallSuccess(data));
|
|
||||||
} else {
|
|
||||||
dispatch(fetchCallError());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dispatch(fetchCallError());
|
|
||||||
let registerMessage = response.data.message;
|
|
||||||
return registerMessage;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(response => {
|
|
||||||
if (response instanceof Error) {
|
|
||||||
// Something happened in setting up the request that triggered an Error
|
|
||||||
console.log("Error", response.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function addCall(call) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
dispatch({ type: types.UPSERT_CALL, data: call});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setStarred(starred) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
dispatch({ type: types.SET_STARRED_FILTER, data: starred});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setLive(live) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
dispatch({ type: types.SET_LIVE, data: live});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setCurrentCallId(callId) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
dispatch({ type: types.SET_CURRENT_CALL_ID, data: callId});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// should be as a unix timestamp
|
|
||||||
export function setDateFilter(date) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
dispatch({ type: types.SET_DATE_FILTER, date: date});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setAllFilter() {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
dispatch({ type: types.SET_ALL_FILTER});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setTalkgroupFilter(tgs) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
dispatch({ type: types.SET_TALKGROUP_FILTER, talkgroups: tgs});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setGroupFilter(groupId) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
dispatch({ type: types.SET_GROUP_FILTER, groupId: groupId});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setShortName(shortName) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
dispatch({ type: types.SET_SHORT_NAME, data: shortName});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setFilter(filter) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
dispatch({ type: types.SET_FILTER, data: filter});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
export const PREPEND_CALL = "PREPEND_CALL"
|
|
||||||
export const ADD_STAR = "ADD_STAR"
|
|
||||||
export const ADD_STAR_SUCCESS = "ADD_STAR_SUCCESS"
|
|
||||||
export const ADD_STAR_ERROR = "ADD_STAR_ERROR"
|
|
||||||
export const UPSERT_CALL = "UPSERT_CALL"
|
|
||||||
export const FETCH_CALL = "FETCH_CALL"
|
|
||||||
export const FETCH_SUCCESS_CALL = "FETCH_SUCCESS_CALL"
|
|
||||||
export const FETCH_SUCCESS_NEWER_CALL = "FETCH_SUCCESS_NEWER_CALL"
|
|
||||||
export const FETCH_SUCCESS_OLDER_CALL = "FETCH_SUCCESS_OLDER_CALL"
|
|
||||||
export const FETCH_ERROR_CALL = "FETCH_ERROR_CALL"
|
|
||||||
export const SET_SHORT_NAME = "SET_SHORT_NAME"
|
|
||||||
export const FETCH_CALL_INFO = "FETCH_CALL_INFO"
|
|
||||||
export const FETCH_SUCCESS_CALL_INFO = "FETCH_SUCCESS_CALL_INFO"
|
|
||||||
export const FETCH_ERROR_CALL_INFO = "FETCH_ERROR_CALL_INFO"
|
|
||||||
export const SET_ALL_FILTER = "SET_ALL_FILTER"
|
|
||||||
export const SET_GROUP_FILTER = "SET_GROUP_FILTER"
|
|
||||||
export const SET_TALKGROUP_FILTER = "SET_TALKGROUP_FILTER"
|
|
||||||
export const SET_DATE_FILTER = "SET_DATE_FILTER"
|
|
||||||
export const SET_FILTER = "SET_FILTER"
|
|
||||||
export const SET_STARRED_FILTER = "SET_STARRED_FILTER"
|
|
||||||
export const SET_LIVE = "SET_LIVE"
|
|
||||||
export const SET_CALL_TIME = "SET_CALL_TIME"
|
|
||||||
export const SET_CURRENT_CALL_ID = "SET_CURRENT_CALL_ID"
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import { useGetGroupsQuery, useGetCallsQuery } from '../features/api/apiSlice'
|
|
||||||
|
|
||||||
export const Groups = (args) => {
|
|
||||||
|
|
||||||
const { data, isError, isLoading, isSuccess,error } = useGetGroupsQuery(args.shortName);
|
|
||||||
|
|
||||||
let content
|
|
||||||
|
|
||||||
if (isLoading) {
|
|
||||||
content = <div>Loading...</div>
|
|
||||||
} else if (isSuccess) {
|
|
||||||
|
|
||||||
for (const num in data) {
|
|
||||||
const group = data[num];
|
|
||||||
content = <li>{group.groupName}</li>;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (isError) {
|
|
||||||
content = <div>{error.toString()}</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<section className="posts-list">
|
|
||||||
<h2>Group</h2>
|
|
||||||
{content}
|
|
||||||
</section>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const Calls = (args) => {
|
|
||||||
|
|
||||||
const { data, isError, isLoading, isSuccess,error } = useGetCallsQuery({shortName: args.shortName});
|
|
||||||
|
|
||||||
let content
|
|
||||||
|
|
||||||
if (isLoading) {
|
|
||||||
content = <div>Loading...</div>
|
|
||||||
} else if (isSuccess) {
|
|
||||||
|
|
||||||
for (const num in data) {
|
|
||||||
const group = data[num];
|
|
||||||
content = <li>{group.groupName}</li>;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (isError) {
|
|
||||||
content = <div>{error.toString()}</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<section className="posts-list">
|
|
||||||
<h2>Group</h2>
|
|
||||||
{content}
|
|
||||||
</section>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,230 +0,0 @@
|
|||||||
import {
|
|
||||||
FETCH_CALL_INFO,
|
|
||||||
FETCH_SUCCESS_CALL_INFO,
|
|
||||||
FETCH_ERROR_CALL_INFO,
|
|
||||||
FETCH_CALL,
|
|
||||||
PREPEND_CALL,
|
|
||||||
UPSERT_CALL,
|
|
||||||
FETCH_SUCCESS_CALL,
|
|
||||||
FETCH_SUCCESS_OLDER_CALL,
|
|
||||||
FETCH_SUCCESS_NEWER_CALL,
|
|
||||||
FETCH_ERROR_CALL,
|
|
||||||
SET_SHORT_NAME,
|
|
||||||
SET_ALL_FILTER,
|
|
||||||
SET_GROUP_FILTER,
|
|
||||||
SET_TALKGROUP_FILTER,
|
|
||||||
SET_DATE_FILTER,
|
|
||||||
SET_STARRED_FILTER,
|
|
||||||
SET_FILTER,
|
|
||||||
SET_CURRENT_CALL_ID,
|
|
||||||
SET_LIVE,
|
|
||||||
SET_CALL_TIME,
|
|
||||||
ADD_STAR_SUCCESS
|
|
||||||
} from "./call-constants";
|
|
||||||
|
|
||||||
function updateObject(oldObject, newValues) {
|
|
||||||
// Encapsulate the idea of passing a new object as the first parameter
|
|
||||||
// to Object.assign to ensure we correctly copy data instead of mutating
|
|
||||||
return Object.assign({}, oldObject, newValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateCallInItems(calls, action) {
|
|
||||||
return calls.map( (item) => {
|
|
||||||
if (item._id !== action.data._id) {
|
|
||||||
// This isn't the item we care about - keep it as-is
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, this is the one we want - return an updated value
|
|
||||||
return {
|
|
||||||
...action.data
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
function updateObjectInArray(array, action) {
|
|
||||||
return array.map((item, index) => {
|
|
||||||
if (index !== action.index) {
|
|
||||||
// This isn't the item we care about - keep it as-is
|
|
||||||
return item
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, this is the one we want - return an updated value
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
...action.item
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateObjectInArray(array, shortName, updatedItem) {
|
|
||||||
return array.map( item => {
|
|
||||||
if(item.shortName !== shortName) {
|
|
||||||
// This isn't the item we care about - keep it as-is
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, this is the one we want - return an updated value
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
...updatedItem
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
const now = new Date();
|
|
||||||
const call = (
|
|
||||||
state = {
|
|
||||||
isWaiting: false,
|
|
||||||
shortName: "",
|
|
||||||
byId: {},
|
|
||||||
allIds: [],
|
|
||||||
oldestCallTime: now,
|
|
||||||
newestCallTime: now,
|
|
||||||
filterType: 0,
|
|
||||||
filterTalkgroups: [],
|
|
||||||
filterGroupId: false,
|
|
||||||
filterDate: false,
|
|
||||||
filterStarred: false,
|
|
||||||
currentCallId: false,
|
|
||||||
live: false
|
|
||||||
},
|
|
||||||
action
|
|
||||||
) => {
|
|
||||||
switch (action.type) {
|
|
||||||
|
|
||||||
case SET_CURRENT_CALL_ID:
|
|
||||||
return Object.assign({}, state, {currentCallId: action.data});
|
|
||||||
|
|
||||||
case SET_CALL_TIME:
|
|
||||||
return Object.assign({}, state, {newestCallTime: action.data, oldestCallTime: action.data });
|
|
||||||
case SET_FILTER:
|
|
||||||
{
|
|
||||||
var filter={};
|
|
||||||
filter.live = !action.data.live ? state.live : action.data.live;
|
|
||||||
filter.filterStarred = !action.data.filterStarred ? false : action.data.filterStarred;
|
|
||||||
filter.filterType = !action.data.filterType ? 0 : action.data.filterType;
|
|
||||||
filter.filterTalkgroups = !action.data.filterTalkgroups ? [] : action.data.filterTalkgroups;
|
|
||||||
filter.filterGroupId = !action.data.filterGroupId ? false : action.data.filterGroupId;
|
|
||||||
filter.filterDate = !action.data.filterDate ? 0 : action.data.filterDate;
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
live: action.data.live,
|
|
||||||
filterType: action.data.filterType,
|
|
||||||
filterTalkgroups: action.data.filterTalkgroups,
|
|
||||||
filterGroupId: action.data.filterGroupId,
|
|
||||||
filterDate: action.data.filterDate,
|
|
||||||
filterStarred: action.data.filterStarred
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
case SET_LIVE:
|
|
||||||
return Object.assign({}, state, {live: action.data});
|
|
||||||
|
|
||||||
case SET_SHORT_NAME:
|
|
||||||
return Object.assign({}, state, {shortName: action.data});
|
|
||||||
|
|
||||||
case SET_DATE_FILTER:
|
|
||||||
return Object.assign({}, state, {filterDate: action.date});
|
|
||||||
|
|
||||||
case SET_STARRED_FILTER:
|
|
||||||
return Object.assign({}, state, {filterStarred: action.data});
|
|
||||||
|
|
||||||
case SET_ALL_FILTER:
|
|
||||||
return Object.assign({}, state, {filterType: 0, filterTalkgroups:[], filterGroupId: false});
|
|
||||||
|
|
||||||
case SET_GROUP_FILTER:
|
|
||||||
return Object.assign({}, state, {filterType: 1, filterTalkgroups:[], filterGroupId: action.groupId});
|
|
||||||
|
|
||||||
case SET_TALKGROUP_FILTER:
|
|
||||||
return Object.assign({}, state, {filterType: 2, filterTalkgroups: action.talkgroups, filterGroupId: false});
|
|
||||||
|
|
||||||
case FETCH_CALL_INFO:
|
|
||||||
case FETCH_CALL:
|
|
||||||
return Object.assign({}, state, { isWaiting: true});
|
|
||||||
|
|
||||||
case FETCH_SUCCESS_CALL_INFO:
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
byId: {...state.byId, [action.data._id]: action.data },
|
|
||||||
isWaiting: false
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
case ADD_STAR_SUCCESS:
|
|
||||||
return Object.assign({}, state,{
|
|
||||||
byId: {...state.byId, [action.data._id]: action.data },
|
|
||||||
isWaiting: false
|
|
||||||
|
|
||||||
});
|
|
||||||
// This will set the items to the rx data
|
|
||||||
case FETCH_SUCCESS_CALL:
|
|
||||||
{
|
|
||||||
const byId = action.data.calls.reduce((acc, call) => ({ ...acc, [call._id]: call }), {});
|
|
||||||
const allIds = action.data.calls.map(call => call._id);
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
isWaiting: false,
|
|
||||||
shortName: action.data.shortName,
|
|
||||||
newestCallTime: new Date(action.data.calls[0].time),
|
|
||||||
oldestCallTime: new Date(action.data.calls[action.data.calls.length-1].time),
|
|
||||||
byId: { ...byId},
|
|
||||||
allIds: [...allIds]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
case UPSERT_CALL:
|
|
||||||
if (typeof state.byId[action.data._id] !== "undefined") {
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
byId: {...state.byId, [action.data._id]: action.data },
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
newestCallTime: new Date(action.data.time),
|
|
||||||
byId: {[action.data._id]: action.data, ...state.byId},
|
|
||||||
allIds: [action.data._id, ...state.allIds]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
case PREPEND_CALL:
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
isWaiting: false,
|
|
||||||
newestCallTime: new Date(action.data.time),
|
|
||||||
byId: {[action.data._id]: action.data, ...state.byId},
|
|
||||||
allIds: [action.data._id, ...state.allIds]
|
|
||||||
});
|
|
||||||
|
|
||||||
// This will add the array of Calls in the data to the beginning of the existing array of Calls
|
|
||||||
case FETCH_SUCCESS_NEWER_CALL:
|
|
||||||
const byId = action.data.calls.reduce((acc, call) => ({ ...acc, [call._id]: call }), {});
|
|
||||||
const allIds = action.data.calls.map(call => call._id).reverse();
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
isWaiting: false,
|
|
||||||
shortName: action.data.shortName,
|
|
||||||
newestCallTime: new Date(action.data.calls[action.data.calls.length-1].time),
|
|
||||||
byId: {...state.byId, ...byId},
|
|
||||||
allIds: [...allIds, ...state.allIds]
|
|
||||||
});
|
|
||||||
|
|
||||||
// This will add the array of Calls in the data to the end of the existing array of Calls
|
|
||||||
case FETCH_SUCCESS_OLDER_CALL:
|
|
||||||
{
|
|
||||||
const byId = action.data.calls.reduce((acc, call) => ({ ...acc, [call._id]: call }), {});
|
|
||||||
const allIds = action.data.calls.map(call => call._id);
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
isWaiting: false,
|
|
||||||
shortName: action.data.shortName,
|
|
||||||
oldestCallTime: new Date(action.data.calls[action.data.calls.length-1].time),
|
|
||||||
byId: {...state.byId, ...byId},
|
|
||||||
allIds: [ ...state.allIds, ...allIds]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
case FETCH_ERROR_CALL_INFO:
|
|
||||||
case FETCH_ERROR_CALL:
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
isWaiting: false
|
|
||||||
});
|
|
||||||
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default call;
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
import axios from "axios";
|
|
||||||
//import { browserHistory } from "react-router"
|
|
||||||
import * as types from "./group-constants";
|
|
||||||
import { push } from 'connected-react-router';
|
|
||||||
|
|
||||||
// "Log In" action creators
|
|
||||||
|
|
||||||
|
|
||||||
function beginFetchGroup() {
|
|
||||||
return { type: types.FETCH_GROUP };
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchGroupSuccess(data) {
|
|
||||||
return {
|
|
||||||
type: types.FETCH_SUCCESS_GROUP,
|
|
||||||
data
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchGroupError(data) {
|
|
||||||
return {
|
|
||||||
type: types.FETCH_ERROR_GROUP,
|
|
||||||
data
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function changeUrl(url) {
|
|
||||||
return dispatch => {
|
|
||||||
dispatch(push(url));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Example of an Async Action Creator
|
|
||||||
// http://redux.js.org/docs/advanced/AsyncActions.html
|
|
||||||
|
|
||||||
|
|
||||||
function shouldFetchGroups(state,shortName) {
|
|
||||||
if (!state.group.items || !state.group.items[shortName]) {
|
|
||||||
return true;
|
|
||||||
} else if (state.group.isWaiting) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function fetchGroups(shortName) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
if (shouldFetchGroups(getState(), shortName)) {
|
|
||||||
dispatch(beginFetchGroup());
|
|
||||||
return axios
|
|
||||||
.get(process.env.REACT_APP_BACKEND_SERVER + "/" + shortName + "/groups")
|
|
||||||
.then(response => {
|
|
||||||
if (true) { //response.data.success) {
|
|
||||||
const data = { shortName: shortName, groups: response.data };
|
|
||||||
dispatch(fetchGroupSuccess(data));
|
|
||||||
} else {
|
|
||||||
dispatch(fetchGroupError());
|
|
||||||
let registerMessage = response.data.message;
|
|
||||||
return registerMessage;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(response => {
|
|
||||||
if (response instanceof Error) {
|
|
||||||
// Something happened in setting up the request that triggered an Error
|
|
||||||
console.log("Error", response.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export const FETCH_GROUP = "FETCH_GROUP"
|
|
||||||
export const FETCH_SUCCESS_GROUP = "FETCH_SUCCESS_GROUP"
|
|
||||||
export const FETCH_ERROR_GROUP = "FETCH_ERROR_GROUP"
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import {
|
|
||||||
FETCH_GROUP,
|
|
||||||
FETCH_SUCCESS_GROUP,
|
|
||||||
FETCH_ERROR_GROUP
|
|
||||||
} from "./group-constants";
|
|
||||||
|
|
||||||
|
|
||||||
const group = (
|
|
||||||
state = {
|
|
||||||
orderChange: false,
|
|
||||||
isWaiting: false,
|
|
||||||
items: {}},
|
|
||||||
action
|
|
||||||
) => {
|
|
||||||
switch (action.type) {
|
|
||||||
|
|
||||||
|
|
||||||
case FETCH_GROUP:
|
|
||||||
return Object.assign({}, state, { isWaiting: true});
|
|
||||||
|
|
||||||
|
|
||||||
case FETCH_SUCCESS_GROUP:
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
isWaiting: false,
|
|
||||||
items: {
|
|
||||||
...state.items,
|
|
||||||
[action.data.shortName]: action.data.groups
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
case FETCH_ERROR_GROUP:
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
isWaiting: false
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default group;
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { Component, useState, useEffect, useRef } from "react";
|
import React, { Component, useState, useEffect, useRef } from "react";
|
||||||
import { Link } from 'react-router-dom'
|
import { Link, useNavigate } from 'react-router-dom'
|
||||||
import SystemCard from "../System/SystemCard";
|
import SystemCard from "../System/SystemCard";
|
||||||
import "./Main.css";
|
import "./Main.css";
|
||||||
import { createMedia } from "@artsy/fresnel";
|
import { createMedia } from "@artsy/fresnel";
|
||||||
@@ -214,6 +214,7 @@ const Main = (props) => {
|
|||||||
const [visible, setVisible] = useState(true);
|
const [visible, setVisible] = useState(true);
|
||||||
const [duration, setDuration] = useState(500);
|
const [duration, setDuration] = useState(500);
|
||||||
const [currentSystem, setCurrentSystem] = useState(0);
|
const [currentSystem, setCurrentSystem] = useState(0);
|
||||||
|
const navigate = useNavigate();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const {data:systems, isSuccess} = useGetSystemsQuery(); //= selectAllSystems();
|
const {data:systems, isSuccess} = useGetSystemsQuery(); //= selectAllSystems();
|
||||||
|
|
||||||
@@ -276,13 +277,13 @@ const Main = (props) => {
|
|||||||
<Grid.Column style={{ paddingBottom: '4em', paddingTop: '2em', maxWidth: 450 }}>
|
<Grid.Column style={{ paddingBottom: '4em', paddingTop: '2em', maxWidth: 450 }}>
|
||||||
{ system && (<Transition visible={visible} animation='pulse' duration={500}>
|
{ system && (<Transition visible={visible} animation='pulse' duration={500}>
|
||||||
|
|
||||||
<SystemCard keepShort={true} system={system} key={system.shortName} onClick={(e) => props.changeUrl("/system/" + system.shortName)}/>
|
<SystemCard keepShort={true} system={system} key={system.shortName} onClick={(e) => navigate("/system/" + system.shortName)}/>
|
||||||
|
|
||||||
</Transition>)}
|
</Transition>)}
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
<Grid.Column style={{ paddingBottom: '0em', paddingTop: '6em', maxWidth: 450 }}>
|
<Grid.Column style={{ paddingBottom: '0em', paddingTop: '6em', maxWidth: 450 }}>
|
||||||
<Link to="/systems">
|
<Link to="/systems">
|
||||||
<Button primary size='huge' id="listen" animated>
|
<Button primary size='huge' id="listen" animated onClick={(e) => navigate("/system/" + system.shortName)}>
|
||||||
<Button.Content visible><Icon name='headphones' />
|
<Button.Content visible><Icon name='headphones' />
|
||||||
<Icon name='right arrow' /></Button.Content>
|
<Icon name='right arrow' /></Button.Content>
|
||||||
<Button.Content hidden>Listen</Button.Content>
|
<Button.Content hidden>Listen</Button.Content>
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import { connect } from "react-redux"
|
|
||||||
import * as systemActions from "./system-actions"
|
|
||||||
import ListSystems from "./ListSystems"
|
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
|
||||||
return {
|
|
||||||
system: state.system
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default connect(
|
|
||||||
mapStateToProps,
|
|
||||||
systemActions
|
|
||||||
)(ListSystems)
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
import axios from "axios";
|
|
||||||
//import { browserHistory } from "react-router"
|
|
||||||
import * as types from "./system-constants";
|
|
||||||
import { push } from 'connected-react-router';
|
|
||||||
|
|
||||||
|
|
||||||
function beginFetchSystem() {
|
|
||||||
return { type: types.FETCH_SYSTEM };
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchSystemSuccess(data) {
|
|
||||||
return { type: types.FETCH_SUCCESS_SYSTEM,
|
|
||||||
data };
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchSystemError(data) {
|
|
||||||
return { type: types.FETCH_ERROR_SYSTEM,
|
|
||||||
data };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function changeUrl(url) {
|
|
||||||
return dispatch => {
|
|
||||||
dispatch(push(url));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Example of an Async Action Creator
|
|
||||||
// http://redux.js.org/docs/advanced/AsyncActions.html
|
|
||||||
|
|
||||||
function shouldFetchSystems(state, subreddit) {
|
|
||||||
if ((!state.system.items) || (state.system.items.length <1)) {
|
|
||||||
return true
|
|
||||||
} else if (state.system.isWaiting) {
|
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function fetchSystems() {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
if (shouldFetchSystems(getState())) {
|
|
||||||
dispatch(beginFetchSystem());
|
|
||||||
|
|
||||||
return axios
|
|
||||||
.get(process.env.REACT_APP_BACKEND_SERVER + "/systems")
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
dispatch(fetchSystemSuccess(response.data.systems));
|
|
||||||
} else {
|
|
||||||
dispatch(fetchSystemError());
|
|
||||||
let registerMessage = response.data.message;
|
|
||||||
return registerMessage;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(response => {
|
|
||||||
if (response instanceof Error) {
|
|
||||||
// Something happened in setting up the request that triggered an Error
|
|
||||||
console.log("Error", response.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export const FETCH_SYSTEM = "FETCH_SYSTEM"
|
|
||||||
export const FETCH_SUCCESS_SYSTEM = "FETCH_SUCCESS_SYSTEM"
|
|
||||||
export const FETCH_ERROR_SYSTEM = "FETCH_ERROR_SYSTEM"
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
import {
|
|
||||||
FETCH_SYSTEM,
|
|
||||||
FETCH_SUCCESS_SYSTEM,
|
|
||||||
FETCH_ERROR_SYSTEM
|
|
||||||
} from "./system-constants";
|
|
||||||
|
|
||||||
|
|
||||||
const system = (
|
|
||||||
state = {
|
|
||||||
isWaiting: false,
|
|
||||||
items: []},
|
|
||||||
action
|
|
||||||
) => {
|
|
||||||
switch (action.type) {
|
|
||||||
|
|
||||||
case FETCH_SYSTEM:
|
|
||||||
|
|
||||||
return Object.assign({}, state, { isWaiting: true});
|
|
||||||
|
|
||||||
|
|
||||||
case FETCH_SUCCESS_SYSTEM:
|
|
||||||
const activeSystems = action.data.filter(system =>{
|
|
||||||
if (system.active) {return true}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
isWaiting: false,
|
|
||||||
items: activeSystems
|
|
||||||
});
|
|
||||||
|
|
||||||
case FETCH_ERROR_SYSTEM:
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
isWaiting: false
|
|
||||||
});
|
|
||||||
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default system;
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
import React, { Component } from "react";
|
|
||||||
import ReactDOM from "react-dom";
|
|
||||||
import { Link } from 'react-router-dom'
|
|
||||||
import {
|
|
||||||
Container,
|
|
||||||
Header,
|
|
||||||
Form,
|
|
||||||
Grid,
|
|
||||||
Segment,
|
|
||||||
Input,
|
|
||||||
Button,
|
|
||||||
Message,
|
|
||||||
Icon,
|
|
||||||
Table
|
|
||||||
} from "semantic-ui-react";
|
|
||||||
|
|
||||||
// ----------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------
|
|
||||||
class ListTalkgroups extends Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//https://stackoverflow.com/questions/36559661/how-can-i-dispatch-from-child-components-in-react-redux
|
|
||||||
//https://stackoverflow.com/questions/42597602/react-onclick-pass-event-with-parameter
|
|
||||||
render() {
|
|
||||||
const talkgroups = this.props.talkgroups;
|
|
||||||
if (talkgroups) {
|
|
||||||
return (
|
|
||||||
|
|
||||||
<Table celled>
|
|
||||||
<Table.Header>
|
|
||||||
<Table.Row>
|
|
||||||
<Table.HeaderCell>Mode</Table.HeaderCell>
|
|
||||||
<Table.HeaderCell>Number</Table.HeaderCell>
|
|
||||||
<Table.HeaderCell>Alpha</Table.HeaderCell>
|
|
||||||
<Table.HeaderCell>Description</Table.HeaderCell>
|
|
||||||
</Table.Row>
|
|
||||||
</Table.Header>
|
|
||||||
<Table.Body>
|
|
||||||
{talkgroups.map((talkgroup, i) => (
|
|
||||||
<Table.Row key={talkgroup.num + "-" + i}>
|
|
||||||
<Table.Cell>{talkgroup.mode}</Table.Cell>
|
|
||||||
<Table.Cell>{talkgroup.num}</Table.Cell>
|
|
||||||
<Table.Cell>{talkgroup.alpha}</Table.Cell>
|
|
||||||
<Table.Cell>{talkgroup.description}</Table.Cell>
|
|
||||||
</Table.Row>
|
|
||||||
))}
|
|
||||||
</Table.Body>
|
|
||||||
</Table>
|
|
||||||
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return (
|
|
||||||
<div/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ListTalkgroups;
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
import axios from 'axios';
|
|
||||||
//import { browserHistory } from "react-router"
|
|
||||||
import * as types from "./talkgroup-constants";
|
|
||||||
import { push } from 'connected-react-router';
|
|
||||||
|
|
||||||
// "Log In" action creators
|
|
||||||
function beginImportTalkgroup() {
|
|
||||||
return { type: types.IMPORT_TALKGROUP };
|
|
||||||
}
|
|
||||||
|
|
||||||
function importTalkgroupSuccess(data) {
|
|
||||||
return {
|
|
||||||
type: types.IMPORT_SUCCESS_TALKGROUP,
|
|
||||||
data
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function importTalkgroupError(data) {
|
|
||||||
return {
|
|
||||||
type: types.IMPORT_ERROR_TALKGROUP,
|
|
||||||
data
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function beginExportTalkgroup() {
|
|
||||||
return { type: types.EXPORT_TALKGROUP };
|
|
||||||
}
|
|
||||||
|
|
||||||
function exportTalkgroupSuccess() {
|
|
||||||
return { type: types.EXPORT_SUCCESS_TALKGROUP };
|
|
||||||
}
|
|
||||||
|
|
||||||
function exportTalkgroupError() {
|
|
||||||
return { type: types.EXPORT_ERROR_TALKGROUP };
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function beginFetchTalkgroup() {
|
|
||||||
return { type: types.FETCH_TALKGROUP };
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchTalkgroupSuccess(data) {
|
|
||||||
return { type: types.FETCH_SUCCESS_TALKGROUP,
|
|
||||||
data };
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchTalkgroupError(data) {
|
|
||||||
return { type: types.FETCH_ERROR_TALKGROUP,
|
|
||||||
data };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function changeUrl(url) {
|
|
||||||
return dispatch => {
|
|
||||||
dispatch(push(url));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/41878838/how-do-i-set-multipart-in-axios-with-react
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function shouldFetchTalkgroups(state, shortName) {
|
|
||||||
if (!state.talkgroup.items.hasOwnProperty(shortName)) {
|
|
||||||
return true
|
|
||||||
} else if (state.talkgroup.isWaiting) {
|
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function fetchTalkgroups(shortName) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
if (shouldFetchTalkgroups(getState(), shortName)) {
|
|
||||||
dispatch(beginFetchTalkgroup());
|
|
||||||
|
|
||||||
return axios
|
|
||||||
.get(process.env.REACT_APP_BACKEND_SERVER + "/" + shortName + "/talkgroups")
|
|
||||||
.then(response => {
|
|
||||||
if (response.data) {
|
|
||||||
var data = {shortName: shortName, talkgroups: response.data.talkgroups}
|
|
||||||
dispatch(fetchTalkgroupSuccess( data));
|
|
||||||
} else {
|
|
||||||
dispatch(fetchTalkgroupError());
|
|
||||||
let registerMessage = response.data.message;
|
|
||||||
return registerMessage;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(response => {
|
|
||||||
if (response instanceof Error) {
|
|
||||||
// Something happened in setting up the request that triggered an Error
|
|
||||||
console.log("Error", response.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
export const IMPORT_TALKGROUP = "IMPORT_TALKGROUP"
|
|
||||||
export const IMPORT_SUCCESS_TALKGROUP = "IMPORT_SUCCESS_TALKGROUP"
|
|
||||||
export const IMPORT_ERROR_TALKGROUP = "IMPORT_ERROR_TALKGROUP"
|
|
||||||
export const EXPORT_TALKGROUP = "EXPORT_TALKGROUP"
|
|
||||||
export const EXPORT_SUCCESS_TALKGROUP = "EXPORT_SUCCESS_TALKGROUP"
|
|
||||||
export const EXPORT_ERROR_TALKGROUP = "EXPORT_ERROR_TALKGROUP"
|
|
||||||
export const FETCH_TALKGROUP = "FETCH_TALKGROUP"
|
|
||||||
export const FETCH_SUCCESS_TALKGROUP = "FETCH_SUCCESS_TALKGROUP"
|
|
||||||
export const FETCH_ERROR_TALKGROUP = "FETCH_ERROR_TALKGROUP"
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
import {
|
|
||||||
IMPORT_TALKGROUP,
|
|
||||||
IMPORT_SUCCESS_TALKGROUP,
|
|
||||||
IMPORT_ERROR_TALKGROUP,
|
|
||||||
EXPORT_TALKGROUP,
|
|
||||||
EXPORT_SUCCESS_TALKGROUP,
|
|
||||||
EXPORT_ERROR_TALKGROUP,
|
|
||||||
FETCH_TALKGROUP,
|
|
||||||
FETCH_SUCCESS_TALKGROUP,
|
|
||||||
FETCH_ERROR_TALKGROUP
|
|
||||||
} from "./talkgroup-constants";
|
|
||||||
|
|
||||||
const talkgroup = (
|
|
||||||
state = {
|
|
||||||
isWaiting: false,
|
|
||||||
items: {}},
|
|
||||||
action
|
|
||||||
) => {
|
|
||||||
switch (action.type) {
|
|
||||||
|
|
||||||
case FETCH_TALKGROUP:
|
|
||||||
case IMPORT_TALKGROUP:
|
|
||||||
case EXPORT_TALKGROUP:
|
|
||||||
return Object.assign({}, state, { isWaiting: true});
|
|
||||||
|
|
||||||
case IMPORT_SUCCESS_TALKGROUP:
|
|
||||||
case FETCH_SUCCESS_TALKGROUP:
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
isWaiting: false,
|
|
||||||
items: {
|
|
||||||
...state.items,
|
|
||||||
[action.data.shortName]: action.data.talkgroups
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
case FETCH_ERROR_TALKGROUP:
|
|
||||||
case IMPORT_ERROR_TALKGROUP:
|
|
||||||
case EXPORT_ERROR_TALKGROUP:
|
|
||||||
case EXPORT_SUCCESS_TALKGROUP:
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
isWaiting: false
|
|
||||||
});
|
|
||||||
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default talkgroup;
|
|
||||||
@@ -6,7 +6,6 @@ import { applyMiddleware, compose, createStore } from 'redux'
|
|||||||
import { routerMiddleware } from 'connected-react-router'
|
import { routerMiddleware } from 'connected-react-router'
|
||||||
import createRootReducer from './reducers'
|
import createRootReducer from './reducers'
|
||||||
import { apiSlice } from '../features/api/apiSlice'
|
import { apiSlice } from '../features/api/apiSlice'
|
||||||
import {callPlayerSlice} from "../features/callPlayer/callPlayerSlice"
|
|
||||||
|
|
||||||
import thunk from 'redux-thunk';
|
import thunk from 'redux-thunk';
|
||||||
|
|
||||||
|
|||||||
@@ -2,22 +2,13 @@
|
|||||||
// from https://github.com/supasate/connected-react-router
|
// from https://github.com/supasate/connected-react-router
|
||||||
import { combineReducers } from 'redux'
|
import { combineReducers } from 'redux'
|
||||||
import { connectRouter } from 'connected-react-router'
|
import { connectRouter } from 'connected-react-router'
|
||||||
import systemReducer from "../System/system-reducer"
|
|
||||||
import talkgroupReducer from "../Talkgroups/talkgroup-reducer"
|
|
||||||
import groupReducer from "../Group/group-reducer"
|
|
||||||
import callReducer from "../Call/call-reducer"
|
|
||||||
import {apiSlice} from "../features/api/apiSlice"
|
import {apiSlice} from "../features/api/apiSlice"
|
||||||
import callPlayerSlice from "../features/callPlayer/callPlayerSlice"
|
import callPlayerSlice from "../features/callPlayer/callPlayerSlice"
|
||||||
import callsSlice, { callsReducer } from "../features/calls/callsSlice"
|
import { callsReducer } from "../features/calls/callsSlice"
|
||||||
|
|
||||||
export default (history) => combineReducers({
|
export default (history) => combineReducers({
|
||||||
router: connectRouter(history),
|
router: connectRouter(history),
|
||||||
system: systemReducer,
|
|
||||||
talkgroup: talkgroupReducer,
|
|
||||||
group: groupReducer,
|
|
||||||
callPlayer: callPlayerSlice,
|
callPlayer: callPlayerSlice,
|
||||||
call: callReducer,
|
|
||||||
calls: callsReducer,
|
calls: callsReducer,
|
||||||
[apiSlice.reducerPath]: apiSlice.reducer,
|
[apiSlice.reducerPath]: apiSlice.reducer,
|
||||||
|
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user