From 7f26deed45a81fe7b185b161132f935f89c7e619 Mon Sep 17 00:00:00 2001 From: rcmerci Date: Tue, 12 Mar 2024 16:53:00 +0800 Subject: [PATCH] enhance: display username too (#11105) * enhance: display username too * enhance(ui): polish the user item from the global dots menu --------- Co-authored-by: charlie --- src/main/frontend/components/header.cljs | 22 ++++++++++++++-------- src/main/frontend/handler/user.cljs | 6 ++++++ src/resources/dicts/de.edn | 1 - src/resources/dicts/en.edn | 1 - src/resources/dicts/es.edn | 1 - src/resources/dicts/fa.edn | 1 - src/resources/dicts/fr.edn | 1 - src/resources/dicts/id.edn | 1 - src/resources/dicts/it.edn | 1 - src/resources/dicts/ja.edn | 1 - src/resources/dicts/nb-no.edn | 1 - src/resources/dicts/pt-br.edn | 1 - src/resources/dicts/ru.edn | 1 - src/resources/dicts/sk.edn | 1 - src/resources/dicts/tr.edn | 1 - 15 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/main/frontend/components/header.cljs b/src/main/frontend/components/header.cljs index fd5346e387b..e343d11e9ce 100644 --- a/src/main/frontend/components/header.cljs +++ b/src/main/frontend/components/header.cljs @@ -84,7 +84,8 @@ [{:keys [current-repo t]}] (let [page-menu (page-menu/page-menu nil) page-menu-and-hr (when (seq page-menu) - (concat page-menu [{:hr true}]))] + (concat page-menu [{:hr true}])) + login? (and (state/sub :auth/id-token) (user-handler/logged-in?))] (ui/dropdown-with-links (fn [{:keys [toggle-fn]}] [:button.button.icon.toolbar-dots-btn @@ -136,13 +137,18 @@ :options {:on-click #(state/toggle-theme!)} :icon (ui/icon "bulb")}) - (when (and (state/sub :auth/id-token) (user-handler/logged-in?)) - {:title (t :logout-user (user-handler/email)) - :options {:on-click #(user-handler/logout)} - :icon (ui/icon "logout")})] - (concat page-menu-and-hr) - (remove nil?)) - {}))) + (when login? {:hr true}) + (when login? + {:item [:span.flex.flex-col.relative.group.pt-1 + [:b.leading-none (user-handler/username)] + [:small.opacity-70 (user-handler/email)] + [:i.absolute.opacity-0.group-hover:opacity-100.text-red-rx-09 + {:class "right-1 top-3" :title (t :logout)} + (ui/icon "logout")]] + :options {:on-click #(user-handler/logout)}})] + (concat page-menu-and-hr) + (remove nil?)) + {}))) (rum/defc back-and-forward < {:key-fn #(identity "nav-history-buttons")} diff --git a/src/main/frontend/handler/user.cljs b/src/main/frontend/handler/user.cljs index c8aab739c3b..7484c192e3b 100644 --- a/src/main/frontend/handler/user.cljs +++ b/src/main/frontend/handler/user.cljs @@ -70,6 +70,12 @@ parse-jwt :email)) +(defn username [] + (some-> + (state/get-auth-id-token) + parse-jwt + :cognito:username)) + (defn user-uuid [] (some-> (state/get-auth-id-token) diff --git a/src/resources/dicts/de.edn b/src/resources/dicts/de.edn index 8924fcef1b6..06c2c255f7e 100644 --- a/src/resources/dicts/de.edn +++ b/src/resources/dicts/de.edn @@ -38,7 +38,6 @@ :loading-files "Dateien laden" :login "Einloggen" :logout "Ausloggen" - :logout-user "Ausloggen ({1})" :new-graph "Neuen Graphen hinzufügen" :new-page "Neue Seite:" :open-a-directory "Öffne ein lokales Verzeichnis" diff --git a/src/resources/dicts/en.edn b/src/resources/dicts/en.edn index 09b66166356..22884ea0e1d 100644 --- a/src/resources/dicts/en.edn +++ b/src/resources/dicts/en.edn @@ -550,7 +550,6 @@ :loading-files "Loading files" :login "Login" :logout "Logout" - :logout-user "Logout ({1})" :download "Download" :language "Language" :remove-background "Remove background" diff --git a/src/resources/dicts/es.edn b/src/resources/dicts/es.edn index 7bd620dc495..a415005fc0c 100644 --- a/src/resources/dicts/es.edn +++ b/src/resources/dicts/es.edn @@ -41,7 +41,6 @@ :loading-files "Cargando archivos" :login "Iniciar sesión" :logout "Cerrar sesión" - :logout-user "Cerrar sesión ({1})" :new-graph "Añadir nuevo grafo" :new-page "Nueva página:" :open-a-directory "Abrir un directorio local" diff --git a/src/resources/dicts/fa.edn b/src/resources/dicts/fa.edn index 972a10a9c28..97cb7cecd3e 100644 --- a/src/resources/dicts/fa.edn +++ b/src/resources/dicts/fa.edn @@ -394,7 +394,6 @@ :loading-files "بار کردن پرونده‌ها" :login "ورود" :logout "خروج" - :logout-user "خروج ({1})" :download "بارگیری" :language "زبان" :remove-background "حذف پس‌زمینه" diff --git a/src/resources/dicts/fr.edn b/src/resources/dicts/fr.edn index 3e244494b6b..1a9ded5c8c3 100644 --- a/src/resources/dicts/fr.edn +++ b/src/resources/dicts/fr.edn @@ -437,7 +437,6 @@ :export-save-to-file "Enregistrer le fichier" :export-transparent-background "Arrière-plan transparent" :home "Accueil" - :logout-user "Déconnecter {1}" :new-page "Nouvelle page :" :remove-orphaned-pages "Supprimer les pages orphelines ?" :toggle-theme "Changer le thème" diff --git a/src/resources/dicts/id.edn b/src/resources/dicts/id.edn index d19fb76cda9..127611f333b 100644 --- a/src/resources/dicts/id.edn +++ b/src/resources/dicts/id.edn @@ -517,7 +517,6 @@ :loading-files "Memuat berkas" :login "Masuk" :logout "Keluar" - :logout-user "Keluar ({1})" :download "Unduh" :language "Bahasa" :remove-background "Hapus latar belakang" diff --git a/src/resources/dicts/it.edn b/src/resources/dicts/it.edn index c39c1d207fb..024b456d710 100644 --- a/src/resources/dicts/it.edn +++ b/src/resources/dicts/it.edn @@ -330,7 +330,6 @@ :host "Host" :importing "Importando" :loading "Caricamento..." - :logout-user "Disconnettiti ({1})" :new-page "Nuova pagina:" :remove-heading "Rimuovi titolo" :remove-orphaned-pages "Rimuovere le pagine orfane?" diff --git a/src/resources/dicts/ja.edn b/src/resources/dicts/ja.edn index 0a673bd9100..28f806a0b27 100644 --- a/src/resources/dicts/ja.edn +++ b/src/resources/dicts/ja.edn @@ -529,7 +529,6 @@ :loading-files "ファイルロード中" :login "ログイン" :logout "ログアウト" - :logout-user "ログアウト ({1})" :download "ダウンロード" :language "言語" :remove-background "背景を消去" diff --git a/src/resources/dicts/nb-no.edn b/src/resources/dicts/nb-no.edn index a497453f534..d3398966ede 100644 --- a/src/resources/dicts/nb-no.edn +++ b/src/resources/dicts/nb-no.edn @@ -615,7 +615,6 @@ :window/restore "Gjenopprett" :loading "Laster..." - :logout-user "Logg av ({1})" :new-page "Ny side:" :remove-orphaned-pages "Fjern foreldreløse sider?" :bug-report/inspector-page-btn-back "Gå tilbake" diff --git a/src/resources/dicts/pt-br.edn b/src/resources/dicts/pt-br.edn index 58282369dc6..f8cfbc8758a 100644 --- a/src/resources/dicts/pt-br.edn +++ b/src/resources/dicts/pt-br.edn @@ -519,7 +519,6 @@ :loading-files "Carregando arquivos" :login "Entrar" :logout "Sair" - :logout-user "Sair ({1})" :download "Baixar" :language "Idioma" :remove-background "Remover fundo" diff --git a/src/resources/dicts/ru.edn b/src/resources/dicts/ru.edn index 2c37e6df4bd..ef89f1e477f 100644 --- a/src/resources/dicts/ru.edn +++ b/src/resources/dicts/ru.edn @@ -382,7 +382,6 @@ :loading-files "Загрузка файлов" :login "Вход" :logout "Выйти" - :logout-user "Выйти ({1})" :download "Скачать" :language "Язык" :remove-background "Удалить фон" diff --git a/src/resources/dicts/sk.edn b/src/resources/dicts/sk.edn index b8473c98904..f6522f7de24 100644 --- a/src/resources/dicts/sk.edn +++ b/src/resources/dicts/sk.edn @@ -521,7 +521,6 @@ :loading-files "Načítavajú sa súbory" :login "Prihlásiť sa" :logout "Odhlásiť sa" - :logout-user "Odhlásiť ({1})" :download "Stiahnuť" :language "Jazyk" :remove-background "Odstrániť pozadie" diff --git a/src/resources/dicts/tr.edn b/src/resources/dicts/tr.edn index dde521f3253..1870c4cbc63 100644 --- a/src/resources/dicts/tr.edn +++ b/src/resources/dicts/tr.edn @@ -550,7 +550,6 @@ :loading-files "Dosyalar yükleniyor" :login "Oturum aç" :logout "Oturumu kapat" - :logout-user "Oturumu kapat ({1})" :download "İndir" :language "Dil" :remove-background "Arka planı kaldır"