chore: merge shared code between ui and app#482
Conversation
c093a9c to
c462c48
Compare
| }, | ||
| { | ||
| files: ['src/ui/**/*.{js,ts,jsx,tsx}'], | ||
| files: ['src/ui/**/*.{js,ts,jsx,tsx}', 'src/shared/**/*.{js,ts,jsx,tsx}'], |
There was a problem hiding this comment.
shared folder to be linted with UI rules.
packages/app/src/app/desktop-app.ts
Outdated
| }); | ||
|
|
||
| ipcMain.handle('set-language', (_event, language) => { | ||
| this.Translation.setLanguage(language); |
There was a problem hiding this comment.
Language changes need to be synced with main process, reasons explained in Translation class below.
| private language: string; | ||
|
|
||
| constructor() { | ||
| this.language = readPersistedSettingFromAppState({ |
There was a problem hiding this comment.
We read language from UI only once the user executes the app.
| this.translate = memoize(this.translate); | ||
| } | ||
|
|
||
| public setLanguage(language: string) { |
There was a problem hiding this comment.
Reading UI state is an expensive operation from performance perspective, this is why we are syncing language here.
So subsequent language changes in the UI will call electron bridge set-language method and eventually will trigger this method.
8c2e161 to
e9b97b3
Compare
.circleci/config.yml
Outdated
| - checkout_with_submodule | ||
| - restore_cache: | ||
| key: dependency-cache-v4-{{ checksum "yarn.lock" }} | ||
| key: dependency-cache-v6-{{ checksum "yarn.lock" }} |
There was a problem hiding this comment.
v5 is accidentally cached wrong on my earlier commits
There was a problem hiding this comment.
Why are we changing the version here at all if we haven't changed the pipeline at all?
packages/app/src/app/desktop-app.ts
Outdated
| super(); | ||
| this.metricsService = MetricsService; | ||
| this.UIState = UIState; | ||
| this.Translation = Translation; |
There was a problem hiding this comment.
As this is a singleton, we shouldn't need a property here as we can just use the import directly.
| private createShowMenuItem() { | ||
| return { | ||
| label: 'Show', | ||
| label: this.Translation.translate('show'), |
There was a problem hiding this comment.
For the sake of simplicity, we could remove the class from the Translation file, use a standard let for the language, and export the methods directly meaning we could import it here as t and make all these translations less verbose.
packages/app/src/app/update-check.ts
Outdated
|
|
||
| export const updateCheck = async (): Promise<UpdateCheckResult | null> => { | ||
| export const updateCheck = async ( | ||
| translate: (key: string) => any, |
There was a problem hiding this comment.
As the translations are so fundamental and not conceptually related, I'd recommend just importing the file directly here rather using a constructor argument, given it's a singleton so there is nothing unique about the instance.
| import { locales } from '../../shared/locales'; | ||
| import { LOCALE_KEYS } from '../../shared/constants/locale'; | ||
|
|
||
| class Translation { |
There was a problem hiding this comment.
As mentioned in the other comment, I'd not use a class here but just store the language in a let as that would allow the other files to import just the translate method with a compact alias like t.
There was a problem hiding this comment.
Make sense, then we would keep the same naming on both UI and app 👍
| @@ -0,0 +1,5 @@ | |||
| export const mmdSubmitTicket = | |||
There was a problem hiding this comment.
Capitals for all constants so URL_SUBMIT_TICKET and URL?
| OS: 'os', | ||
| }; | ||
|
|
||
| export const themeIndex = [ |
b182002 to
036e663
Compare
Socket Security Pull Request Report👍 No new dependency issues detected in pull request Pull request report summary
Bot CommandsTo ignore an alert, reply with a comment starting with Powered by socket.dev |
40043bf to
12f772d
Compare
80f18e0 to
63a76f4
Compare
5e64573 to
e72930f
Compare
Overview
This PR aims to create a
sharedfolder undersrcand merge the common code between UI and app.Common code consists of: