From 25d96d6233c12be9fd1050a885f04ce844e07da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hampus=20Sj=C3=B6berg?= Date: Tue, 30 May 2023 01:08:58 +0200 Subject: [PATCH] settings: Add the ability to see all toast notifications in current session --- locales/en.json | 4 ++ src/utils/index.ts | 10 +++- src/windows/Settings/Settings.tsx | 6 +++ src/windows/Settings/ToastLog.tsx | 82 +++++++++++++++++++++++++++++++ src/windows/Settings/index.tsx | 3 ++ 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/windows/Settings/ToastLog.tsx diff --git a/locales/en.json b/locales/en.json index 84aa3927d..aea174aee 100644 --- a/locales/en.json +++ b/locales/en.json @@ -897,6 +897,10 @@ "title": "Show startup info notifications", "subtitle": "" }, + "showNotifications": { + "title": "Show notifications for this session", + "subtitle": "" + }, "helpCencer": { "title": "LndMobile help center", "subtitle": "" diff --git a/src/utils/index.ts b/src/utils/index.ts index d6e93df9e..ffb8066b7 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -74,9 +74,17 @@ export const hexToUint8Array = (hexString: string) => { return new Uint8Array(hexString.match(/.{1,2}/g)!.map(byte => parseInt(byte, 16))); }; +export const toastEntries: string[] = [] + +// TODO: maybe make array observable in order trigger re-render for hook +export function useGetToastEntries(): string[] { + return toastEntries; +} + export const toast = (message: string, period = 8000, type: "danger" | "success" | "warning" = "success", button?: string) => { + toastEntries.push(message); + console.log(message); try { - console.log(message); if (AppState.currentState === "active") { Toast.show({ duration: period, diff --git a/src/windows/Settings/Settings.tsx b/src/windows/Settings/Settings.tsx index 8807094af..275628663 100644 --- a/src/windows/Settings/Settings.tsx +++ b/src/windows/Settings/Settings.tsx @@ -1555,6 +1555,12 @@ ${t("experimental.tor.disabled.msg2")}`; {t("debug.startup.title")} + navigation.navigate("ToastLog")}> + + + {t("debug.showNotifications.title")} + + diff --git a/src/windows/Settings/ToastLog.tsx b/src/windows/Settings/ToastLog.tsx new file mode 100644 index 000000000..0b316b114 --- /dev/null +++ b/src/windows/Settings/ToastLog.tsx @@ -0,0 +1,82 @@ +import React, { useLayoutEffect } from "react"; +import { FlatList, StyleSheet } from "react-native"; +import { Body, Card, CardItem, Icon, Row, Text } from "native-base"; +import { StackNavigationProp } from "@react-navigation/stack"; +import { RouteProp } from "@react-navigation/native"; +import Clipboard from "@react-native-community/clipboard"; + +import Container from "../../components/Container"; +import { NavigationButton } from "../../components/NavigationButton"; +import { SettingsStackParamList } from "./index"; +import { toast, useGetToastEntries } from "../../utils"; +import { fontFactorNormalized } from "../../utils/scale"; + +import { useTranslation } from "react-i18next"; +import { namespaces } from "../../i18n/i18n.constants"; + + +export interface ISelectListProps { + navigation: StackNavigationProp; + route: RouteProp; +} + +export default function({ navigation }: ISelectListProps) { + const t = useTranslation(namespaces.settings.lightningPeers).t; + const toastEntries = useGetToastEntries(); + + useLayoutEffect(() => { + navigation.setOptions({ + headerTitle: t("layout.title"), + headerShown: true, + headerRight: () => { + return ( + + + + ) + } + }); + }, [navigation]); + + const onCopyToastMessage = (i: number) => { + console.log(toastEntries); + Clipboard.setString(toastEntries[i] ?? ""); + toast("Copied to clipboard"); + } + + const onPressCopyAllToasts = () => { + Clipboard.setString(toastEntries.join("\n") ?? ""); + toast("Copied to clipboard"); + } + + return ( + + ( + + + + + {toast} + + onCopyToastMessage(index)} /> + + + + + + )} + keyExtractor={(toast, i) => toast + i} + /> + + ) +} + +const style = StyleSheet.create({ + icon: { + fontSize: 18 * fontFactorNormalized, + }, +}); diff --git a/src/windows/Settings/index.tsx b/src/windows/Settings/index.tsx index 0b66bf9ba..c310d4fa2 100644 --- a/src/windows/Settings/index.tsx +++ b/src/windows/Settings/index.tsx @@ -18,6 +18,7 @@ import LightningPeers from "./LightningPeers"; import ConnectToLightningPeer from "./ConnectToLightningPeer"; import LndLog from "./LndLog"; import DunderDoctor from "./DunderDoctor"; +import ToastLog from "./ToastLog"; const Stack = createStackNavigator(); @@ -41,6 +42,7 @@ export type SettingsStackParamList = { ChannelProvider: ISelectListNavigationProps; LndLog: undefined; DunderDoctor: undefined; + ToastLog: undefined; } export default function SettingsIndex() { @@ -73,6 +75,7 @@ export default function SettingsIndex() { + ); }