diff --git a/app/soapbox/features/ui/components/theme_toggle.js b/app/soapbox/features/ui/components/theme_toggle.js deleted file mode 100644 index c91c67c807..0000000000 Binary files a/app/soapbox/features/ui/components/theme_toggle.js and /dev/null differ diff --git a/app/soapbox/features/ui/components/theme_toggle.tsx b/app/soapbox/features/ui/components/theme_toggle.tsx new file mode 100644 index 0000000000..34d5d3b0e2 --- /dev/null +++ b/app/soapbox/features/ui/components/theme_toggle.tsx @@ -0,0 +1,46 @@ +import React from 'react'; +import { defineMessages, useIntl } from 'react-intl'; +import { useDispatch } from 'react-redux'; +import Toggle from 'react-toggle'; +import { v4 as uuidv4 } from 'uuid'; + +import { changeSetting } from 'soapbox/actions/settings'; +import { useSettings } from 'soapbox/hooks'; + +const messages = defineMessages({ + switchToLight: { id: 'tabs_bar.theme_toggle_light', defaultMessage: 'Switch to light theme' }, + switchToDark: { id: 'tabs_bar.theme_toggle_dark', defaultMessage: 'Switch to dark theme' }, +}); + +interface IThemeToggle { + showLabel: boolean, +} + +function ThemeToggle({ showLabel }: IThemeToggle) { + const intl = useIntl(); + const dispatch = useDispatch(); + const themeMode = useSettings().get('themeMode'); + + const id = uuidv4(); + const label = intl.formatMessage(themeMode === 'light' ? messages.switchToDark : messages.switchToLight); + + const onToggle = () => { + const setting = themeMode === 'light' ? 'dark' : 'light'; + dispatch(changeSetting(['themeMode'], setting)); + }; + + return ( +