diff --git a/src/components/admin/order/OrderView.tsx b/src/components/admin/order/OrderView.tsx index c915775c41e7f2ac234748f6f87a081102a198ee..0db93f3d9819ee89518f2ba89a8369436b61e7a1 100644 --- a/src/components/admin/order/OrderView.tsx +++ b/src/components/admin/order/OrderView.tsx @@ -19,12 +19,6 @@ const useStyles = makeStyles((theme) => ({ } })) -/** - * Drag & Drop list entry - * mostly copied from example https://react-dnd.github.io/react-dnd/examples/sortable/simple - * (https://codesandbox.io/s/github/react-dnd/react-dnd/tree/gh-pages/examples_hooks_ts/04-sortable/simple?from-embed=&file=/src/Card.tsx:403-440) - */ - export const OrderView: React.FC = () => { const dispatch = useAppDispatch() const classes = useStyles() diff --git a/src/components/admin/questions/Question.tsx b/src/components/admin/questions/Question.tsx index 2e352ff252bfc0b725c72f6e10c2756b6c70005c..2e0f6629d70c47d99f03367ce802969f9aa9d0f7 100644 --- a/src/components/admin/questions/Question.tsx +++ b/src/components/admin/questions/Question.tsx @@ -16,7 +16,7 @@ import ArrowDownwardIcon from '@material-ui/icons/ArrowDownward' import ClearIcon from '@material-ui/icons/Clear' import ArrowUpwardIcon from '@material-ui/icons/ArrowUpward' import { IQuestion, Language } from '../../../types/ApiTypes' -import { ICategorie } from '../shared/sharedMockData' +import { ICategorie } from '../shared/ICategorie' const useStyles = makeStyles((theme: Theme) => createStyles({ diff --git a/src/components/admin/questions/QuestionView.tsx b/src/components/admin/questions/QuestionView.tsx index c1cbf782a84c3d730c80ad929e82d26457f138f7..efe1d4f0084b90c3c57d93b6bec3f65458671c80 100644 --- a/src/components/admin/questions/QuestionView.tsx +++ b/src/components/admin/questions/QuestionView.tsx @@ -6,7 +6,7 @@ import Divider from '@material-ui/core/Divider' import { IQuestion } from '../../../types/ApiTypes' import { action, CustomSpeedDial } from '../shared/CustomSpeedDial' import SaveIcon from '@material-ui/icons/Save' -import { ICategorie } from '../shared/sharedMockData' +import { ICategorie } from '../shared/ICategorie' import ObjectID from 'bson-objectid' import { useAppDispatch, useAppSelector } from '../../../hooks' import { ConfirmDialog } from '../shared/Dialogs/ConfirmDialog' @@ -21,6 +21,7 @@ export const QuestionView: React.FC = () => { const isLoading = questions === [] const questionsRef: React.MutableRefObject<IQuestion[]> = useRef([]) const dispatch = useAppDispatch() + useEffect(() => { const copy = JSON.parse(JSON.stringify(questionsData)) setQuestions(copy) diff --git a/src/components/admin/shared/sharedMockData.ts b/src/components/admin/shared/ICategorie.ts similarity index 100% rename from src/components/admin/shared/sharedMockData.ts rename to src/components/admin/shared/ICategorie.ts diff --git a/src/components/admin/snacks & co/AddDialog.tsx b/src/components/admin/snacks & co/Dialogs/AddDialog.tsx similarity index 100% rename from src/components/admin/snacks & co/AddDialog.tsx rename to src/components/admin/snacks & co/Dialogs/AddDialog.tsx diff --git a/src/components/admin/snacks & co/ChangeDialog.tsx b/src/components/admin/snacks & co/Dialogs/ChangeDialog.tsx similarity index 98% rename from src/components/admin/snacks & co/ChangeDialog.tsx rename to src/components/admin/snacks & co/Dialogs/ChangeDialog.tsx index 8aed06cd082cbf6cba8939bb2ce60577027ae4fe..8847e651a52bacbf740f0347d7d915ff9357af98 100644 --- a/src/components/admin/snacks & co/ChangeDialog.tsx +++ b/src/components/admin/snacks & co/Dialogs/ChangeDialog.tsx @@ -14,7 +14,7 @@ import { TableCell, TableRow } from '@material-ui/core' -import { Language, TranslatedString } from '../../../types/ApiTypes' +import { Language, TranslatedString } from '../../../../types/ApiTypes' import Collapse from '@material-ui/core/Collapse' interface FormDialogProps { diff --git a/src/components/admin/snacks & co/SnackTable.tsx b/src/components/admin/snacks & co/SnackTable.tsx index a199715252bafe6a113d091dc4dd3bcdbb328936..621a51ea22c109ed277faab2e68df96d68ce7e76 100644 --- a/src/components/admin/snacks & co/SnackTable.tsx +++ b/src/components/admin/snacks & co/SnackTable.tsx @@ -18,7 +18,7 @@ import ClearIcon from '@material-ui/icons/Clear' import ArrowUpwardIcon from '@material-ui/icons/ArrowUpward' import ArrowDownwardIcon from '@material-ui/icons/ArrowDownward' import { ImageManagerPopup } from './ImageManager' -import { ChangeDialog } from './ChangeDialog' +import { ChangeDialog } from './Dialogs/ChangeDialog' import { TranslatedString } from '../../../types/ApiTypes' import PhotoCameraIcon from '@material-ui/icons/PhotoCamera' diff --git a/src/components/admin/snacks & co/SnacksView.tsx b/src/components/admin/snacks & co/SnacksView.tsx index 44f3a21bd284d40404f3e2819e1acaed7199831d..d80add8892326ef24aedb28e641b0ebc3aa374aa 100644 --- a/src/components/admin/snacks & co/SnacksView.tsx +++ b/src/components/admin/snacks & co/SnacksView.tsx @@ -1,31 +1,18 @@ import React, { useState } from 'react' -import { Fab, makeStyles } from '@material-ui/core' import AddIcon from '@material-ui/icons/Add' import { SnackTable } from './SnackTable' import { useFetchSnacksAndActivities } from './useFetchSnacksAndActivities' import { ConfirmDialog } from '../shared/Dialogs/ConfirmDialog' import { action, CustomSpeedDial } from '../shared/CustomSpeedDial' import SaveIcon from '@material-ui/icons/Save' -import { AddDialog } from './AddDialog' +import { AddDialog } from './Dialogs/AddDialog' import ObjectID from 'bson-objectid' -import { ChangeDialog } from './ChangeDialog' import { IActivity, ISnack } from '../../../types/ApiTypes' -import { updateSports } from '../../../redux/Slices/sportsSlice' -import { updateCategoriesFromSport } from '../../../redux/Slices/categoriesSlice' import { updateSnacks } from '../../../redux/Slices/snacksSlice' import { useAppDispatch } from '../../../hooks' import { updateActivities } from '../../../redux/Slices/activitiesSlice' -const useStyles = makeStyles((theme) => ({ - fab: { - position: 'fixed', - bottom: theme.spacing(2), - right: theme.spacing(2) - } -})) - export const SnacksView: React.FC = () => { - const classes = useStyles() const [pages, setPages] = useFetchSnacksAndActivities() const dialogConfirmState = useState(false) const dialogAddState = useState(false) @@ -94,7 +81,6 @@ export const SnacksView: React.FC = () => { totalViews: 0 }) setPages(copy) - console.log(pages) } return ( diff --git a/src/components/admin/sports/Dialogs/DeleteDialog.tsx b/src/components/admin/sports/Dialogs/DeleteDialog.tsx index f865e7502d88e756c83709947817ee503924c8f8..088fddb2fa2e62258b159f25941be689afaae7e8 100644 --- a/src/components/admin/sports/Dialogs/DeleteDialog.tsx +++ b/src/components/admin/sports/Dialogs/DeleteDialog.tsx @@ -6,7 +6,7 @@ import DialogContent from '@material-ui/core/DialogContent' import DialogContentText from '@material-ui/core/DialogContentText' import DialogTitle from '@material-ui/core/DialogTitle' import { MenuItem, Select } from '@material-ui/core' -import { ICategorie } from '../../shared/sharedMockData' +import { ICategorie } from '../../shared/ICategorie' interface FormDialogProps { categories: string[] diff --git a/src/components/admin/sports/SportartenCustomCell.tsx b/src/components/admin/sports/SportartenCustomCell.tsx index 624a0a8864cd4c954d6e389d569db8f7206309a3..46c33eea6a377746aa75b63e10c5f7d859e586b5 100644 --- a/src/components/admin/sports/SportartenCustomCell.tsx +++ b/src/components/admin/sports/SportartenCustomCell.tsx @@ -25,8 +25,7 @@ export const CustomCell: React.FC<{ setValue(parseInt(e.target.value, 10)) if (e.target.value === '') { valueRef.current[index].categoryWeights[categorieId] = null - } - else { + } else { valueRef.current[index].categoryWeights[ categorieId ] = parseInt(e.target.value, 10) diff --git a/src/components/admin/sports/SportartenRow.tsx b/src/components/admin/sports/SportartenRow.tsx new file mode 100644 index 0000000000000000000000000000000000000000..449f5e33e133c9bb2fafb52b50a63ccedc2272d3 --- /dev/null +++ b/src/components/admin/sports/SportartenRow.tsx @@ -0,0 +1,72 @@ +import React from 'react' +import { IconButton, TableCell, TableRow } from '@material-ui/core' +import { CustomCell } from './SportartenCustomCell' +import { ArrowDownward, ArrowUpward } from '@material-ui/icons' +import ClearIcon from '@material-ui/icons/Clear' +import { ISports } from '../../../types/ApiTypes' + +interface CustomTableRowProps { + index: number + valueRef: React.MutableRefObject<ISports[]> + updateRef: any + sportarten: ISports[] + sportId: string +} + +export const CustomTableRow: React.FC<CustomTableRowProps> = ({ + index, + valueRef, + updateRef, + sportarten, + sportId +}) => { + const sport = valueRef.current[index] + return ( + <TableRow> + <TableCell> {sport.name}</TableCell> + {Object.keys(sport.categoryWeights).map(function (key) { + return ( + <TableCell key={sport.name + '_' + key}> + <CustomCell + index={index} + categorieId={key} + valueRef={valueRef} + data={sport.categoryWeights[key]} + sportarten={sportarten} + /> + </TableCell> + ) + })} + <TableCell /> + <TableCell> + <a + href={'https://' + sport.url} + target="_blank" + rel="noreferrer" + > + {sport.url} + </a> + </TableCell> + <TableCell> + <IconButton + onClick={() => { + sport.active = !sport.active + updateRef() + }} + > + {sport.active ? <ArrowDownward /> : <ArrowUpward />} + </IconButton> + </TableCell> + <TableCell> + <IconButton + onClick={() => { + valueRef.current.splice(index, 1) + updateRef() + }} + > + <ClearIcon /> + </IconButton> + </TableCell> + </TableRow> + ) +} diff --git a/src/components/admin/sports/SportartenTable.tsx b/src/components/admin/sports/SportartenTable.tsx index ea278fe8f5bdf3a2791b021755f2aa57b7c3240c..1d8e8e8e281e8e32a9b7bcf32e4f52bbd7ae5887 100644 --- a/src/components/admin/sports/SportartenTable.tsx +++ b/src/components/admin/sports/SportartenTable.tsx @@ -9,11 +9,12 @@ import { } from '@material-ui/core' import { ArrowDownward, ArrowUpward } from '@material-ui/icons' import ClearIcon from '@material-ui/icons/Clear' -import { ICategorie } from '../shared/sharedMockData' +import { ICategorie } from '../shared/ICategorie' import { CustomCell } from './SportartenCustomCell' import { ISports } from '../../../types/ApiTypes' import { useState } from 'react' import { useEffect } from 'react' +import { CustomTableRow } from './SportartenRow' interface SportartenTableProps { categories: string[] diff --git a/src/components/admin/sports/SportartenView.tsx b/src/components/admin/sports/SportartenView.tsx index 09632f2406f868de07f4a924aca35310930d0b73..c2a49957cd79d72ce1296a4ac19d833ec7cc2019 100644 --- a/src/components/admin/sports/SportartenView.tsx +++ b/src/components/admin/sports/SportartenView.tsx @@ -10,7 +10,7 @@ import { AddDialog } from '../shared/Dialogs/AddDialog' import { CopyDialog } from './Dialogs/CopyDialog' import { ISports } from '../../../types/ApiTypes' import SortIcon from '@material-ui/icons/Sort' -import { compareSportWeights } from './sportsMockData' +import { compareSportWeights } from './compareSportsWeights' import ObjectID from 'bson-objectid' import { useAppDispatch, useAppSelector } from '../../../hooks' import { ConfirmDialog } from '../shared/Dialogs/ConfirmDialog' diff --git a/src/components/admin/sports/compareSportsWeights.ts b/src/components/admin/sports/compareSportsWeights.ts new file mode 100644 index 0000000000000000000000000000000000000000..74d5132ca98fe0f0e253d8f5ef0c56d71e3d6f9d --- /dev/null +++ b/src/components/admin/sports/compareSportsWeights.ts @@ -0,0 +1,21 @@ +import { ISports } from '../../../types/ApiTypes' + +export function compareSportWeights(a: ISports, b: ISports) { + let c1 = 0 + let c2 = 0 + Object.keys(a.categoryWeights).forEach((key) => { + if (a.active) c1 += 100 + if (a.categoryWeights[key] === null) { + c1 += 1 + } + }) + Object.keys(b.categoryWeights).forEach((key) => { + if (b.active) c2 += 100 + if (b.categoryWeights[key] === null) { + c2 += 1 + } + }) + if (c1 > c2) return -1 + else if (c1 < c2) return 1 + return 0 +} diff --git a/src/components/admin/sports/sportsMockData.ts b/src/components/admin/sports/sportsMockData.ts deleted file mode 100644 index 394049362696d5821b6eca6bc9880c4234612c15..0000000000000000000000000000000000000000 --- a/src/components/admin/sports/sportsMockData.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { ISports } from '../../../types/ApiTypes' - -export const mockSportsData: ISports[] = [ - { - _id: '', - name: 'Kunfgu', - url: 'https://http.cat/', - active: true, - categoryWeights: { '0': 1, '1': 4, '2': 1, '3': 4, '4': 5, '5': 1 } - }, - { - _id: '', - name: 'Volleyball', - url: 'https://http.cat/', - active: true, - categoryWeights: { '0': 1, '1': 4, '2': 1, '3': 4, '4': 5, '5': 1 } - }, - { - _id: '', - name: 'Tischtennis', - url: 'https://http.cat/', - active: true, - categoryWeights: { '0': 1, '1': 4, '2': 5, '3': 4, '4': 5, '5': 1 } - }, - { - _id: '', - name: 'Hot Yoga', - url: 'https://http.cat/', - active: true, - categoryWeights: { '0': 3, '1': 0, '2': 5, '3': 4, '4': 5, '5': 1 } - }, - { - _id: '', - name: 'Basketball', - url: 'https://http.cat/', - active: true, - categoryWeights: { '0': 1, '1': 4, '2': 1, '3': 7, '4': 5, '5': 0 } - }, - { - _id: '', - name: 'Kunfgu2', - url: 'https://http.cat/', - active: false, - categoryWeights: { '0': 1, '1': 0, '2': 1, '3': 4, '4': 5, '5': 0 } - }, - { - _id: '', - name: 'Volleyball2', - url: 'https://http.cat/', - active: false, - categoryWeights: { '0': 5, '1': 4, '2': 1, '3': 9, '4': 5, '5': 3 } - }, - { - _id: '', - name: 'Tischtennis2', - url: 'https://http.cat/', - active: false, - categoryWeights: { '0': 1, '1': 4, '2': 1, '3': 4, '4': 5, '5': 5 } - }, - { - _id: '', - name: 'Hot Yoga2', - url: 'https://http.cat/', - active: false, - categoryWeights: { '0': 1, '1': 5, '2': 1, '3': 4, '4': 5, '5': 2 } - }, - { - _id: '', - name: 'Basketball2', - url: 'https://http.cat/', - active: false, - categoryWeights: { '0': 5, '1': 4, '2': 1, '3': 4, '4': 5, '5': 0 } - } -] - -export function compareSportWeights(a: ISports, b: ISports) { - let c1 = 0 - let c2 = 0 - Object.keys(a.categoryWeights).forEach((key) => { - if (a.active) c1 += 100 - if (a.categoryWeights[key] === null) { - c1 += 1 - } - }) - Object.keys(b.categoryWeights).forEach((key) => { - if (b.active) c2 += 100 - if (b.categoryWeights[key] === null) { - c2 += 1 - } - }) - if (c1 > c2) return -1 - else if (c1 < c2) return 1 - return 0 -} diff --git a/src/components/admin/sports/useFetchData.tsx b/src/components/admin/sports/useFetchData.tsx deleted file mode 100644 index 1c49d8234a95cb8afbc272f6a0c8475077db9d2d..0000000000000000000000000000000000000000 --- a/src/components/admin/sports/useFetchData.tsx +++ /dev/null @@ -1,159 +0,0 @@ -import { useState } from 'react' -import { ISports } from '../../../types/ApiTypes' - -export const useFetchData = (): [isLoading: boolean, content: ISports[]] => { - const [isLoading, setIsLoading] = useState(true) - const [content, setContent] = useState<ISports[]>([]) - const [isFirstFetch, setIsFirstFetch] = useState(true) - if (isFirstFetch) { - new Promise(() => - setTimeout(() => { - setContent([ - { - _id: '0', - name: 'Kunfgu', - url: 'https://http.cat/', - active: true, - categoryWeights: { - '0': 1, - '1': 4, - '2': 1, - '3': 4, - '4': 5, - '5': 1 - } - }, - { - _id: '1', - name: 'Volleyball', - url: 'https://http.cat/', - active: true, - categoryWeights: { - '0': 1, - '1': 4, - '2': 1, - '3': 4, - '4': 5, - '5': 1 - } - }, - { - _id: '2', - name: 'Tischtennis', - url: 'https://http.cat/', - active: true, - categoryWeights: { - '0': 1, - '1': 4, - '2': 5, - '3': 4, - '4': 5, - '5': 1 - } - }, - { - _id: '3', - name: 'Hot Yoga', - url: 'https://http.cat/', - active: true, - categoryWeights: { - '0': 3, - '1': 0, - '2': 5, - '3': 4, - '4': 5, - '5': 1 - } - }, - { - _id: '4', - name: 'Basketball', - url: 'https://http.cat/', - active: true, - categoryWeights: { - '0': 1, - '1': 4, - '2': 1, - '3': 7, - '4': 5, - '5': 0 - } - }, - { - _id: '5', - name: 'Kunfgu2', - url: 'https://http.cat/', - active: false, - categoryWeights: { - '0': 1, - '1': 0, - '2': 1, - '3': 4, - '4': 5, - '5': 0 - } - }, - { - _id: '6', - name: 'Volleyball2', - url: 'https://http.cat/', - active: false, - categoryWeights: { - '0': 5, - '1': 4, - '2': 1, - '3': 9, - '4': 5, - '5': 3 - } - }, - { - _id: '7', - name: 'Tischtennis2', - url: 'https://http.cat/', - active: false, - categoryWeights: { - '0': 1, - '1': 4, - '2': 1, - '3': 4, - '4': 5, - '5': 5 - } - }, - { - _id: '8', - name: 'Hot Yoga2', - url: 'https://http.cat/', - active: false, - categoryWeights: { - '0': 1, - '1': 5, - '2': 1, - '3': 4, - '4': 5, - '5': 2 - } - }, - { - _id: '9', - name: 'Basketball2', - url: 'https://http.cat/', - active: false, - categoryWeights: { - '0': 5, - '1': 4, - '2': 1, - '3': 4, - '4': 5, - '5': 0 - } - } - ]) - setIsLoading(false) - }, 900) - ) - setIsFirstFetch(false) - } - return [isLoading, content] -} diff --git a/src/components/admin/synchronise/SynchroniseTableView.tsx b/src/components/admin/synchronise/SynchroniseTableView.tsx index 045e7d807a34da7eed268963b47a9a096c2ba273..9f2a9ccf4ca34b591f768cb3d4f18b059307e3db 100644 --- a/src/components/admin/synchronise/SynchroniseTableView.tsx +++ b/src/components/admin/synchronise/SynchroniseTableView.tsx @@ -1,13 +1,11 @@ import React, { useState } from 'react' -import { useFetchData } from './useFetchData' import { Fab, makeStyles } from '@material-ui/core' import SaveIcon from '@material-ui/icons/Save' import { createStyles, Theme } from '@material-ui/core/styles' import { SynchroniseContainer } from './SynchroniseContainer' -import { SyncApiData, SyncListEntry } from './SynchroniseView' +import { SyncListEntry } from './SynchroniseView' import { useRef } from 'react' import { ConfirmDialog } from '../shared/Dialogs/ConfirmDialog' -import { ISports } from '../../../types/ApiTypes' const useStyles = makeStyles((theme: Theme) => createStyles({ @@ -78,16 +76,11 @@ export const SynchroniseTableView: React.FC<SynchroniseTableViewProps> = ({ toInactive.push(rest) } }) - console.log(toRemove) - console.log(toAdd) - console.log(toActive) - console.log(toInactive) } return ( <div style={{ minHeight: '100%', textAlign: 'center' }}> <div className={classes.div}> - {/*Should be display in the same row, but css is not my strength */} <SynchroniseContainer sports={newSports} text={['neue Sportarten', 'nicht übernehmen', 'übernehmen']} diff --git a/src/components/admin/synchronise/SynchroniseView.tsx b/src/components/admin/synchronise/SynchroniseView.tsx index a90b2f42d4d25316798391a9f1e2e95d37560bc8..fb87b5b80bdd4a6ebdf14b763c52cc22f9f127d6 100644 --- a/src/components/admin/synchronise/SynchroniseView.tsx +++ b/src/components/admin/synchronise/SynchroniseView.tsx @@ -1,7 +1,6 @@ import React, { useState } from 'react' import { Button } from '@material-ui/core' import { SynchroniseTableView } from './SynchroniseTableView' -import { useEffect } from 'react' export type SyncApiData = { newSports: { name: string; url: string }[] @@ -45,9 +44,9 @@ export const SynchroniseView: React.FC = () => { setMode('finished') } - function toSyncListEntry<T extends SyncApiData['newSports'][number]>( + const toSyncListEntry = <T extends SyncApiData['newSports'][number]>( e: T - ): T & SyncListEntry { + ): T & SyncListEntry => { const a = (e as unknown) as SyncListEntry a.selected = true return a as T & SyncListEntry diff --git a/src/components/admin/synchronise/useFetchData.tsx b/src/components/admin/synchronise/useFetchData.tsx deleted file mode 100644 index 9f609d9ab0c8447d72db2473f1ed624c60fb4c19..0000000000000000000000000000000000000000 --- a/src/components/admin/synchronise/useFetchData.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { useState, useEffect } from 'react' - -export const useFetchData = (): [isLoading: boolean, content: string[]] => { - const [isLoading, setIsLoading] = useState(true) - const [content, setContent] = useState<string[]>([]) - useEffect(() => { - setTimeout(() => { - setContent([ - 'Klettern', - 'Bogenschießen', - 'Volleyball', - 'Tischtennis', - 'Klettern', - 'Bogenschießen', - 'Volleyball', - 'Tischtennis', - 'Klettern', - 'Bogenschießen', - 'Volleyball', - 'Tischtennis' - ]) - setIsLoading(false) - }, 900) - }, []) - return [isLoading, content] -} diff --git a/src/redux/Slices/categoriesSlice.ts b/src/redux/Slices/categoriesSlice.ts index 24371a3a0656e587b79009f5dab03f57c5523edd..70d8e22ef0ea4258b83c5796b8fb7a715c3d287c 100644 --- a/src/redux/Slices/categoriesSlice.ts +++ b/src/redux/Slices/categoriesSlice.ts @@ -1,5 +1,5 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit' -import { ICategorie } from '../../components/admin/shared/sharedMockData' +import { ICategorie } from '../../components/admin/shared/ICategorie' import { ISports } from '../../types/ApiTypes' interface categoriesState {