-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[view] Theme Selector 테마 전역 저장 및 코드 리팩토링 #760
Changes from all commits
f9821f3
c6bd614
c49f15d
78e43a9
e03075f
7bd6aa5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useEffect, useRef, useState } from "react"; | ||
import "./ThemeSelector.scss"; | ||
import AutoAwesomeIcon from "@mui/icons-material/AutoAwesome"; | ||
import CloseIcon from "@mui/icons-material/Close"; | ||
|
||
const themes = [ | ||
import { setCustomTheme } from "services"; | ||
|
||
type ThemeInfo = { | ||
title: string; | ||
value: string; | ||
colors: { | ||
primary: string; | ||
secondary: string; | ||
tertiary: string; | ||
}; | ||
}; | ||
|
||
type ThemeIconsProps = ThemeInfo & { | ||
onClick: () => void; | ||
}; | ||
|
||
const themeInfo: ThemeInfo[] = [ | ||
{ | ||
title: "Githru", | ||
value: "githru", | ||
|
@@ -52,83 +68,82 @@ const themes = [ | |
}, | ||
]; | ||
|
||
type ThemeIconsProps = { | ||
title: string; | ||
value: string; | ||
colors: { | ||
primary: string; | ||
secondary: string; | ||
tertiary: string; | ||
}; | ||
onClick: () => void; | ||
}; | ||
|
||
const ThemeIcons = ({ title, value, colors, onClick }: ThemeIconsProps) => { | ||
const [isSelected, setIsSelected] = useState<string>(""); | ||
const [selectedItem, setSelectedItem] = useState<string>(""); | ||
|
||
useEffect(() => { | ||
const selectedTheme = document.documentElement.getAttribute("custom-type"); | ||
if (selectedTheme) setIsSelected(selectedTheme); | ||
if (selectedTheme) setSelectedItem(selectedTheme); | ||
}, []); | ||
|
||
return ( | ||
<div | ||
className={`theme-icon${isSelected === value ? "--selected" : ""}`} | ||
className={`theme-icon${selectedItem === value ? "--selected" : ""}`} | ||
onClick={onClick} | ||
role="presentation" | ||
> | ||
<div className="theme-icon__container"> | ||
<div | ||
className="theme-icon__color" | ||
style={{ backgroundColor: colors.primary }} | ||
/> | ||
<div | ||
className="theme-icon__color" | ||
style={{ backgroundColor: colors.secondary }} | ||
/> | ||
<div | ||
className="theme-icon__color" | ||
style={{ backgroundColor: colors.tertiary }} | ||
/> | ||
{Object.values(colors).map((color, index) => ( | ||
<div | ||
key={Number(index)} | ||
className="theme-icon__color" | ||
style={{ backgroundColor: color }} | ||
/> | ||
))} | ||
</div> | ||
<p className="theme-icon__title">{title}</p> | ||
</div> | ||
); | ||
}; | ||
|
||
const ThemeSelector = () => { | ||
const [open, setOpen] = useState<boolean>(false); | ||
const [isOpen, setIsOpen] = useState<boolean>(false); | ||
const themeSelectorRef = useRef<HTMLDivElement>(null); | ||
|
||
const handleTheme = (value: string) => { | ||
setCustomTheme(value); | ||
document.documentElement.setAttribute("custom-type", value); | ||
}; | ||
|
||
useEffect(() => { | ||
document.documentElement.setAttribute("custom-type", "githru"); | ||
const handleClickOutside = (event: MouseEvent) => { | ||
if (themeSelectorRef.current && !themeSelectorRef.current.contains(event.target as Node)) { | ||
setIsOpen(false); | ||
} | ||
}; | ||
document.addEventListener("mousedown", handleClickOutside); | ||
return () => { | ||
document.removeEventListener("mousedown", handleClickOutside); | ||
}; | ||
}, []); | ||
|
||
Comment on lines
+109
to
+118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (궁금💭) if (themeSelectorRef.current && !themeSelectorRef.current.contains(event.target as Node)) 해당 조건이 어떤 이유로 필요한지 궁금합니다! ?ㅅ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 부분은 theme selector의 바깥 영역을 확인하는 코드인데요,
|
||
useEffect(() => { | ||
document.documentElement.setAttribute("custom-type", window.theme); | ||
}, []); | ||
|
||
return ( | ||
<div className="theme-selector"> | ||
<AutoAwesomeIcon onClick={() => setOpen(true)} /> | ||
{open && ( | ||
<div | ||
className="theme-selector" | ||
ref={themeSelectorRef} | ||
> | ||
<AutoAwesomeIcon onClick={() => setIsOpen(true)} /> | ||
{isOpen && ( | ||
<div className="theme-selector__container"> | ||
<div className="theme-selector__header"> | ||
<p>Theme</p> | ||
<CloseIcon | ||
fontSize="small" | ||
onClick={() => setOpen(false)} | ||
onClick={() => setIsOpen(false)} | ||
/> | ||
</div> | ||
<div className="theme-selector__list"> | ||
{themes.map((theme) => ( | ||
{themeInfo.map((theme) => ( | ||
<ThemeIcons | ||
key={theme.value} | ||
title={theme.title} | ||
value={theme.value} | ||
colors={theme.colors} | ||
{...theme} | ||
onClick={() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍👍👍👍👍👍👍 |
||
handleTheme(theme.value); | ||
setOpen(false); | ||
setIsOpen(false); | ||
}} | ||
/> | ||
))} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,5 @@ export default interface IDEPort { | |
sendRefreshDataMessage: (payload?: string) => void; | ||
sendFetchAnalyzedDataMessage: (payload?: string) => void; | ||
sendFetchBranchListMessage: () => void; | ||
setPrimaryColor: (color: string) => void; | ||
setCustomTheme: (theme: string) => void; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사소한 부분이지만 실제 setCustomTheme 함수의 매개변수는 color라고 되어있는 것 같습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
어느 부분에서 사용되는 함수인지 명시적으로 사용해야겠습니다 ............ |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import * as vscode from "vscode"; | |
|
||
const SETTING_PROPERTY_NAMES = { | ||
GITHUB_TOKEN: "githru.github.token", | ||
PRIMARY_COLOR: "githru.color.primary", | ||
THEME: "githru.theme", | ||
}; | ||
|
||
export const getGithubToken = async (secrets: vscode.SecretStorage) => { | ||
|
@@ -14,22 +14,21 @@ export const setGithubToken = async (secrets: vscode.SecretStorage, newGithubTok | |
}; | ||
|
||
export const deleteGithubToken = async (secrets: vscode.SecretStorage) => { | ||
return await secrets.delete(SETTING_PROPERTY_NAMES.GITHUB_TOKEN); | ||
} | ||
return await secrets.delete(SETTING_PROPERTY_NAMES.GITHUB_TOKEN); | ||
}; | ||
|
||
export const setPrimaryColor = (color: string) => { | ||
export const setTheme = async (newTheme: string) => { | ||
const configuration = vscode.workspace.getConfiguration(); | ||
configuration.update(SETTING_PROPERTY_NAMES.PRIMARY_COLOR, color); | ||
configuration.update(SETTING_PROPERTY_NAMES.THEME, newTheme); | ||
}; | ||
|
||
export const getPrimaryColor = (): string => { | ||
export const getTheme = async (): Promise<string> => { | ||
Comment on lines
+20
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (궁금) async를 왜 달아주셨는지 궁금합니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분 트러블슈팅 하다가 configuration 가져오는 부분이 비동기인가 싶어서 추가했던 것 같습니다 .. ! 다음 이슈에서 수정하도록 하겠습니다 !! |
||
const configuration = vscode.workspace.getConfiguration(); | ||
const primaryColor = configuration.get(SETTING_PROPERTY_NAMES.PRIMARY_COLOR) as string; | ||
const theme = configuration.get(SETTING_PROPERTY_NAMES.THEME) as string; | ||
|
||
if (!primaryColor) { | ||
configuration.update(SETTING_PROPERTY_NAMES.PRIMARY_COLOR, "#ff8272"); | ||
return "#ff8272"; | ||
} else { | ||
return primaryColor; | ||
if (!theme) { | ||
await setTheme("githru"); | ||
return "githru"; | ||
} | ||
return theme; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분 너무 깔끔하고 좋은거 같습니다!!