From bf3b952f21d9b3b132698c9fd9dd598cac36fec5 Mon Sep 17 00:00:00 2001
From: ChaotiCryptidz
Date: Thu, 3 Mar 2022 14:27:34 +0000
Subject: [PATCH] add search bar to totp list
---
src/translations/en.js | 8 +--
src/translations/ru.js | 8 +--
src/ui/pages/Secrets/TOTP/TOTPList.tsx | 86 +++++++++++++++++++++-----
3 files changed, 76 insertions(+), 26 deletions(-)
diff --git a/src/translations/en.js b/src/translations/en.js
index a1db8f6..7678908 100644
--- a/src/translations/en.js
+++ b/src/translations/en.js
@@ -189,11 +189,9 @@ module.exports = {
kv_view_none_here_text: "You seem to have no secrets here, would you like to create one?",
kv_view_search_input_text: "Search",
- // TOTP View Page
- totp_view_title: "TOTP",
- totp_view_loading: "Loading TOTP Codes..",
- totp_view_empty: "You seem to have no TOTP codes here, would you like to create one?",
- totp_view_loading_box: "Loading..",
+ // TOTP List Page
+ totp_list_empty: "You seem to have no TOTP codes here, would you like to create one?",
+ totp_list_search_input_text: "Search",
// New TOTP Key Page
totp_new_title: "New TOTP Key",
diff --git a/src/translations/ru.js b/src/translations/ru.js
index 62c09e4..96f19c2 100644
--- a/src/translations/ru.js
+++ b/src/translations/ru.js
@@ -163,11 +163,9 @@ module.exports = {
kv_view_none_here_text: "У вас на данный момент нет тайных данных. Хотите ли вы их создать?",
kv_view_search_input_text: "Поиск",
- // TOTP View Page
- totp_view_title: "TOTP",
- totp_view_loading: "Загрузка кодов TOTP..",
- totp_view_empty: "У вас на данный момент нет кодов TOTP. Хотите ли вы их создать?",
- totp_view_loading_box: "Загрузка..",
+ // TOTP New Page
+ totp_list_empty: "У вас на данный момент нет кодов TOTP. Хотите ли вы их создать?",
+ totp_list_search_input_text: "Поиск",
// New TOTP Key Page
totp_new_title: "Новый ключ TOTP",
diff --git a/src/ui/pages/Secrets/TOTP/TOTPList.tsx b/src/ui/pages/Secrets/TOTP/TOTPList.tsx
index da4b043..7977807 100644
--- a/src/ui/pages/Secrets/TOTP/TOTPList.tsx
+++ b/src/ui/pages/Secrets/TOTP/TOTPList.tsx
@@ -1,6 +1,6 @@
import { Button } from "../../../elements/Button";
import { CapabilitiesType } from "../../../../api/types/capabilities";
-import { Component, JSX } from "preact";
+import { Component, createRef, JSX } from "preact";
import { CopyableInputBox } from "../../../elements/CopyableInputBox";
import { DefaultPageProps } from "../../../../types/DefaultPageProps";
import { Grid, GridSizes } from "../../../elements/Grid";
@@ -14,7 +14,9 @@ import {
} from "../../pageLinks";
import { removeDoubleSlash } from "../../../../utils";
import { sendErrorNotification } from "../../../elements/ErrorMessage";
-import i18next from "i18next";
+import i18next, { t } from "i18next";
+import { Margin } from "../../../elements/Margin";
+import { TextInput } from "../../../elements/forms/TextInput";
type TOTPGridItemProps = DefaultPageProps & {
baseMount: string;
@@ -72,6 +74,70 @@ type TOTPItem = {
canDelete: boolean;
};
+type TOTPListViewProps = DefaultPageProps & {
+ totpItems: TOTPItem[];
+}
+
+type TOTPListViewState = {
+ searchQuery: string;
+}
+
+export class TOTPListView extends Component {
+ constructor() {
+ super();
+ this.state = {
+ searchQuery: ""
+ };
+ }
+
+ searchBarRef = createRef();
+
+ componentDidMount(): void {
+ this.setState({
+ searchQuery: ""
+ });
+ }
+
+ render() {
+ if (this.props.totpItems.length == 0) {
+ return {i18next.t("totp_list_empty")}
+ }
+
+ return (
+ <>
+
+ {
+ this.setState({
+ searchQuery: this.searchBarRef.current.value,
+ });
+ }}
+ />
+
+
+ {this.props.totpItems.map((totpItem) => {
+ if (this.state.searchQuery.length > 0) {
+ if (!totpItem.totpKey.includes(this.state.searchQuery)) {
+ return;
+ }
+ }
+ return (
+
+ );
+ })}
+ >
+ )
+ }
+}
+
+
type TOTPListState = {
capabilities?: CapabilitiesType;
totpItems: TOTPItem[];
@@ -80,11 +146,9 @@ type TOTPListState = {
export class TOTPList extends Component {
constructor() {
super();
- this.refresher = undefined;
this.state = { capabilities: null, totpItems: [] };
}
- refresher: number;
async doApiFetches() {
const api = this.props.api;
@@ -167,18 +231,8 @@ export class TOTPList extends Component {
/>
)}
-
- {(() => {
- if (this.state.totpItems.length == 0) {
- return
{i18next.t("totp_view_empty")}
;
- } else {
- return this.state.totpItems.map((totpItem) => {
- return (
-
- );
- });
- }
- })()}
+
+
>