User commited on
Commit
e7b6f84
·
1 Parent(s): 6d969de

Deploy theme state fix

Browse files
TaskTrackingSystem.WebApp/Components/App.razor CHANGED
@@ -23,6 +23,7 @@
23
  } catch {
24
  }
25
  document.documentElement.classList.toggle('dark', theme === 'dark');
 
26
  })();
27
  </script>
28
  <script>
@@ -550,7 +551,13 @@
550
  apply(theme) {
551
  const normalizedTheme = normalizeThemePreference(theme);
552
  const isDark = normalizedTheme === 'dark';
553
- document.documentElement.classList.toggle('dark', isDark);
 
 
 
 
 
 
554
  try {
555
  localStorage.setItem(themePreferenceStorageKey, normalizedTheme);
556
  } catch {
@@ -566,11 +573,14 @@
566
  return this.apply(theme);
567
  },
568
  toggle() {
569
- return this.apply(document.documentElement.classList.contains('dark') ? 'light' : 'dark');
 
 
570
  }
571
  };
572
  window.updateTaskifyThemeControls = function () {
573
- const isDark = document.documentElement.classList.contains('dark');
 
574
  const title = isDark ? 'Switch to light mode' : 'Switch to dark mode';
575
  const iconName = isDark ? 'sun' : 'moon';
576
  document.querySelectorAll('[data-theme-toggle]').forEach(button => {
@@ -584,16 +594,14 @@
584
  });
585
  initIcons();
586
  };
587
- document.addEventListener('click', event => {
588
- const button = event.target.closest('[data-theme-toggle]');
589
- if (!button) {
590
- return;
591
  }
592
- event.preventDefault();
593
- event.stopPropagation();
594
  window.themePreference.toggle();
595
  window.updateTaskifyThemeControls();
596
- }, true);
 
597
  function downloadFile(filename, contentType, content) {
598
  const file = new Blob([content], {type: contentType});
599
  const exportUrl = URL.createObjectURL(file);
 
23
  } catch {
24
  }
25
  document.documentElement.classList.toggle('dark', theme === 'dark');
26
+ document.documentElement.dataset.theme = theme;
27
  })();
28
  </script>
29
  <script>
 
551
  apply(theme) {
552
  const normalizedTheme = normalizeThemePreference(theme);
553
  const isDark = normalizedTheme === 'dark';
554
+ const root = document.documentElement;
555
+ root.classList.toggle('dark', isDark);
556
+ root.dataset.theme = normalizedTheme;
557
+ if (document.body) {
558
+ document.body.classList.toggle('dark', isDark);
559
+ document.body.dataset.theme = normalizedTheme;
560
+ }
561
  try {
562
  localStorage.setItem(themePreferenceStorageKey, normalizedTheme);
563
  } catch {
 
573
  return this.apply(theme);
574
  },
575
  toggle() {
576
+ const currentTheme = document.documentElement.dataset.theme ||
577
+ (document.documentElement.classList.contains('dark') ? 'dark' : 'light');
578
+ return this.apply(currentTheme === 'dark' ? 'light' : 'dark');
579
  }
580
  };
581
  window.updateTaskifyThemeControls = function () {
582
+ const isDark = document.documentElement.dataset.theme === 'dark' ||
583
+ document.documentElement.classList.contains('dark');
584
  const title = isDark ? 'Switch to light mode' : 'Switch to dark mode';
585
  const iconName = isDark ? 'sun' : 'moon';
586
  document.querySelectorAll('[data-theme-toggle]').forEach(button => {
 
594
  });
595
  initIcons();
596
  };
597
+ window.toggleTaskifyThemeButton = function () {
598
+ if (!window.themePreference) {
599
+ return false;
 
600
  }
 
 
601
  window.themePreference.toggle();
602
  window.updateTaskifyThemeControls();
603
+ return false;
604
+ };
605
  function downloadFile(filename, contentType, content) {
606
  const file = new Blob([content], {type: contentType});
607
  const exportUrl = URL.createObjectURL(file);
TaskTrackingSystem.WebApp/Components/Partial/ThemeToggle.razor CHANGED
@@ -1,6 +1,7 @@
1
  <button type="button"
2
  class="control-button"
3
  data-theme-toggle
 
4
  title="Switch to dark mode"
5
  aria-label="Switch to dark mode"
6
  aria-pressed="false">
 
1
  <button type="button"
2
  class="control-button"
3
  data-theme-toggle
4
+ onclick="return window.toggleTaskifyThemeButton && window.toggleTaskifyThemeButton(this);"
5
  title="Switch to dark mode"
6
  aria-label="Switch to dark mode"
7
  aria-pressed="false">