/** * @author Tanya Vykliuk */ import React, { useState } from 'react'; import { connect } from 'react-redux'; import { bindActionCreators, Dispatch } from 'redux'; import { PAGE_LIMIT } from '../reducers/admin/reducers'; import { createStyles, makeStyles, Theme } from '@material-ui/core/styles'; import Table from "@material-ui/core/Table"; import TableBody from "@material-ui/core/TableBody"; import TableContainer from "@material-ui/core/TableContainer"; import TableRow from "@material-ui/core/TableRow"; import TableCell from "@material-ui/core/TableCell"; import Paper from "@material-ui/core/Paper"; import Button from "@material-ui/core/Button"; import CardMedia from "@material-ui/core/CardMedia"; import Typography from "@material-ui/core/Typography"; import Avatar from "@material-ui/core/Avatar"; // @ts-ignore import styles from './Admin.module.scss'; import Backdrop from '@material-ui/core/Backdrop'; import CircularProgress from '@material-ui/core/CircularProgress'; import VisibilityIcon from '@material-ui/icons/Visibility'; import WhatshotIcon from '@material-ui/icons/Whatshot'; import BookmarkIcon from '@material-ui/icons/Bookmark'; import StarIcon from '@material-ui/icons/Star'; import StarOutlineIcon from '@material-ui/icons/StarOutline'; import { Edit } from '@material-ui/icons'; import Slide from '@material-ui/core/Slide'; import { TransitionProps } from '@material-ui/core/transitions'; import SharedModal from './SharedModal'; import FeedForm from '../../socialmedia/components/FeedForm'; import { EnhancedTableHead } from './AdminHelpers'; import { updateFeedAsAdmin } from '../../socialmedia/reducers/feed/service'; if (!global.setImmediate) { global.setImmediate = setTimeout as any; } interface Props { adminState?: any; authState?: any; locationState?: any; fetchAdminLocations?: any; fetchAdminScenes?: any; fetchLocationTypes?: any; fetchUsersAsAdmin?: any; fetchAdminInstances?: any; removeUser?: any; list?:any; updateFeedAsAdmin?: typeof updateFeedAsAdmin; } const mapStateToProps = (state: any): any => { return { }; }; const mapDispatchToProps = (dispatch: Dispatch): any => ({ updateFeedAsAdmin: bindActionCreators(updateFeedAsAdmin, dispatch), }); const useStyles = makeStyles((theme: Theme) => createStyles({ formControl: { margin: theme.spacing(0), minWidth: 120, backgroundColor: "white" }, selectEmpty: { marginTop: theme.spacing(0), }, backdrop: { zIndex: theme.zIndex.drawer + 1, color: '#fff', } }), ); const Transition = React.forwardRef(( props: TransitionProps & { children?: React.ReactElement }, ref: React.Ref, ) => { return ; }); const FeedConsole = (props: Props) => { const classes = useStyles(); const { list, updateFeedAsAdmin } = props; const headCells = [ { id: 'featuredByAdmin', numeric: false, disablePadding: false, label: 'Featured by Admin' }, { id: 'preview', numeric: false, disablePadding: false, label: 'Preview' }, { id: 'video', numeric: false, disablePadding: false, label: 'Video' }, { id: 'details', numeric: false, disablePadding: false, label: 'Details' }, { id: 'creatorId', numeric: false, disablePadding: false, label: 'Creator' }, { id: 'createdAt', numeric: false, disablePadding: false, label: 'Created' }, { id: 'action', numeric: false, disablePadding: false, label: '' } ]; function descendingComparator(a: T, b: T, orderBy: keyof T) { if (b[orderBy] < a[orderBy]) { return -1; } if (b[orderBy] > a[orderBy]) { return 1; } return 0; } type Order = 'asc' | 'desc'; function getComparator( order: Order, orderBy: Key, ): (a: { [key in Key]: number | string }, b: { [key in Key]: number | string }) => number { return order === 'desc' ? (a, b) => descendingComparator(a, b, orderBy) : (a, b) => -descendingComparator(a, b, orderBy); } function stableSort(array: T[], comparator: (a: T, b: T) => number) { const stabilizedThis = array.map((el, index) => [el, index] as [T, number]); stabilizedThis.sort((a, b) => { const order = comparator(a[0], b[0]); if (order !== 0) return order; return a[1] - b[1]; }); return stabilizedThis.map((el) => { return el[0]; }); } const [modalOpen, setModalOpen] = useState(false); const [order, setOrder] = React.useState('asc'); const [orderBy, setOrderBy] = React.useState('name'); const [selected, setSelected] = React.useState([]); const [dense, setDense] = React.useState(false); const [page, setPage] = React.useState(0); const [rowsPerPage, setRowsPerPage] = React.useState(PAGE_LIMIT); const [loading, setLoading] = React.useState(false); const [view, setView] = React.useState(null); // const adminUsers = adminState.get('users').get('users'); const handleRequestSort = (event: React.MouseEvent, property) => { const isAsc = orderBy === property && order === 'asc'; setOrder(isAsc ? 'desc' : 'asc'); setOrderBy(property); }; const handleView = (id: string) => { setView(list.find(item => item.id === id)); setModalOpen(true); }; const handleClose = () => { setModalOpen(false); }; const handleUpdateFeed = (feed)=>{ updateFeedAsAdmin(feed.id, feed); }; return (
ARC Feeds List {stableSort(list, getComparator(order, orderBy)) .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) .map((row, index) => { return ( {row.featuredByAdmin ? : }
{row.featured ? : } {row.viewsCount} {row.fires} {row.bookmarks}

{row.title}
{row.description}
{row.creatorName+', '+row.creatorUserName} {row.createdAt} {row.featuredByAdmin === 1 ? : }
); })}
{view && }
); }; export default connect(mapStateToProps, mapDispatchToProps)(FeedConsole);