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 { AcUnitTwoTone, AddCircleTwoTone, CloudUploadTwoTone, DeleteOutlineTwoTone, LabelTwoTone, PersonOutlineTwoTone, PublicTwoTone, ShareTwoTone, StarTwoTone } from '@material-ui/icons'; import { Button, Link, ListItemSecondaryAction, ListItemText, Tooltip } from '@material-ui/core'; import { MapsList } from './maps-list'; import { FormattedMessage, IntlProvider, useIntl } from 'react-intl'; import { useQuery, useMutation, useQueryClient } from 'react-query'; import { activeInstance } from '../../redux/clientSlice'; import { useSelector } from 'react-redux'; import Client, { Label } from '../../classes/client'; import ActionDispatcher from './action-dispatcher'; import { ActionType } from './action-chooser'; import AccountMenu from './account-menu'; import ClientHealthSentinel from '../../classes/client/client-health-sentinel'; import HelpMenu from './help-menu'; import LanguageMenu from './language-menu'; import AppI18n, { Locales } from '../../classes/app-i18n'; const logoIcon = require('../../images/logo-small.svg'); const poweredByIcon = require('../../images/pwrdby-white.svg'); export type Filter = GenericFilter | LabelFilter; export interface GenericFilter { type: 'public' | 'all' | 'starred' | 'shared' | 'label' | 'owned'; } export interface LabelFilter { type: 'label', label: Label } interface ToolbarButtonInfo { filter: GenericFilter | LabelFilter, label: string icon: any; } const MapsPage = () => { const classes = useStyles(); const [filter, setFilter] = React.useState({ type: 'all' }); const client: Client = useSelector(activeInstance); const queryClient = useQueryClient(); const [activeDialog, setActiveDialog] = React.useState(undefined); const intl = useIntl(); useEffect(() => { document.title = 'Maps | WiseMapping'; }, []); const mutation = useMutation( (id: number) => client.deleteLabel(id), { onSuccess: () => queryClient.invalidateQueries('labels') } ); const handleMenuClick = (filter: Filter) => { queryClient.invalidateQueries('maps'); setFilter(filter); }; const handleLabelDelete = (id: number) => { mutation.mutate(id); }; const { data } = useQuery('labels', async () => { return await client.fetchLabels(); }); const labels: Label[] = data ? data : []; const filterButtons: ToolbarButtonInfo[] = [{ filter: { type: 'all' }, label: 'All', icon: }, { filter: { type: 'owned' }, label: 'Owned', icon: }, { filter: { type: 'starred' }, label: 'Starred', icon: }, { filter: { type: 'shared' }, label: 'Shared with me', icon: }, { filter: { type: 'public' }, label: 'Public', icon: }]; labels.forEach(l => filterButtons.push({ filter: { type: 'label', label: l }, label: l.title, icon: })) // Configure using user settings ... const appi18n = new AppI18n(); const userLocale = appi18n.getUserLocale(); return (
setActiveDialog(undefined)} mapsId={[]} />
logo
{filterButtons.map(buttonInfo => { return () } )}
Powered By WiseMapping
); } interface ListItemProps { icon: any, label: string, filter: Filter, active?: Filter onClick: (filter: Filter) => void; onDelete?: (id: number) => void; } const StyleListItem = (props: ListItemProps) => { const icon = props.icon; const label = props.label; const filter = props.filter; const activeFilter = props.active; const onClick = props.onClick; const onDeleteLabel = props.onDelete; const isSelected = activeFilter && (activeFilter.type == filter.type) && (activeFilter.type != 'label' || ((activeFilter as LabelFilter).label == (filter as LabelFilter).label)); 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.id); } return ( handleOnClick(e, filter)}> {icon} {filter.type == 'label' && handleOnDelete(e, filter)}> } ); } export default MapsPage;