@@ -12,6 +12,7 @@ import { tryCatch } from "@monkeytype/util/trycatch";
1212import { LanguageList } from "../constants/languages" ;
1313import { Language } from "@monkeytype/schemas/languages" ;
1414import { LayoutObject } from "@monkeytype/schemas/layouts" ;
15+ import { qs , qsr } from "../utils/dom" ;
1516
1617type FilterPreset = {
1718 display : string ;
@@ -26,7 +27,9 @@ type FilterPreset = {
2627 }
2728) ;
2829
29- const exactMatchCheckbox = $ ( "#wordFilterModal #exactMatchOnly" ) ;
30+ const exactMatchCheckbox = qs < HTMLInputElement > (
31+ "#wordFilterModal #exactMatchOnly" ,
32+ ) ;
3033
3134const presets : Record < string , FilterPreset > = {
3235 homeKeys : {
@@ -82,26 +85,26 @@ const presets: Record<string, FilterPreset> = {
8285} ;
8386
8487async function initSelectOptions ( ) : Promise < void > {
85- $ ( "#wordFilterModal .languageInput" ) . empty ( ) ;
86- $ ( "#wordFilterModal .layoutInput" ) . empty ( ) ;
87- $ ( "wordFilterModal .presetInput" ) . empty ( ) ;
88+ qsr ( "#wordFilterModal .languageInput" ) . empty ( ) ;
89+ qsr ( "#wordFilterModal .layoutInput" ) . empty ( ) ;
90+ qsr ( "wordFilterModal .presetInput" ) . empty ( ) ;
8891
8992 LanguageList . forEach ( ( language ) => {
9093 const prettyLang = language . replace ( / _ / gi, " " ) ;
91- $ ( "#wordFilterModal .languageInput" ) . append ( `
94+ qsr ( "#wordFilterModal .languageInput" ) . appendHtml ( `
9295 <option value=${ language } >${ prettyLang } </option>
9396 ` ) ;
9497 } ) ;
9598
9699 for ( const layout of LayoutsList ) {
97100 const prettyLayout = layout . replace ( / _ / gi, " " ) ;
98- $ ( "#wordFilterModal .layoutInput" ) . append ( `
101+ qsr ( "#wordFilterModal .layoutInput" ) . appendHtml ( `
99102 <option value=${ layout } >${ prettyLayout } </option>
100103 ` ) ;
101104 }
102105
103106 for ( const [ presetId , preset ] of Object . entries ( presets ) ) {
104- $ ( "#wordFilterModal .presetInput" ) . append (
107+ qsr ( "#wordFilterModal .presetInput" ) . appendHtml (
105108 `<option value=${ presetId } >${ preset . display } </option>` ,
106109 ) ;
107110 }
@@ -133,7 +136,7 @@ export async function show(showOptions?: ShowOptions): Promise<void> {
133136 contentLocation : modal . getModal ( ) ,
134137 } ,
135138 } ) ;
136- $ ( "#wordFilterModal .loadingIndicator" ) . removeClass ( "hidden" ) ;
139+ qsr ( "#wordFilterModal .loadingIndicator" ) . removeClass ( "hidden" ) ;
137140 enableButtons ( ) ;
138141 } ,
139142 } ) ;
@@ -146,8 +149,10 @@ function hide(hideOptions?: HideOptions<OutgoingData>): void {
146149}
147150
148151async function filter ( language : Language ) : Promise < string [ ] > {
149- const exactMatchOnly = exactMatchCheckbox . is ( ":checked" ) ;
150- let filterin = $ ( "#wordFilterModal .wordIncludeInput" ) . val ( ) as string ;
152+ const exactMatchOnly = exactMatchCheckbox ?. isChecked ( ) as boolean ;
153+ let filterin = qsr < HTMLInputElement > (
154+ "#wordFilterModal .wordIncludeInput" ,
155+ ) . getValue ( ) as string ;
151156 filterin = Misc . escapeRegExp ( filterin ?. trim ( ) ) ;
152157 filterin = filterin . replace ( / \s + / gi, "|" ) ;
153158 let regincl ;
@@ -158,7 +163,9 @@ async function filter(language: Language): Promise<string[]> {
158163 regincl = new RegExp ( filterin , "i" ) ;
159164 }
160165
161- let filterout = $ ( "#wordFilterModal .wordExcludeInput" ) . val ( ) as string ;
166+ let filterout = qsr < HTMLInputElement > (
167+ "#wordFilterModal .wordExcludeInput" ,
168+ ) . getValue ( ) as string ;
162169 filterout = Misc . escapeRegExp ( filterout . trim ( ) ) ;
163170 filterout = filterout . replace ( / \s + / gi, "|" ) ;
164171 const regexcl = new RegExp ( filterout , "i" ) ;
@@ -175,8 +182,12 @@ async function filter(language: Language): Promise<string[]> {
175182 return [ ] ;
176183 }
177184
178- const maxLengthInput = $ ( "#wordFilterModal .wordMaxInput" ) . val ( ) as string ;
179- const minLengthInput = $ ( "#wordFilterModal .wordMinInput" ) . val ( ) as string ;
185+ const maxLengthInput = qsr < HTMLInputElement > (
186+ "#wordFilterModal .wordMaxInput" ,
187+ ) . getValue ( ) as string ;
188+ const minLengthInput = qsr < HTMLInputElement > (
189+ "#wordFilterModal .wordMinInput" ,
190+ ) . getValue ( ) as string ;
180191 let maxLength ;
181192 let minLength ;
182193 if ( maxLengthInput === "" ) {
@@ -204,7 +215,9 @@ async function filter(language: Language): Promise<string[]> {
204215}
205216
206217async function apply ( set : boolean ) : Promise < void > {
207- const language = $ ( "#wordFilterModal .languageInput" ) . val ( ) as Language ;
218+ const language = qsr < HTMLSelectElement > (
219+ "#wordFilterModal .languageInput" ,
220+ ) . getValue ( ) as Language ;
208221 const filteredWords = await filter ( language ) ;
209222
210223 if ( filteredWords . length === 0 ) {
@@ -226,16 +239,22 @@ async function apply(set: boolean): Promise<void> {
226239}
227240
228241function setExactMatchInput ( disable : boolean ) : void {
229- const wordExcludeInputEl = $ ( "#wordFilterModal #wordExcludeInput" ) ;
242+ const wordExcludeInputEl = qsr < HTMLInputElement > (
243+ "#wordFilterModal #wordExcludeInput" ,
244+ ) ;
230245
231246 if ( disable ) {
232- $ ( "#wordFilterModal #wordExcludeInput" ) . val ( "" ) ;
233- wordExcludeInputEl . attr ( "disabled" , "disabled" ) ;
247+ wordExcludeInputEl . setValue ( "" ) ;
248+ wordExcludeInputEl . disable ( ) ;
234249 } else {
235- wordExcludeInputEl . removeAttr ( "disabled" ) ;
250+ wordExcludeInputEl . enable ( ) ;
236251 }
237252
238- exactMatchCheckbox . prop ( "checked" , disable ) ;
253+ if ( disable ) {
254+ exactMatchCheckbox ?. removeAttribute ( "checked" ) ;
255+ } else {
256+ exactMatchCheckbox ?. setAttribute ( "checked" , "true" ) ;
257+ }
239258}
240259
241260function disableButtons ( ) : void {
@@ -253,9 +272,13 @@ function enableButtons(): void {
253272async function setup ( ) : Promise < void > {
254273 await initSelectOptions ( ) ;
255274
256- $ ( "#wordFilterModal button.generateButton" ) . on ( "click" , async ( ) => {
257- const presetName = $ ( "#wordFilterModal .presetInput" ) . val ( ) as string ;
258- const layoutName = $ ( "#wordFilterModal .layoutInput" ) . val ( ) as string ;
275+ qsr ( "#wordFilterModal button.generateButton" ) . on ( "click" , async ( ) => {
276+ const presetName = qsr < HTMLSelectElement > (
277+ "#wordFilterModal .presetInput" ,
278+ ) . getValue ( ) as string ;
279+ const layoutName = qsr < HTMLSelectElement > (
280+ "#wordFilterModal .layoutInput" ,
281+ ) . getValue ( ) as string ;
259282
260283 const presetToApply = presets [ presetName ] ;
261284
@@ -266,7 +289,7 @@ async function setup(): Promise<void> {
266289
267290 const layout = await JSONData . getLayout ( layoutName ) ;
268291
269- $ ( "#wordIncludeInput" ) . val (
292+ qsr < HTMLInputElement > ( "#wordIncludeInput" ) . setValue (
270293 presetToApply
271294 . getIncludeString ( layout )
272295 . map ( ( x ) => x [ 0 ] )
@@ -278,7 +301,7 @@ async function setup(): Promise<void> {
278301 } else {
279302 setExactMatchInput ( false ) ;
280303 if ( presetToApply . getExcludeString !== undefined ) {
281- $ ( "#wordExcludeInput" ) . val (
304+ qsr < HTMLInputElement > ( "#wordExcludeInput" ) . setValue (
282305 presetToApply
283306 . getExcludeString ( layout )
284307 . map ( ( x ) => x [ 0 ] )
@@ -288,20 +311,20 @@ async function setup(): Promise<void> {
288311 }
289312 } ) ;
290313
291- exactMatchCheckbox . on ( "change" , ( ) => {
292- setExactMatchInput ( exactMatchCheckbox . is ( ":checked" ) ) ;
314+ exactMatchCheckbox ? .on ( "change" , ( ) => {
315+ setExactMatchInput ( exactMatchCheckbox . isChecked ( ) as boolean ) ;
293316 } ) ;
294317
295- $ ( "#wordFilterModal button.addButton" ) . on ( "click" , ( ) => {
296- $ ( "#wordFilterModal .loadingIndicator" ) . removeClass ( "hidden" ) ;
318+ qsr ( "#wordFilterModal button.addButton" ) . on ( "click" , ( ) => {
319+ qsr ( "#wordFilterModal .loadingIndicator" ) . show ( ) ;
297320 disableButtons ( ) ;
298321 setTimeout ( ( ) => {
299322 void apply ( false ) ;
300323 } , 0 ) ;
301324 } ) ;
302325
303- $ ( "#wordFilterModal button.setButton" ) . on ( "click" , ( ) => {
304- $ ( "#wordFilterModal .loadingIndicator" ) . removeClass ( "hidden" ) ;
326+ qsr ( "#wordFilterModal button.setButton" ) . on ( "click" , ( ) => {
327+ qsr ( "#wordFilterModal .loadingIndicator" ) . show ( ) ;
305328 disableButtons ( ) ;
306329 setTimeout ( ( ) => {
307330 void apply ( true ) ;
0 commit comments