Skip to content
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

Merged
merged 6 commits into from
Oct 10, 2024

Conversation

taboowiths
Copy link
Contributor

Related issue

#752

Result

2024-10-06.8.11.20.mov

Work list

1. Theme Selector 테마 전역 저장

ThemeSelector를 이용해 선택한 테마를 재접속 시 유지할 수 있도록 구현했습니다.
로직은 다음과 같습니다:

  1. ThemeSelector 컴포넌트를 통해 테마를 선택하여 변경합니다.
  2. vscode api를 통해, vscode에 메시지를 보냅니다. (view/services)
 public setCustomTheme(theme: string) {
    const message: IDEMessage = {
      command: "updateCustomTheme",
      payload: JSON.stringify({ theme }),
    };
    this.sendMessageToIDE(message);
  }
  1. vscode가 메시지를 수신, command에 맞는 동작을 수행합니다.
    여기서는 setTheme() 함수를 호출하여, vscode의 configuration 중 githru.theme 값을 업데이트 합니다.
 // vscode/webview-loader.ts
 if (command === "updateCustomTheme") {
   const colorCode = payload && JSON.parse(payload);
   if (colorCode.theme) {
     setTheme(colorCode.theme);
   }
 }

// vscode/setting-repository.ts
export const setTheme = async (newTheme: string) => {
  const configuration = vscode.workspace.getConfiguration();
  configuration.update(SETTING_PROPERTY_NAMES.THEME, newTheme);
};
  1. 저장된 값은 다음 webview를 로드할 때 getTheme()함수를 통해 vscode configuration에 업데이트 한 theme 값을 가져와 window 객체에 저장합니다. (vscode/webview-loader.ts)
  2. ThemeSelector 컴포넌트에서 window.theme 값을 가져와 테마를 업데이트 합니다.

2. 코드 리팩토링

#687 의 피드백을 반영하여 코드를 리팩토링 했습니다.
type 설정, 변수명 변경, 그리고 selector 영역 외 클릭 시 창이 닫히도록 구현했습니다.

Discussion

@taboowiths taboowiths added this to the v0.7.2 milestone Oct 6, 2024
@taboowiths taboowiths self-assigned this Oct 6, 2024
@taboowiths taboowiths requested review from a team as code owners October 6, 2024 11:32
Copy link
Contributor

@joonwonBaek joonwonBaek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정현님 수고하셨습니다...!!
웹뷰쪽 코드가 까다로운데 잘 구현해주셨네요 👏👏👏

Comment on lines +86 to +92
{Object.values(colors).map((color, index) => (
<div
key={Number(index)}
className="theme-icon__color"
style={{ backgroundColor: color }}
/>
))}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 너무 깔끔하고 좋은거 같습니다!!

@joonwonBaek
Copy link
Contributor

👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍
👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍
👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍

Copy link
Member

@seungineer seungineer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀🚀🚀
theme selector 바깥 영역을 클릭하면, 창이 닫히는 것까지 포함되어 them selector 완성도가 높아져 더욱 좋은 것 같아요 👍👍

Comment on lines +109 to +118
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);
};
}, []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(궁금💭)

if (themeSelectorRef.current && !themeSelectorRef.current.contains(event.target as Node))

해당 조건이 어떤 이유로 필요한지 궁금합니다! ?ㅅ?

Copy link
Contributor Author

@taboowiths taboowiths Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 부분은 theme selector의 바깥 영역을 확인하는 코드인데요,
"mousedown" 이벤트가 발생해 handleClickOutside() 함수가 실행되면,

  1. themeSelectorRef.current 코드를 통해 현재 시점에서 themeSelectorRef가 DOM에 있는지 확인하게 됩니다!
  2. 그리고 DOM에 있다면, !themeSelectorRef.current.contains(event.target as Node) 코드를 통해 현재 이벤트의 타겟인 클릭 지점이 theme selector의 영역 안에 있는지 확인합니다. 클릭 지점이 ref의 영역 안에 있으면 setIsOpen(false)를 실행하지 않아 창이 닫히지 않게 되고, 영역 밖에 있으면 닫히게 됩니다!!

title={theme.title}
value={theme.value}
colors={theme.colors}
{...theme}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍👍👍👍👍👍

@@ -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;
Copy link
Contributor

@xxxjinn xxxjinn Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사소한 부분이지만 실제 setCustomTheme 함수의 매개변수는 color라고 되어있는 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setCustomTheme() 함수를 여러 군데에서 이름만 동일하게 사용하다보니 헷갈려 이런 문제가 생기네요 ... !

어느 부분에서 사용되는 함수인지 명시적으로 사용해야겠습니다 ............
찾아주셔서 감사합니다 !!!!!!!!!!! 👍👍👍👍👍👍

Comment on lines +20 to +25
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> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(궁금) async를 왜 달아주셨는지 궁금합니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 트러블슈팅 하다가 configuration 가져오는 부분이 비동기인가 싶어서 추가했던 것 같습니다 .. !
지금 확인해보니 async처리 하지 않아도 잘 동작하네요 ㅎㅎ ...

다음 이슈에서 수정하도록 하겠습니다 !!

Copy link
Contributor

@ytaek ytaek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

view랑 vscode까지 다 작업하시느라 고생많으셨습니다.
저장하고 나니 theme 기능이 잘 동작하는 느낌이 더 팍팍나네요 👍👍👍

(사소)
전반적으로 customThemetheme이 같이 사용된 것 같은데,
혹시 다른 의미가 있는게 아니라면 하나로 통일시켜도 좋을 것 같습니다.

@taboowiths
Copy link
Contributor Author

taboowiths commented Oct 10, 2024

view랑 vscode까지 다 작업하시느라 고생많으셨습니다. 저장하고 나니 theme 기능이 잘 동작하는 느낌이 더 팍팍나네요 👍👍👍

(사소) 전반적으로 customThemetheme이 같이 사용된 것 같은데, 혹시 다른 의미가 있는게 아니라면 하나로 통일시켜도 좋을 것 같습니다.

theme 이라는 용어가 현재 ThemeSelector와 관련된 로직에서만 쓰이는 것으로 판단되니, 간단하게 theme 으로 통일하는 것이 좋을 것 같습니다 .

다음 issue로 올리겠습니다 !!!

  • customTheme -> theme으로 용어 통일
  • 불필요한 비동기 제거
  • 함수 역할에 기반한 함수명으로 변경

@taboowiths taboowiths merged commit 8f28b4e into githru:main Oct 10, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants