File tree Expand file tree Collapse file tree 5 files changed +74
-65
lines changed Expand file tree Collapse file tree 5 files changed +74
-65
lines changed Original file line number Diff line number Diff line change 11<template >
22 <nav
3- class =" sticky top-0 left-0 right-0 z-10 text-gray-800 shadow-lg dark:shadow-dark bg-gray-50 dark:bg-gray-900 dark:text-gray-50"
3+ class =" sticky top-0 left-0 right-0 z-10 text-gray-800 shadow-lg dark:shadow-dark bg-gray-50 dark:bg-gray-900 dark:text-gray-50"
44 >
55 <div class =" container flex items-center py-4 m-auto" >
66 <div
6666 <slot name =" right" />
6767 <button
6868 type =" button"
69- class =" inline-flex items-center justify-center ml-4 bg-transparent border-2 border-gray-700 rounded-full shadow-lg w-9 h-9 active:scale-y-75 hover:scale-105 hover:shadow-lg"
70- aria-label =" Toggle Dark Mode"
69+ class =" inline-flex items-center justify-center ml-4 bg-transparent border-2 border-gray-700 rounded-full shadow-lg w-9 h-9 active:scale-y-75 hover:scale-105 hover:shadow-lg"
70+ :aria-label ="
71+ darkMode ? 'Switch to light theme' : 'Switch to dark theme'
72+ "
7173 @click =" toggleDarkMode"
7274 >
7375 <svg
@@ -173,19 +175,24 @@ export default Vue.extend({
173175 },
174176 mounted() {
175177 if (darkMode === null ) {
176- darkMode = this .$cookies .isDarkMode
178+ this . darkMode = darkMode = this .$cookies .isDarkMode
177179 if (darkMode ) {
178180 document .documentElement .classList .add (' dark' )
179181 document .cookie = ` darkMode=${darkMode }; Secure; max-age=31536000; path=/; `
182+ this .$store .commit (' theme/set' , darkMode )
180183 }
181184 }
182185 document .documentElement .classList .remove (' hidden' )
183186 },
184187 methods: {
185188 toggleDarkMode() {
186- darkMode = ! darkMode
187- document .documentElement .classList [darkMode ? ' add' : ' remove' ](' dark' )
188- document .cookie = ` darkMode=${darkMode }; Secure; max-age=31536000; path=/; `
189+ const currentDarkMode = this .darkMode
190+ document .documentElement .classList [! currentDarkMode ? ' add' : ' remove' ](
191+ ' dark'
192+ )
193+ document .cookie = ` darkMode=${! currentDarkMode }; Secure; max-age=31536000; path=/; `
194+ this .$store .commit (' theme/set' , ! currentDarkMode )
195+ this .darkMode = ! currentDarkMode
189196 },
190197 },
191198})
Original file line number Diff line number Diff line change @@ -90,19 +90,22 @@ const diffTutorials: TutorialMetadata[] = [
9090 } ,
9191]
9292
93+ const comparePageTutorials : TutorialMetadata [ ] = [
94+ {
95+ tutorial : labelsTutorial ,
96+ cookieName : 'isSkipTutorial' ,
97+ } ,
98+ {
99+ tutorial : submitShortcutTutorial ,
100+ cookieName : 'isSkipSubmitKbdShortcutTutorial' ,
101+ } ,
102+ ]
103+
93104const tutorialsMetadata : TutorialsMetadata = {
94105 '/v1/diff' : diffTutorials ,
95- 'v2/diff' : diffTutorials ,
96- '/' : [
97- {
98- tutorial : labelsTutorial ,
99- cookieName : 'isSkipTutorial' ,
100- } ,
101- {
102- tutorial : submitShortcutTutorial ,
103- cookieName : 'isSkipSubmitKbdShortcutTutorial' ,
104- } ,
105- ] ,
106+ '/v2/diff' : diffTutorials ,
107+ '/' : comparePageTutorials ,
108+ '/v2' : comparePageTutorials ,
106109}
107110
108111export default async function showTutorials (
Original file line number Diff line number Diff line change 11<template >
22 <div class =" page-contents" >
3+ <!-- Following hidden input is hacky way to update monaco editor theme when user changes theme manually -->
4+ <input type =" hidden" inert :value =" onThemeChange" />
35 <Navbar :show-back-button =" true" />
46 <main class =" outline-none" tabindex =" 0" >
57 <DiffActionBar :diff-navigator =" diffNavigator" />
68 <section
7- class ="
8- flex
9- items-stretch
10- flex-wrap
11- w-full
12- gap-4
13- font-mono
14- text-gray-800
15- dark:text-gray-50
16- "
9+ class =" flex flex-wrap items-stretch w-full gap-4 font-mono text-gray-800 dark:text-gray-50"
1710 >
18- <div class =" flex space-around w-full gap-4" >
11+ <div class =" flex w-full gap-4 space-around " >
1912 <p
20- class ="
21- flex-grow-0 flex-shrink-0
22- w-1/2
23- text-lg
24- font-bold
25- text-center
26- capitalize
27- break-all
28- "
13+ class =" flex-grow-0 flex-shrink-0 w-1/2 text-lg font-bold text-center capitalize break-all "
2914 >
3015 <span class =" inline-block w-4/5" >{{ lhsLabel }}</span >
3116 </p >
3217 <p
33- class ="
34- flex-grow-0 flex-shrink-0
35- w-1/2
36- text-lg
37- font-bold
38- text-center
39- capitalize
40- break-all
41- "
18+ class =" flex-grow-0 flex-shrink-0 w-1/2 text-lg font-bold text-center capitalize break-all "
4219 >
4320 <span class =" inline-block w-4/5" >{{ rhsLabel }}</span >
4421 </p >
@@ -76,6 +53,13 @@ export default Vue.extend({
7653 diffNavigator: {},
7754 }
7855 },
56+ computed: {
57+ onThemeChange() {
58+ const theme = this .$store .state .theme .darkMode ? ' vs-dark' : ' light'
59+ this .monacoDiffEditor ?.updateOptions ?.({ theme })
60+ return this .$store .state .theme .darkMode
61+ },
62+ },
7963 beforeMount() {
8064 const _diff = this .$route .hash
8165 if (_diff ) {
Original file line number Diff line number Diff line change 1+ n
12<template >
23 <div class =" page-contents" >
34 <Navbar />
5+ <!-- Following hidden input is hacky way to update monaco editor theme when user changes theme manually -->
6+ <input type =" hidden" inert :value =" onThemeChange" />
47 <main class =" text-gray-800 outline-none dark:text-gray-50" tabindex =" 0" >
58 <section >
69 <header >
5457 <div class =" self-end flex-grow-0 w-full mt-4 text-center" >
5558 <button
5659 id =" submitButton"
57- class ="
58- inline-flex
59- items-center
60- justify-center
61- w-48
62- px-4
63- py-2
64- transition-transform
65- transform
66- bg-blue-600
67- rounded-md
68- shadow-lg
69- outline-none
70- text-gray-50
71- focus:ring-4
72- active:scale-y-75
73- "
60+ class =" inline-flex items-center justify-center w-48 px-4 py-2 transition-transform transform bg-blue-600 rounded-md shadow-lg outline-none text-gray-50 focus:ring-4 active:scale-y-75"
7461 aria-label =" Click here to compare the inputted text blocks"
7562 >
7663 Compare
@@ -101,6 +88,14 @@ export default Vue.extend({
10188 rhsEditor: null ,
10289 }
10390 },
91+ computed: {
92+ onThemeChange() {
93+ const theme = this .$store .state .theme .darkMode ? ' vs-dark' : ' light'
94+ this .lhsEditor ?.updateOptions ({ theme })
95+ this .rhsEditor ?.updateOptions ({ theme })
96+ return this .$store .state .theme .darkMode
97+ },
98+ },
10499 mounted() {
105100 showTutorials (this .$cookies , this .$route .path , this .$cookies .isDarkMode )
106101 document .addEventListener (' keydown' , this .handleCtrlEnter )
@@ -121,7 +116,7 @@ export default Vue.extend({
121116 this .rhsEditor = monaco .editor .create (rhs , {
122117 ... monacoEditorOptions ,
123118 value: this .rhs || ' ' ,
124- wordWrap: ' on'
119+ wordWrap: ' on' ,
125120 })
126121 }
127122 })
Original file line number Diff line number Diff line change 1+ import { GetterTree , MutationTree } from 'vuex/types'
2+
3+ export const state = ( ) => ( {
4+ darkMode : false
5+ } )
6+
7+ export type themeStore = ReturnType < typeof state >
8+
9+ export const getters : GetterTree < themeStore , themeStore > = {
10+ isEnabled : ( state ) => state . darkMode ,
11+ }
12+
13+ export const mutations : MutationTree < themeStore > = {
14+ toggle ( state ) {
15+ state . darkMode = ! state . darkMode
16+ } ,
17+ set ( state , value ) {
18+ state . darkMode = value
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments