Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

chore: merge shared code between ui and app#482

Merged
OGPoyraz merged 2 commits intomainfrom
chore/merge-shared-code-between-ui-and-app
Feb 6, 2023
Merged

chore: merge shared code between ui and app#482
OGPoyraz merged 2 commits intomainfrom
chore/merge-shared-code-between-ui-and-app

Conversation

@OGPoyraz
Copy link
Copy Markdown
Member

@OGPoyraz OGPoyraz commented Feb 1, 2023

Overview

This PR aims to create a shared folder under src and merge the common code between UI and app.
Common code consists of:

  • Constants
    • Links
    • Locale indexes
    • Theme indexes
    • UI Routes
    • Metric constants for analytics (Not going to add them for now since topic is under progress)
  • Locales
    • locale jsons
    • locale helpers

@OGPoyraz OGPoyraz requested a review from a team February 1, 2023 12:15
@OGPoyraz OGPoyraz force-pushed the chore/merge-shared-code-between-ui-and-app branch from c093a9c to c462c48 Compare February 1, 2023 12:16
},
{
files: ['src/ui/**/*.{js,ts,jsx,tsx}'],
files: ['src/ui/**/*.{js,ts,jsx,tsx}', 'src/shared/**/*.{js,ts,jsx,tsx}'],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

shared folder to be linted with UI rules.

});

ipcMain.handle('set-language', (_event, language) => {
this.Translation.setLanguage(language);
Copy link
Copy Markdown
Member Author

@OGPoyraz OGPoyraz Feb 1, 2023

Choose a reason for hiding this comment

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

Language changes need to be synced with main process, reasons explained in Translation class below.

private language: string;

constructor() {
this.language = readPersistedSettingFromAppState({
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We read language from UI only once the user executes the app.

this.translate = memoize(this.translate);
}

public setLanguage(language: string) {
Copy link
Copy Markdown
Member Author

@OGPoyraz OGPoyraz Feb 1, 2023

Choose a reason for hiding this comment

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

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.

@OGPoyraz OGPoyraz force-pushed the chore/merge-shared-code-between-ui-and-app branch 12 times, most recently from 8c2e161 to e9b97b3 Compare February 1, 2023 14:25
- checkout_with_submodule
- restore_cache:
key: dependency-cache-v4-{{ checksum "yarn.lock" }}
key: dependency-cache-v6-{{ checksum "yarn.lock" }}
Copy link
Copy Markdown
Member Author

@OGPoyraz OGPoyraz Feb 1, 2023

Choose a reason for hiding this comment

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

v5 is accidentally cached wrong on my earlier commits

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are we changing the version here at all if we haven't changed the pipeline at all?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

My mistake fixed.

super();
this.metricsService = MetricsService;
this.UIState = UIState;
this.Translation = Translation;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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'),
Copy link
Copy Markdown
Member

@matthewwalsh0 matthewwalsh0 Feb 2, 2023

Choose a reason for hiding this comment

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

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.


export const updateCheck = async (): Promise<UpdateCheckResult | null> => {
export const updateCheck = async (
translate: (key: string) => any,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Make sense, then we would keep the same naming on both UI and app 👍

@@ -0,0 +1,5 @@
export const mmdSubmitTicket =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Capitals for all constants so URL_SUBMIT_TICKET and URL?

OS: 'os',
};

export const themeIndex = [
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Capitals here also.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed this and others

@OGPoyraz OGPoyraz force-pushed the chore/merge-shared-code-between-ui-and-app branch 3 times, most recently from b182002 to 036e663 Compare February 2, 2023 18:09
@socket-security
Copy link
Copy Markdown

socket-security bot commented Feb 3, 2023

Socket Security Pull Request Report

👍 No new dependency issues detected in pull request

Pull request report summary
Issue Status
Install scripts ✅ 0 issues
Native code ✅ 0 issues
Bin script confusion ✅ 0 issues
Bin script shell injection ✅ 0 issues
Unresolved require ✅ 0 issues
Invalid package.json ✅ 0 issues
HTTP dependency ✅ 0 issues
Git dependency ✅ 0 issues
Potential typo squat ✅ 0 issues
Known Malware ✅ 0 issues
Telemetry ✅ 0 issues
Protestware/Troll package ✅ 0 issues
Bot Commands

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore foo@1.0.0 bar@2.4.2

Powered by socket.dev

@OGPoyraz OGPoyraz force-pushed the chore/merge-shared-code-between-ui-and-app branch from 40043bf to 12f772d Compare February 3, 2023 08:15
@OGPoyraz OGPoyraz force-pushed the chore/merge-shared-code-between-ui-and-app branch 2 times, most recently from 80f18e0 to 63a76f4 Compare February 3, 2023 08:40
@OGPoyraz OGPoyraz force-pushed the chore/merge-shared-code-between-ui-and-app branch from 5e64573 to e72930f Compare February 6, 2023 10:15
@OGPoyraz OGPoyraz merged commit 941f526 into main Feb 6, 2023
@cryptotavares cryptotavares mentioned this pull request Mar 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants