From f3d066abd1d1ec0de33767bb4cd82a9a8e3412b6 Mon Sep 17 00:00:00 2001 From: ShimaginAndrey Date: Wed, 9 Mar 2022 12:49:09 +0300 Subject: [PATCH] Refactoring 'EditText' --- .../mobile/src/view/edit/EditText.jsx | 27 ++++++----------- .../mobile/src/view/edit/EditText.jsx | 27 ++++++----------- .../mobile/src/view/edit/EditCell.jsx | 29 +++++++------------ .../mobile/src/view/edit/EditText.jsx | 27 ++++++----------- 4 files changed, 37 insertions(+), 73 deletions(-) diff --git a/apps/documenteditor/mobile/src/view/edit/EditText.jsx b/apps/documenteditor/mobile/src/view/edit/EditText.jsx index 4043672ba..b38ce1be0 100644 --- a/apps/documenteditor/mobile/src/view/edit/EditText.jsx +++ b/apps/documenteditor/mobile/src/view/edit/EditText.jsx @@ -25,26 +25,10 @@ const PageFonts = props => { const spriteThumbs = storeTextSettings.spriteThumbs; const arrayRecentFonts = storeTextSettings.arrayRecentFonts; - useEffect(() => { - setRecent(getImageUri(arrayRecentFonts)); - - return () => { - } - }, []); - const addRecentStorage = () => { - let arr = []; - arrayRecentFonts.forEach(item => arr.push(item)); setRecent(getImageUri(arrayRecentFonts)); - LocalStorage.setItem('dde-settings-recent-fonts', JSON.stringify(arr)); - } - - const [stateRecent, setRecent] = useState([]); - const [vlFonts, setVlFonts] = useState({ - vlData: { - items: [], - } - }); + LocalStorage.setItem('dde-settings-recent-fonts', JSON.stringify(arrayRecentFonts)); + }; const getImageUri = fonts => { return fonts.map(font => { @@ -55,6 +39,13 @@ const PageFonts = props => { }); }; + const [stateRecent, setRecent] = useState(() => getImageUri(arrayRecentFonts)); + const [vlFonts, setVlFonts] = useState({ + vlData: { + items: [], + } + }); + const renderExternal = (vl, vlData) => { setVlFonts((prevState) => { let fonts = [...prevState.vlData.items]; diff --git a/apps/presentationeditor/mobile/src/view/edit/EditText.jsx b/apps/presentationeditor/mobile/src/view/edit/EditText.jsx index cb6baa7ff..e6bcb068c 100644 --- a/apps/presentationeditor/mobile/src/view/edit/EditText.jsx +++ b/apps/presentationeditor/mobile/src/view/edit/EditText.jsx @@ -209,26 +209,10 @@ const PageFonts = props => { const spriteThumbs = storeTextSettings.spriteThumbs; const arrayRecentFonts = storeTextSettings.arrayRecentFonts; - useEffect(() => { - setRecent(getImageUri(arrayRecentFonts)); - - return () => { - } - }, []); - const addRecentStorage = () => { - let arr = []; - arrayRecentFonts.forEach(item => arr.push(item)); setRecent(getImageUri(arrayRecentFonts)); - LocalStorage.setItem('ppe-settings-recent-fonts', JSON.stringify(arr)); - } - - const [stateRecent, setRecent] = useState([]); - const [vlFonts, setVlFonts] = useState({ - vlData: { - items: [], - } - }); + LocalStorage.setItem('ppe-settings-recent-fonts', JSON.stringify(arrayRecentFonts)); + }; const getImageUri = fonts => { return fonts.map(font => { @@ -239,6 +223,13 @@ const PageFonts = props => { }); }; + const [stateRecent, setRecent] = useState(() => getImageUri(arrayRecentFonts)); + const [vlFonts, setVlFonts] = useState({ + vlData: { + items: [], + } + }); + const renderExternal = (vl, vlData) => { setVlFonts((prevState) => { let fonts = [...prevState.vlData.items]; diff --git a/apps/spreadsheeteditor/mobile/src/view/edit/EditCell.jsx b/apps/spreadsheeteditor/mobile/src/view/edit/EditCell.jsx index 2ab4ceb8b..0c0943407 100644 --- a/apps/spreadsheeteditor/mobile/src/view/edit/EditCell.jsx +++ b/apps/spreadsheeteditor/mobile/src/view/edit/EditCell.jsx @@ -156,26 +156,10 @@ const PageFontsCell = props => { const spriteCols = storeTextSettings.spriteCols; const spriteThumbs = storeTextSettings.spriteThumbs; - useEffect(() => { - setRecent(getImageUri(arrayRecentFonts)); - - return () => { - } - }, []); - const addRecentStorage = () => { - let arr = []; - arrayRecentFonts.forEach(item => arr.push(item)); setRecent(getImageUri(arrayRecentFonts)); - LocalStorage.setItem('sse-settings-recent-fonts', JSON.stringify(arr)); - } - - const [stateRecent, setRecent] = useState([]); - const [vlFonts, setVlFonts] = useState({ - vlData: { - items: [], - } - }); + LocalStorage.setItem('sse-settings-recent-fonts', JSON.stringify(arrayRecentFonts)); + }; const getImageUri = fonts => { return fonts.map(font => { @@ -184,7 +168,14 @@ const PageFontsCell = props => { return thumbCanvas.toDataURL(); }); - }; + }; + + const [stateRecent, setRecent] = useState(() => getImageUri(arrayRecentFonts)); + const [vlFonts, setVlFonts] = useState({ + vlData: { + items: [], + } + }); const renderExternal = (vl, vlData) => { setVlFonts((prevState) => { diff --git a/apps/spreadsheeteditor/mobile/src/view/edit/EditText.jsx b/apps/spreadsheeteditor/mobile/src/view/edit/EditText.jsx index a44c736ab..4baee0613 100644 --- a/apps/spreadsheeteditor/mobile/src/view/edit/EditText.jsx +++ b/apps/spreadsheeteditor/mobile/src/view/edit/EditText.jsx @@ -109,26 +109,10 @@ const PageFonts = props => { const spriteThumbs = storeTextSettings.spriteThumbs; const arrayRecentFonts = storeTextSettings.arrayRecentFonts; - useEffect(() => { - setRecent(getImageUri(arrayRecentFonts)); - - return () => { - } - }, []); - const addRecentStorage = () => { - let arr = []; - arrayRecentFonts.forEach(item => arr.push(item)); setRecent(getImageUri(arrayRecentFonts)); - LocalStorage.setItem('sse-settings-recent-fonts', JSON.stringify(arr)); - } - - const [stateRecent, setRecent] = useState([]); - const [vlFonts, setVlFonts] = useState({ - vlData: { - items: [], - } - }); + LocalStorage.setItem('sse-settings-recent-fonts', JSON.stringify(arrayRecentFonts)); + }; const getImageUri = fonts => { return fonts.map(font => { @@ -139,6 +123,13 @@ const PageFonts = props => { }); }; + const [stateRecent, setRecent] = useState(() => getImageUri(arrayRecentFonts)); + const [vlFonts, setVlFonts] = useState({ + vlData: { + items: [], + } + }); + const renderExternal = (vl, vlData) => { setVlFonts((prevState) => { let fonts = [...prevState.vlData.items];