@@ -7,10 +7,16 @@ import { STORAGE_KEYS } from "../../background/constants";
77type UppercaseFontWeight = "REGULAR" | "BOLD" | "XBOLD" ;
88type UppercaseFontSize = "XS" | "S" | "M" | "L" | "XL" ;
99
10- const ControlFont = ( ) => {
10+ interface ControlFontProps {
11+ onClose : ( ) => void ;
12+ }
13+
14+ const ControlFont : React . FC < ControlFontProps > = ( { onClose } ) => {
1115 const [ selectedWeight , setSelectedWeight ] =
1216 useState < UppercaseFontWeight > ( "BOLD" ) ;
1317 const [ selectedSize , setSelectedSize ] = useState < UppercaseFontSize > ( "S" ) ;
18+ const [ hasChanged , setHasChanged ] = useState ( false ) ;
19+
1420 const {
1521 setFontSize,
1622 setFontWeight,
@@ -63,14 +69,6 @@ const ControlFont = () => {
6369 }
6470 } , [ fontWeight , fontSize ] ) ;
6571
66- function isValidFontWeight ( value : string ) : value is UppercaseFontWeight {
67- return [ "REGULAR" , "BOLD" , "XBOLD" ] . includes ( value ) ;
68- }
69-
70- function isValidFontSize ( value : string ) : value is UppercaseFontSize {
71- return [ "XS" , "S" , "M" , "L" , "XL" ] . includes ( value ) ;
72- }
73-
7472 const sendMessage = ( type : string ) => {
7573 chrome . runtime . sendMessage ( { type } , ( response ) => {
7674 if ( chrome . runtime . lastError ) {
@@ -81,39 +79,35 @@ const ControlFont = () => {
8179
8280 const handleWeightClick = ( label : string ) => {
8381 const value = weightMap [ label ] ;
82+
83+ if ( value !== selectedWeight ) setHasChanged ( true ) ;
8484 setSelectedWeight ( value ) ;
8585
86- if ( chrome ?. storage ?. local ) {
87- chrome . storage . local
88- . set ( { [ STORAGE_KEYS . FONT_WEIGHT ] : toFontWeight ( value ) } )
89- . catch ( ( err ) => console . error ( "ํฐํธ ๊ตต๊ธฐ ์ ์ฅ ์ค๋ฅ:" , err ) ) ;
90- }
86+ chrome . storage ?. local
87+ . set ( { [ STORAGE_KEYS . FONT_WEIGHT ] : toFontWeight ( value ) } )
88+ . catch ( ( err ) => console . error ( "ํฐํธ ๊ตต๊ธฐ ์ ์ฅ ์ค๋ฅ:" , err ) ) ;
9189
9290 sendMessage ( `SET_FONT_WEIGHT_${ value } ` ) ;
93-
94- const fontWeight = toFontWeight ( value ) ;
95- setFontWeight ( fontWeight ) ;
91+ setFontWeight ( toFontWeight ( value ) ) ;
9692 } ;
9793
9894 const handleSizeClick = ( label : string ) => {
9995 const value = sizeMap [ label ] ;
96+
97+ if ( value !== selectedSize ) setHasChanged ( true ) ;
10098 setSelectedSize ( value ) ;
10199
102- if ( chrome ?. storage ?. local ) {
103- chrome . storage . local
104- . set ( { [ STORAGE_KEYS . FONT_SIZE ] : toFontSize ( value ) } )
105- . catch ( ( err ) => console . error ( "ํฐํธ ํฌ๊ธฐ ์ ์ฅ ์ค๋ฅ:" , err ) ) ;
106- }
100+ chrome . storage ?. local
101+ . set ( { [ STORAGE_KEYS . FONT_SIZE ] : toFontSize ( value ) } )
102+ . catch ( ( err ) => console . error ( "ํฐํธ ํฌ๊ธฐ ์ ์ฅ ์ค๋ฅ:" , err ) ) ;
107103
108104 sendMessage ( `SET_FONT_SIZE_${ value } ` ) ;
109-
110- const fontSize = toFontSize ( value ) ;
111- setFontSize ( fontSize ) ;
105+ setFontSize ( toFontSize ( value ) ) ;
112106 } ;
113107
114108 return (
115109 < div
116- className = { `inline-flex flex-col items-start p-[18px] rounded-[20px] ${
110+ className = { `inline-flex flex-col items-start p-[18px] rounded-[20px] ${
117111 isDarkMode
118112 ? `bg-grayscale-900 text-grayscale-100`
119113 : `bg-grayscale-100 text-grayscale-900`
@@ -153,6 +147,13 @@ const ControlFont = () => {
153147 ) }
154148 </ div >
155149 </ div >
150+
151+ < button
152+ onClick = { onClose }
153+ className = "w-full h-[68px] mt-[18px] py-[10px] rounded-[14px] bg-purple-default text-white font-20-Bold"
154+ >
155+ { hasChanged ? "์๋ฃ" : "๋ซ๊ธฐ" }
156+ </ button >
156157 </ div >
157158 ) ;
158159} ;
0 commit comments