Skip to content

Commit bc2849b

Browse files
authored
fix: flickering theme (#3624)
1 parent 2ec59b8 commit bc2849b

File tree

4 files changed

+10
-48
lines changed

4 files changed

+10
-48
lines changed

src/app/views/App.tsx

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { connect } from 'react-redux';
1313
import { removeSpinners } from '../..';
1414
import { authenticationWrapper } from '../../modules/authentication';
1515
import { ApplicationState } from '../../store';
16-
import { loadGETheme } from '../../themes';
1716
import { ThemeContext } from '../../themes/theme-context';
1817
import { Mode } from '../../types/enums';
1918
import {
@@ -62,16 +61,6 @@ interface IAppState {
6261
sidebarTabSelection: string;
6362
}
6463

65-
const getSystemTheme = (): string => {
66-
if (
67-
window.matchMedia &&
68-
window.matchMedia('(prefers-color-scheme: dark)').matches
69-
) {
70-
return 'dark';
71-
}
72-
return 'light';
73-
};
74-
7564
class App extends Component<IAppProps, IAppState> {
7665
private mediaQueryList = window.matchMedia('(max-width: 992px)');
7766

@@ -119,12 +108,6 @@ class App extends Component<IAppProps, IAppState> {
119108
// Listens for messages from host document
120109
window.addEventListener('message', this.receiveMessage, false);
121110
this.handleSharedQueries();
122-
123-
// Load the theme from local storage or use the system theme as the default
124-
const savedTheme = localStorage.getItem('appTheme') ?? getSystemTheme();
125-
// @ts-ignore
126-
this.props.actions.changeTheme(savedTheme);
127-
loadGETheme(savedTheme); // TODO: Remove when cleaning up
128111
};
129112

130113
public handleSharedQueries() {
@@ -193,8 +176,6 @@ class App extends Component<IAppProps, IAppState> {
193176
}
194177

195178
private handleThemeChangeMsg = (msg: IThemeChangedMessage) => {
196-
loadGETheme(msg.theme); // TODO: remove when done moving to fluent ui
197-
198179
// @ts-ignore
199180
this.props.actions!.changeTheme(msg.theme);
200181
};

src/app/views/main-header/settings/ThemeChooser.tsx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useAppDispatch, useAppSelector } from '../../../../store';
44
import { componentNames, eventTypes, telemetry } from '../../../../telemetry';
55
import { PopupsComponent } from '../../../services/context/popups-context';
66
import { changeTheme } from '../../../services/slices/theme.slice';
7-
import { loadGETheme } from '../../../../themes';
87
import { translateMessage } from '../../../utils/translate-messages';
98
import { useIconOptionStyles, useRadioGroupStyles } from './ThemeChooser.styles';
109
import { BrightnessHigh24Regular, WeatherMoon24Regular, DarkTheme24Regular} from '@fluentui/react-icons';
@@ -27,34 +26,18 @@ const availableThemes = [
2726
}
2827
];
2928

30-
const getSystemTheme = (): string => {
31-
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
32-
return 'dark';
33-
}
34-
return 'light';
35-
};
36-
3729
const ThemeChooser: React.FC<PopupsComponent<null>> = (props) => {
3830
const dispatch = useAppDispatch();
3931
const appTheme = useAppSelector(state=> state.theme);
4032
const iconOptionStyles = useIconOptionStyles();
4133
const radioGroupStyles = useRadioGroupStyles();
4234

43-
useEffect(() => {
44-
// Load the theme from local storage or use the system theme as the default
45-
const savedTheme = localStorage.getItem('appTheme') ?? getSystemTheme();
46-
dispatch(changeTheme(savedTheme));
47-
loadGETheme(savedTheme); // Remove when cleaning up
48-
}, [dispatch]);
49-
50-
5135
const handleChangeTheme = (selectedTheme: { key: string; displayName: string; icon: JSX.Element }) => {
5236
const newTheme: string = selectedTheme.key;
5337
// Save the selected theme to local storage
54-
localStorage.setItem('appTheme', newTheme);
38+
localStorage.setItem('CURRENT_THEME', newTheme);
5539
// Applies the theme to the Fluent UI components
5640
dispatch(changeTheme(newTheme));
57-
loadGETheme(newTheme); //Remove when cleaning up
5841
telemetry.trackEvent(eventTypes.BUTTON_CLICK_EVENT, {
5942
ComponentName: componentNames.SELECT_THEME_BUTTON,
6043
SelectedTheme: newTheme.replace('-', ' ').toSentenceCase()

src/app/views/sidebar/history/History.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ const HistoryItems = (props: HistoryProps)=>{
198198
'Today'.split('').forEach(ch=> openHistoryItems.add(ch))
199199
openHistoryItems.add('Today')
200200

201-
const styles = useStyles()
201+
const itemStyles = useStyles()
202202

203203
const [openItems, setOpenItems] = useState<Set<TreeItemValue>>(
204204
() => openHistoryItems
@@ -318,11 +318,11 @@ const HistoryItems = (props: HistoryProps)=>{
318318
aria-posinset={historyLeafs.findIndex((q) => q.createdAt === h.createdAt) + 1}
319319
>
320320
<TreeItemLayout
321-
className={styles.historyTreeItemLayout}
321+
className={itemStyles.historyTreeItemLayout}
322322
onClick={()=>handleViewQuery(h)}
323323
iconBefore={<HistoryStatusCodes status={h.status} method={h.method}/>}
324324
aside={
325-
<div data-history-aside className={styles.historyAsideIcons}>
325+
<div data-history-aside className={itemStyles.historyAsideIcons}>
326326
<HistoryItemActionMenu item={h}/>
327327
{isInCollection(h) ? (
328328
<Tooltip

src/index.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { store } from './store';
2828
import './styles/index.scss';
2929
import { telemetry } from './telemetry';
3030
import ITelemetry from './telemetry/ITelemetry';
31-
import { loadGETheme } from './themes';
3231
import { IDevxAPI } from './types/devx-api';
3332
import { Mode } from './types/enums';
3433
import { IHistoryItem } from './types/history';
@@ -38,7 +37,7 @@ import { Collection } from './types/resources';
3837
const appRoot: HTMLElement = document.getElementById('root')!;
3938
initializeIcons();
4039

41-
let currentTheme = readFromLocalStorage(CURRENT_THEME) || 'light';
40+
let currentTheme = readFromLocalStorage(CURRENT_THEME);
4241
export function removeSpinners() {
4342
// removes the loading spinner from GE html after the app is loaded
4443
const spinner = document.getElementById('spinner');
@@ -56,16 +55,17 @@ export function removeSpinners() {
5655
appRoot.classList.remove('hidden');
5756
}
5857

59-
function setCurrentSystemTheme(): void {
58+
function setCurrentTheme(): void {
6059
const themeFromLocalStorage = readFromLocalStorage(CURRENT_THEME);
6160

6261
if (themeFromLocalStorage) {
6362
currentTheme = themeFromLocalStorage;
6463
} else {
6564
currentTheme = getOSTheme();
65+
localStorage.setItem('CURRENT_THEME', currentTheme);
6666
}
6767

68-
applyCurrentSystemTheme(currentTheme);
68+
applyCurrentTheme(currentTheme);
6969
}
7070
function getOSTheme(): string {
7171
let currentSystemTheme: string;
@@ -88,14 +88,13 @@ function getOSTheme(): string {
8888
return currentSystemTheme;
8989
}
9090

91-
function applyCurrentSystemTheme(themeToApply: string): void {
92-
loadGETheme(themeToApply);
91+
function applyCurrentTheme(themeToApply: string): void {
9392
appStore.dispatch(changeTheme(themeToApply));
9493
}
9594

9695
const appStore: any = store;
9796

98-
setCurrentSystemTheme();
97+
setCurrentTheme();
9998
appStore.dispatch(getGraphProxyUrl());
10099

101100
function refreshAccessToken() {
@@ -116,7 +115,6 @@ setInterval(refreshAccessToken, 1000 * 60 * 10); // refresh access token every 1
116115
const theme = new URLSearchParams(location.search).get('theme');
117116

118117
if (theme) {
119-
loadGETheme(theme);
120118
appStore.dispatch(changeTheme(theme));
121119
appStore.dispatch(setGraphExplorerMode(Mode.TryIt));
122120
} else {

0 commit comments

Comments
 (0)