import React from "react"; import { useDispatch, useSelector } from "react-redux"; import { useTheme } from "@mui/material/styles"; import { useTranslation } from "react-i18next"; import Tab from "@mui/material/Tab"; import Tabs from "@mui/material/Tabs"; import Box from "@mui/material/Box"; import Button from "@mui/material/Button"; import { createCombinationsText, createGlyphsText, getGlyphCollection, getGlyphCollections, } from "./glyphsLib"; import { setText, setContentEditable, setSelectedCollection } from "./labSlice"; import { RootState } from "./reducers"; import { LabState } from "./labSlice"; export function GlyphPanel() { const theme = useTheme(); const { t } = useTranslation(undefined, {keyPrefix: 'lab'}); const dispatch = useDispatch(); const labState: LabState = useSelector( (state: RootState) => state.labReducer, (prev, next) => prev.selectedCollection === next.selectedCollection, ); const { selectedCollection } = labState; const handleGlyphClick = (g: string) => { dispatch( setText( createCombinationsText(getGlyphCollection(selectedCollection), g), ), ); dispatch(setContentEditable(true)); }; const handleAllCombinationsClick = () => { let text = ""; const gc = getGlyphCollection(selectedCollection); gc.letters.concat(gc.numbers.concat(gc.signs)).map((g: string) => { text += createCombinationsText(gc, g, true); }); dispatch(setText(text)); dispatch(setContentEditable(false)); }; const handleAllGlyphsClick = () => { let text = createGlyphsText(getGlyphCollection(selectedCollection)); dispatch(setText(text)); dispatch(setContentEditable(true)); }; return ( dispatch(setSelectedCollection(newValue)) } variant="scrollable" textColor="inherit" indicatorColor="primary" scrollButtons="auto" sx={{ minHeight: "unset" }} > {Object.keys(getGlyphCollections()).map((collectionName: string) => ( ))} {getGlyphCollection(selectedCollection) .letters.concat( getGlyphCollection(selectedCollection).numbers.concat( getGlyphCollection(selectedCollection).signs, ), ) .map((g: string) => ( handleGlyphClick(g)} sx={{ width: "40px", backgroundColor: "transparent", border: "none", fontSize: "16px", color: theme.palette.text.primary, cursor: "pointer", "&:hover": { backgroundColor: theme.palette.action.selected, }, }} > {g} ))} ); }