import React, { ErrorInfo, useEffect } from 'react'; import clsx from 'clsx'; import Drawer from '@material-ui/core/Drawer'; import AppBar from '@material-ui/core/AppBar'; import Toolbar from '@material-ui/core/Toolbar'; import List from '@material-ui/core/List'; import IconButton from '@material-ui/core/IconButton'; import ListItem from '@material-ui/core/ListItem'; import ListItemIcon from '@material-ui/core/ListItemIcon'; import { useStyles } from './style'; import { AccountCircle, AddCircleTwoTone, BlurCircular, CloudUploadTwoTone, DeleteOutlineTwoTone, EmailOutlined, EmojiPeopleOutlined, ExitToAppOutlined, FeedbackOutlined, Help, PolicyOutlined, PublicTwoTone, SettingsApplicationsOutlined, ShareTwoTone, StarRateTwoTone, Translate, TranslateTwoTone } from '@material-ui/icons'; import InboxTwoToneIcon from '@material-ui/icons/InboxTwoTone'; import { Button, Link, ListItemSecondaryAction, ListItemText, Menu, MenuItem, Tooltip } from '@material-ui/core'; import { MapsList } from './maps-list'; import { FormattedMessage } from 'react-intl'; import { useQuery, useMutation, useQueryClient } from 'react-query'; import { activeInstance } from '../../reducers/serviceSlice'; import { useSelector } from 'react-redux'; import Client from '../../client'; const logoIcon = require('../../images/logo-small.svg'); const poweredByIcon = require('../../images/pwrdby-white.svg'); export type Filter = GenericFilter | LabelFilter; interface GenericFilter { type: 'public' | 'all' | 'starred' | 'shared' | 'label' | 'owned'; } interface LabelFilter { type: 'label', label: string } interface ToolbarButtonInfo { filter: GenericFilter | LabelFilter, label: string } const MapsPage = (props: any) => { const classes = useStyles(); const [filter, setFilter] = React.useState({ type: 'all' }); const client: Client = useSelector(activeInstance); const queryClient = useQueryClient(); useEffect(() => { document.title = 'Maps | WiseMapping'; }, []); const mutation = useMutation( (label: string) => client.deleteLabel(label), { onSuccess: () => queryClient.invalidateQueries('labels') } ); const handleMenuClick = (filter: Filter) => { setFilter(filter); }; const handleLabelDelete = (label: string) => { mutation.mutate(label); }; const { isLoading, error, data } = useQuery('labels', async () => { return await client.fetchLabels(); }); const labels: string[] = data ? data : []; const filterButtons: ToolbarButtonInfo[] = [{ filter: { type: 'all' }, label: 'All' }, { filter: { type: 'owned' }, label: 'Owned' }, { filter: { type: 'starred' }, label: 'Starred' }, { filter: { type: 'shared' }, label: 'Shared with me' }, { filter: { type: 'public' }, label: 'Public' }]; labels.forEach(l => filterButtons.push({ filter: { type: 'label', label: l }, label: l })) return (
logo
{filterButtons.map(buttonInfo => (} label={buttonInfo.label} filter={buttonInfo.filter} active={filter} onClick={handleMenuClick} onDelete={handleLabelDelete} key={`${buttonInfo.filter.type}:${(buttonInfo.filter as LabelFilter).label}`} />) )}
Powered By WiseMapping
); } interface ListItemProps { icon: any, label: string, filter: Filter, active?: Filter onClick: (filter: Filter) => void; onDelete?: (label: string) => void; } const StyleListItem = (props: ListItemProps) => { const icon = props.icon; const label = props.label; const filter = props.filter; const activeType = props.active?.type; const onClick = props.onClick; const onDeleteLabel = props.onDelete; const handleOnClick = (event: any, filter: Filter) => { event.stopPropagation(); onClick(filter); } const handleOnDelete = (event: any, filter: Filter) => { event.stopPropagation(); if (!onDeleteLabel) { throw "Illegal state exeption"; } onDeleteLabel((filter as LabelFilter).label); } return ( handleOnClick(e, filter)}> {icon} {filter.type == 'label' ? ( handleOnDelete(e, filter)}> ) : null} ); } const ProfileToobarButton = () => { const [anchorEl, setAnchorEl] = React.useState(null); const open = Boolean(anchorEl); const handleMenu = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; const handleClose = () => { setAnchorEl(null); }; return ( ); } const HelpToobarButton = () => { const [anchorEl, setAnchorEl] = React.useState(null); const open = Boolean(anchorEl); const handleMenu = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; const handleClose = () => { setAnchorEl(null); }; return ( ); } export default MapsPage;