From 0ed20e499fcd5f8e42a9f218cf4b819b48ea9e73 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Mon, 26 Apr 2021 16:41:12 +0200 Subject: [PATCH] [GH-190] Add global option to disable randomized card icons (#310) Relates to: #190 --- webapp/i18n/en.json | 1 + webapp/src/components/centerPanel.tsx | 3 ++- .../components/sidebar/sidebarSettingsMenu.tsx | 15 ++++++++++++++- webapp/src/userSettings.ts | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 webapp/src/userSettings.ts diff --git a/webapp/i18n/en.json b/webapp/i18n/en.json index f6e5f3c7d..c30e0a3e5 100644 --- a/webapp/i18n/en.json +++ b/webapp/i18n/en.json @@ -105,6 +105,7 @@ "Sidebar.logout": "Log out", "Sidebar.no-views-in-board": "No pages inside", "Sidebar.occitan": "Occitan", + "Sidebar.random-icons": "Random icons", "Sidebar.russian": "Russian", "Sidebar.select-a-template": "Select a template", "Sidebar.set-language": "Set language", diff --git a/webapp/src/components/centerPanel.tsx b/webapp/src/components/centerPanel.tsx index fd02641b4..8edc9b823 100644 --- a/webapp/src/components/centerPanel.tsx +++ b/webapp/src/components/centerPanel.tsx @@ -11,6 +11,7 @@ import {CardFilter} from '../cardFilter' import mutator from '../mutator' import {Utils} from '../utils' import {BoardTree} from '../viewModel/boardTree' +import {UserSettings} from '../userSettings' import './centerPanel.scss' import CardDialog from './cardDialog' @@ -217,7 +218,7 @@ class CenterPanel extends React.Component { } } card.properties = {...card.properties, ...propertiesThatMeetFilters} - if (!card.icon) { + if (!card.icon && UserSettings.prefillRandomIcons) { card.icon = BlockIcons.shared.randomIcon() } await mutator.insertBlock( diff --git a/webapp/src/components/sidebar/sidebarSettingsMenu.tsx b/webapp/src/components/sidebar/sidebarSettingsMenu.tsx index 1f8154895..4906f9ee9 100644 --- a/webapp/src/components/sidebar/sidebarSettingsMenu.tsx +++ b/webapp/src/components/sidebar/sidebarSettingsMenu.tsx @@ -1,6 +1,6 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import React, {useContext} from 'react' +import React, {useContext, useState} from 'react' import {FormattedMessage, injectIntl, IntlShape} from 'react-intl' import {Archiver} from '../../archiver' @@ -8,6 +8,7 @@ import {darkTheme, defaultTheme, lightTheme, setTheme, Theme} from '../../theme' import Menu from '../../widgets/menu' import MenuWrapper from '../../widgets/menuWrapper' import {SetLanguageContext} from '../../setLanguageContext' +import {UserSettings} from '../../userSettings' import './sidebarSettingsMenu.scss' @@ -26,6 +27,12 @@ const SidebarSettingsMenu = React.memo((props: Props) => { props.setWhiteLogo(whiteLogo) } + const [randomIcons, setRandomIcons] = useState(UserSettings.prefillRandomIcons) + const toggleRandomIcons = () => { + UserSettings.prefillRandomIcons = !UserSettings.prefillRandomIcons + setRandomIcons(!randomIcons) + } + return (
@@ -128,6 +135,12 @@ const SidebarSettingsMenu = React.memo((props: Props) => { onClick={async () => updateTheme(null)} /> + toggleRandomIcons()} + />
diff --git a/webapp/src/userSettings.ts b/webapp/src/userSettings.ts new file mode 100644 index 000000000..55126f1c9 --- /dev/null +++ b/webapp/src/userSettings.ts @@ -0,0 +1,14 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +class UserSettings { + static get prefillRandomIcons(): boolean { + return localStorage.getItem('randomIcons') !== 'false' + } + + static set prefillRandomIcons(newValue: boolean) { + localStorage.setItem('randomIcons', JSON.stringify(newValue)) + } +} + +export {UserSettings}