2
2
3
3
import { useState } from 'react'
4
4
import { Download , LucideIcon } from 'lucide-react'
5
+ import { parseAsStringLiteral , useQueryState } from 'nuqs'
5
6
6
7
import { downloadText } from '~/shared/lib/download-text'
7
8
@@ -17,7 +18,7 @@ import {
17
18
} from '~/shared/components/select'
18
19
import { CopyButton } from '~/shared/components/copy-button'
19
20
20
- import { Method , morse } from './_lib/morse'
21
+ import { Method , Methods , morse } from './_lib/morse'
21
22
22
23
const ActionButton = ( {
23
24
title,
@@ -43,7 +44,10 @@ const ActionButton = ({
43
44
44
45
export default function Page ( ) {
45
46
const [ plainText , setPlainText ] = useState ( '' )
46
- const [ method , setMethod ] = useState < Method > ( 'encode' )
47
+ const [ method , setMethod ] = useQueryState (
48
+ 'method' ,
49
+ parseAsStringLiteral ( Methods ) . withDefault ( 'encode' )
50
+ )
47
51
48
52
const encodedText = morse ( plainText , method )
49
53
@@ -73,7 +77,7 @@ export default function Page() {
73
77
< div className = "flex justify-center gap-2 flex-wrap" >
74
78
< Select
75
79
onValueChange = { value => setMethod ( value as Method ) }
76
- defaultValue = "encode"
80
+ defaultValue = { method }
77
81
>
78
82
< SelectTrigger className = "w-fit space-x-3" >
79
83
< SelectValue />
0 commit comments