From dc2245f2a87f40255f3faf2c43ffef4688262a12 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 24 Nov 2021 20:22:12 -0300 Subject: [PATCH 1/2] Chore: Migrate ThemeView to Typescript --- app/views/{ThemeView.js => ThemeView.tsx} | 39 +++++++++++++++-------- 1 file changed, 25 insertions(+), 14 deletions(-) rename app/views/{ThemeView.js => ThemeView.tsx} (81%) diff --git a/app/views/ThemeView.js b/app/views/ThemeView.tsx similarity index 81% rename from app/views/ThemeView.js rename to app/views/ThemeView.tsx index 98c0e872d9b..eaa59a806e6 100644 --- a/app/views/ThemeView.js +++ b/app/views/ThemeView.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import PropTypes from 'prop-types'; +import { StackNavigationOptions } from '@react-navigation/stack'; import I18n from '../i18n'; import { withTheme } from '../theme'; @@ -51,18 +51,29 @@ if (supportSystemTheme()) { const themeGroup = THEMES.filter(item => item.group === THEME_GROUP); const darkGroup = THEMES.filter(item => item.group === DARK_GROUP); -class ThemeView extends React.Component { - static navigationOptions = () => ({ +interface ITheme { + label: string; + value: string; + group: string; +} + +interface IThemePreference { + currentTheme: string; + darkLevel: string; +} + +interface IThemeViewProps { + theme: string; + themePreferences: IThemePreference; + setTheme(newTheme?: IThemePreference): void; +} + +class ThemeView extends React.Component { + static navigationOptions = (): StackNavigationOptions => ({ title: I18n.t('Theme') }); - static propTypes = { - theme: PropTypes.string, - themePreferences: PropTypes.object, - setTheme: PropTypes.func - }; - - isSelected = item => { + isSelected = (item: ITheme) => { const { themePreferences } = this.props; const { group } = item; const { darkLevel, currentTheme } = themePreferences; @@ -74,11 +85,11 @@ class ThemeView extends React.Component { } }; - onClick = item => { + onClick = (item: ITheme) => { const { themePreferences } = this.props; const { darkLevel, currentTheme } = themePreferences; const { value, group } = item; - let changes = {}; + let changes = {} as Partial; if (group === THEME_GROUP && currentTheme !== value) { logEvent(events.THEME_SET_THEME_GROUP, { theme_group: value }); changes = { currentTheme: value }; @@ -90,7 +101,7 @@ class ThemeView extends React.Component { this.setTheme(changes); }; - setTheme = async theme => { + setTheme = async (theme: Partial) => { const { setTheme, themePreferences } = this.props; const newTheme = { ...themePreferences, ...theme }; setTheme(newTheme); @@ -102,7 +113,7 @@ class ThemeView extends React.Component { return ; }; - renderItem = ({ item }) => { + renderItem = ({ item }: { item: ITheme }) => { const { label, value } = item; return ( <> From 0676ecd9a1f6c6994c767440c0b458a78c894e83 Mon Sep 17 00:00:00 2001 From: AlexAlexandre Date: Mon, 29 Nov 2021 15:02:24 -0300 Subject: [PATCH 2/2] refactor: minor tweak --- app/views/ThemeView.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/ThemeView.tsx b/app/views/ThemeView.tsx index eaa59a806e6..8ab9010c474 100644 --- a/app/views/ThemeView.tsx +++ b/app/views/ThemeView.tsx @@ -58,8 +58,8 @@ interface ITheme { } interface IThemePreference { - currentTheme: string; - darkLevel: string; + currentTheme?: string; + darkLevel?: string; } interface IThemeViewProps { @@ -89,7 +89,7 @@ class ThemeView extends React.Component { const { themePreferences } = this.props; const { darkLevel, currentTheme } = themePreferences; const { value, group } = item; - let changes = {} as Partial; + let changes: IThemePreference = {}; if (group === THEME_GROUP && currentTheme !== value) { logEvent(events.THEME_SET_THEME_GROUP, { theme_group: value }); changes = { currentTheme: value }; @@ -101,7 +101,7 @@ class ThemeView extends React.Component { this.setTheme(changes); }; - setTheme = async (theme: Partial) => { + setTheme = async (theme: IThemePreference) => { const { setTheme, themePreferences } = this.props; const newTheme = { ...themePreferences, ...theme }; setTheme(newTheme);