From 6c0dd714ce871d34477a7fcc69690ccd9d6df1ff Mon Sep 17 00:00:00 2001 From: Roj Date: Wed, 20 Mar 2024 23:31:25 +0300 Subject: [PATCH] [Session String Generator] Remember generated strings --- islands/Error.tsx | 29 ++++++--- islands/SessionStringGenerator.tsx | 98 +++++++++++++++++++++++++++--- lib/session_string.ts | 7 +++ lib/session_string_generator_db.ts | 25 ++++++++ 4 files changed, 142 insertions(+), 17 deletions(-) create mode 100644 lib/session_string_generator_db.ts diff --git a/islands/Error.tsx b/islands/Error.tsx index 50ce26f..116a597 100644 --- a/islands/Error.tsx +++ b/islands/Error.tsx @@ -5,6 +5,13 @@ import { IS_BROWSER } from "$fresh/runtime.ts"; import { Button } from "../components/Button.tsx"; export const error = signal(null); +export const showDismissButton = signal(true); + +IS_BROWSER && effect(() => { + if (error.value == null) { + showDismissButton.value = true; + } +}); IS_BROWSER && effect(() => { if (error.value != null) { @@ -39,14 +46,20 @@ export function Error({ onDismiss }: { onDismiss?: () => void }) { >
-

- {error.value} -

- + {typeof error.value == "string" + ? ( +

+ {error.value} +

+ ) + : error.value} + {showDismissButton.value && ( + + )}
diff --git a/islands/SessionStringGenerator.tsx b/islands/SessionStringGenerator.tsx index 3654330..73c71ee 100644 --- a/islands/SessionStringGenerator.tsx +++ b/islands/SessionStringGenerator.tsx @@ -5,11 +5,12 @@ import { Caption } from "../components/Caption.tsx"; import { Input } from "../components/Input.tsx"; import { Label } from "../components/Label.tsx"; import { Select } from "../components/Select.tsx"; -import { Error, error } from "./Error.tsx"; +import { Error, error, showDismissButton } from "./Error.tsx"; import { getDcIps } from "mtkruto/transport/2_transport_provider.ts"; import { serializeGramjs, serializeMtcute, + serializeMtkruto, serializePyrogram, serializeTelethon, } from "../lib/session_string.ts"; @@ -18,6 +19,9 @@ import { Spinner2 } from "../components/icons/Spinner.tsx"; import { storedString } from "../lib/stored_signals.tsx"; import { getHashSignal } from "../lib/hash_signal.ts"; import { IS_BROWSER } from "$fresh/runtime.ts"; +import { Db, SessionString } from "../lib/session_string_generator_db.ts"; + +const db = new Db(); const hash = getHashSignal(); const sessionString = signal(""); @@ -166,11 +170,37 @@ export function SessionStringGenerator() {