From f6144f9634482d6bd0ed88a31495c6c6c88add96 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Cuesta?=
 <1827495+alvaro-cuesta@users.noreply.github.com>
Date: Thu, 2 Jan 2025 20:38:40 +0100
Subject: feat: sync with local plugin status in store (#733)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* fix: useDeckyState proper type and safety

* refactor: plugin list

Avoids unneeded re-renders. See https://react.dev/learn/you-might-not-need-an-effect#caching-expensive-calculations

* feat: sync with local plugin status in store

Adds some QoL changes to the plugin store browser:

- Add ✓ icon to currently installed plugin version in version selector
- Change install button label depending on the install type that the
  button would trigger
- Adds icon to install button for clarity

The goal is to make it clear to the user what the current state of the
installed plugin is, and what would be the impact of installing the
selected version.

Resolves #360

* lint: prettier

* fix: add missing translations

* refactor: safer translation strings on install

Prefer using `t(...)` instead of `TranslationHelper` since it ensures
that the translation keys are not missing in the locale files when
running the `extractext` task.

By adding comments with `t(...)` calls, `i18next-parser` will generate
the strings as if they were present as literals in the code (see
https://github.com/i18next/i18next-parser#caveats).

This does _not_ suppress the warnings (since `i18next-parser` does not
have access to TS types, so it cannot infer template literals) but it at
least makes it less likely that a translation will be missed by mistake,
have typos, etc.
---
 frontend/src/utils/TranslationHelper.tsx | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)

(limited to 'frontend/src/utils/TranslationHelper.tsx')

diff --git a/frontend/src/utils/TranslationHelper.tsx b/frontend/src/utils/TranslationHelper.tsx
index 61bd24bf..4596060d 100644
--- a/frontend/src/utils/TranslationHelper.tsx
+++ b/frontend/src/utils/TranslationHelper.tsx
@@ -2,11 +2,9 @@ import { FC } from 'react';
 import { Translation } from 'react-i18next';
 
 import Logger from '../logger';
-import { InstallType } from '../plugin';
 
 export enum TranslationClass {
   PLUGIN_LOADER = 'PluginLoader',
-  PLUGIN_INSTALL_MODAL = 'PluginInstallModal',
   DEVELOPER = 'Developer',
 }
 
@@ -19,7 +17,7 @@ interface TranslationHelperProps {
 
 const logger = new Logger('TranslationHelper');
 
-const TranslationHelper: FC<TranslationHelperProps> = ({ transClass, transText, i18nArgs = null, installType = 0 }) => {
+const TranslationHelper: FC<TranslationHelperProps> = ({ transClass, transText, i18nArgs = null }) => {
   return (
     <Translation>
       {(t, {}) => {
@@ -28,21 +26,6 @@ const TranslationHelper: FC<TranslationHelperProps> = ({ transClass, transText,
             return i18nArgs
               ? t(TranslationClass.PLUGIN_LOADER + '.' + transText, i18nArgs)
               : t(TranslationClass.PLUGIN_LOADER + '.' + transText);
-          case TranslationClass.PLUGIN_INSTALL_MODAL:
-            switch (installType) {
-              case InstallType.INSTALL:
-                return i18nArgs
-                  ? t(TranslationClass.PLUGIN_INSTALL_MODAL + '.install.' + transText, i18nArgs)
-                  : t(TranslationClass.PLUGIN_INSTALL_MODAL + '.install.' + transText);
-              case InstallType.REINSTALL:
-                return i18nArgs
-                  ? t(TranslationClass.PLUGIN_INSTALL_MODAL + '.reinstall.' + transText, i18nArgs)
-                  : t(TranslationClass.PLUGIN_INSTALL_MODAL + '.reinstall.' + transText);
-              case InstallType.UPDATE:
-                return i18nArgs
-                  ? t(TranslationClass.PLUGIN_INSTALL_MODAL + '.update.' + transText, i18nArgs)
-                  : t(TranslationClass.PLUGIN_INSTALL_MODAL + '.update.' + transText);
-            }
           case TranslationClass.DEVELOPER:
             return i18nArgs
               ? t(TranslationClass.DEVELOPER + '.' + transText, i18nArgs)
-- 
cgit v1.2.3

