{"version":3,"file":"InfoBox.BoSMDIPt.js","sources":["../../src/components/icons/purposed/HelperIcon/components/InfoBox.jsx"],"sourcesContent":["import { Component, createRef } from \"react\";\r\nimport {\r\n Grid,\r\n IconButton,\r\n TextField,\r\n Tooltip,\r\n Typography,\r\n} from \"@mui/material\";\r\nimport PropTypes from \"prop-types\";\r\n\r\nimport ProgressCirc from \"src/components/layout/Progress/ProgressCirc\";\r\nimport StepButtons from \"src/components/buttons/StepButtons/StepButtons\";\r\nimport { EditIcon, SaveIcon } from \"src/components/icons/ActionIcons\";\r\nimport {\r\n cache_clear,\r\n cache_read,\r\n cache_write,\r\n helps_cacheName,\r\n} from \"src/components/js/CacheFunctions\";\r\n\r\nexport default class InfoBox extends Component {\r\n constructor(props) {\r\n super(props);\r\n this.otsikkoRef = createRef();\r\n this.htmlTextRef = createRef();\r\n this.state = {\r\n items: [],\r\n title: \"haetaan...\",\r\n text: \"\",\r\n rev: 0,\r\n isLoaded: false,\r\n };\r\n }\r\n componentDidMount() {\r\n try {\r\n this.getData();\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n }\r\n\r\n getData() {\r\n const url =\r\n import.meta.env.VITE_SERVER_URL + \"/api/helps/get/\" + this.props.helpId;\r\n try {\r\n const c = cache_read(helps_cacheName, url);\r\n if (c) {\r\n this.processJson(c);\r\n return;\r\n }\r\n\r\n fetch(url)\r\n .then((res) => res.json())\r\n .then((json) => {\r\n cache_write(helps_cacheName, url, json, 3600);\r\n this.processJson(json);\r\n })\r\n .catch((error) => {\r\n throw error;\r\n });\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n }\r\n\r\n processJson(json) {\r\n if (json.length > 0)\r\n this.setState({\r\n title: json[0].title,\r\n htmlText: json[0].htmltext,\r\n img: json[0].img,\r\n rev: json[0].rev,\r\n shortText: json[0].shorttext,\r\n });\r\n else\r\n this.setState({\r\n title: \"Syötä otsikko\",\r\n });\r\n\r\n this.setState({\r\n isLoaded: true,\r\n editOtsikko: false,\r\n editText: false,\r\n });\r\n this.props.onShowSuljeButtonChange(true);\r\n }\r\n\r\n render() {\r\n const allowEdit = this.props.allowEdit;\r\n const onEditTitleButtonClick = (value) => {\r\n this.setState({ editOtsikko: value });\r\n this.props.onShowSuljeButtonChange(false);\r\n };\r\n const onEditHtmlTextButtonClick = (value) => {\r\n this.setState({ editText: value });\r\n this.props.onShowSuljeButtonChange(false);\r\n };\r\n const onSaveTitleButtonClick = () => {\r\n cache_clear(helps_cacheName);\r\n const otsikko = this.otsikkoRef.current.value;\r\n this.setState({\r\n title: otsikko,\r\n editOtsikko: false,\r\n });\r\n this.props.onShowSuljeButtonChange(true);\r\n const requestOptions = {\r\n method: \"PUT\",\r\n headers: {\r\n \"Content-Type\": \"application/json\",\r\n },\r\n body: JSON.stringify({\r\n helpId: this.props.helpId,\r\n img: this.state.img,\r\n title: otsikko,\r\n shorttext: this.state.shortText,\r\n htmltext: this.state.htmlText,\r\n }),\r\n };\r\n fetch(\r\n import.meta.env.VITE_SERVER_URL + \"/api/helps/update\",\r\n requestOptions\r\n ).then((response) => response.json());\r\n };\r\n const onSaveHtmlTextButtonClick = () => {\r\n cache_clear(helps_cacheName);\r\n const htmlTeksti = this.htmlTextRef.current.value;\r\n this.setState({\r\n htmlText: htmlTeksti,\r\n editText: false,\r\n });\r\n this.props.onShowSuljeButtonChange(true);\r\n const requestOptions = {\r\n method: \"PUT\",\r\n headers: {\r\n \"Content-Type\": \"application/json\",\r\n },\r\n body: JSON.stringify({\r\n helpId: this.props.helpId,\r\n img: this.state.img,\r\n title: this.state.title,\r\n shorttext: this.state.shortText,\r\n htmltext: htmlTeksti,\r\n }),\r\n };\r\n fetch(\r\n import.meta.env.VITE_SERVER_URL + \"/api/helps/update\",\r\n requestOptions\r\n ).then((response) => response.json());\r\n };\r\n\r\n return (\r\n <>\r\n \r\n \r\n {!this.state.editOtsikko ? (\r\n <>\r\n {this.state.isLoaded ? (\r\n \r\n ) : (\r\n \r\n )}\r\n \r\n ) : (\r\n <>\r\n {\r\n if (e.key === \"Enter\") {\r\n onSaveTitleButtonClick();\r\n }\r\n if (e.key === \"Escape\") {\r\n this.getData();\r\n }\r\n }}\r\n />\r\n \r\n )}\r\n \r\n \r\n {allowEdit ? (\r\n
\r\n {!this.state.editOtsikko ? (\r\n \r\n onEditTitleButtonClick(!this.state.editOtsikko)\r\n }\r\n aria-label=\"Muokkaa\"\r\n >\r\n \r\n \r\n ) : (\r\n onSaveTitleButtonClick()}\r\n aria-label=\"Tallenna\"\r\n >\r\n \r\n \r\n )}\r\n
\r\n ) : (\r\n \"\"\r\n )}\r\n
\r\n
\r\n \r\n \r\n {!this.state.editText ? (\r\n <>\r\n \r\n \r\n \r\n \r\n ) : (\r\n \r\n )}\r\n \r\n \r\n {allowEdit ? (\r\n <>\r\n {!this.state.editText ? (\r\n \r\n \r\n onEditHtmlTextButtonClick(!this.state.editText)\r\n }\r\n aria-label=\"Muokkaa\"\r\n >\r\n \r\n \r\n \r\n ) : (\r\n onSaveHtmlTextButtonClick()}\r\n aria-label=\"Tallenna\"\r\n >\r\n \r\n \r\n )}\r\n \r\n ) : (\r\n \"\"\r\n )}\r\n \r\n \r\n {(this.state.editOtsikko || this.state.editText) && (\r\n <>\r\n this.getData()}\r\n onSaveKlik={() => {\r\n if (this.state.editText) onSaveHtmlTextButtonClick();\r\n if (this.state.editOtsikko) onSaveTitleButtonClick();\r\n }}\r\n />\r\n \r\n )}\r\n \r\n );\r\n }\r\n}\r\n\r\nInfoBox.propTypes = {\r\n allowEdit: PropTypes.bool,\r\n onShowSuljeButtonChange: PropTypes.func,\r\n helpId: PropTypes.string,\r\n};\r\n"],"names":["InfoBox","Component","constructor","props","super","otsikkoRef","createRef","htmlTextRef","this","state","items","title","text","rev","isLoaded","componentDidMount","getData","error","console","log","url","import","helpId","c","cache_read","helps_cacheName","processJson","then","res","json","catch","length","setState","htmlText","htmltext","img","shortText","shorttext","editOtsikko","editText","onShowSuljeButtonChange","render","allowEdit","onEditTitleButtonClick","value","onEditHtmlTextButtonClick","onSaveTitleButtonClick","cache_clear","otsikko","current","requestOptions","method","headers","body","JSON","stringify","response","onSaveHtmlTextButtonClick","htmlTeksti","jsxs","Fragment","children","Grid","container","sx","width","jsx","size","xs","TextField","fullWidth","id","label","defaultValue","inputRef","onKeyDown","e","key","Typography","variant","color","component","whiteSpace","dangerouslySetInnerHTML","__html","ProgressCirc","isLoading","className","IconButton","onClick","SaveIcon","EditIcon","multiline","maxRows","style","Tooltip","disableInteractive","StepButtons","onCancelKlik","onSaveKlik","propTypes","PropTypes","bool","func","string"],"mappings":"4aAoBA,MAAqBA,UAAgBC,EAAAA,UACnCC,WAAAA,CAAYC,GACVC,MAAMD,GACDE,KAAAA,WAAaC,cACbC,KAAAA,YAAcD,cACnBE,KAAKC,MAAQ,CACXC,MAAO,GACPC,MAAO,aACPC,KAAM,GACNC,IAAK,EACLC,UAAU,EACZ,CAEFC,iBAAAA,GACM,IACFP,KAAKQ,gBACEC,GACPC,QAAQC,IAAIF,EAAK,CACnB,CAGFD,OAAAA,GACQI,MAAAA,EACJC,uDAAsDb,KAAKL,MAAMmB,OAC/D,IACIC,MAAAA,EAAIC,EAAWC,EAAiBL,GACtC,GAAIG,EAEF,YADAf,KAAKkB,YAAYH,GAIbH,MAAAA,GACHO,MAAMC,GAAQA,EAAIC,SAClBF,MAAeE,IACFJ,EAAAA,EAAiBL,EAAKS,EAAM,MACxCrB,KAAKkB,YAAYG,EAAI,IAEtBC,OAAiBb,IACVA,MAAAA,CAAAA,UAEHA,GACPC,QAAQC,IAAIF,EAAK,CACnB,CAGFS,WAAAA,CAAYG,GACNA,EAAKE,OAAS,EAChBvB,KAAKwB,SAAS,CACZrB,MAAOkB,EAAK,GAAGlB,MACfsB,SAAUJ,EAAK,GAAGK,SAClBC,IAAKN,EAAK,GAAGM,IACbtB,IAAKgB,EAAK,GAAGhB,IACbuB,UAAWP,EAAK,GAAGQ,iBAGhBL,SAAS,CACZrB,MAAO,kBAGXH,KAAKwB,SAAS,CACZ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