From d0c9f93ebbac1d16ba671abf3c476799849512bf Mon Sep 17 00:00:00 2001 From: reya Date: Tue, 20 Feb 2024 10:26:19 +0700 Subject: [PATCH] wip: small updates --- apps/desktop2/package.json | 86 +++++++++---------- apps/desktop2/src/app.tsx | 20 +++-- apps/desktop2/src/routes/__root.tsx | 3 + apps/desktop2/src/routes/app.tsx | 9 +- apps/desktop2/src/routes/app/home.lazy.tsx | 7 +- .../src/routes/auth/create/index.lazy.tsx | 4 +- .../src/routes/auth/create/self.lazy.tsx | 70 ++++++++------- apps/desktop2/src/routes/auth/import.lazy.tsx | 81 +++++++++-------- apps/desktop2/src/routes/index.tsx | 2 +- apps/desktop2/src/routes/landing/index.tsx | 11 ++- apps/desktop2/src/routes/select.tsx | 5 -- packages/ark/src/ark.ts | 17 ++-- pnpm-lock.yaml | 6 -- src-tauri/locales/en.json | 1 + 14 files changed, 165 insertions(+), 157 deletions(-) delete mode 100644 apps/desktop2/src/routes/select.tsx diff --git a/apps/desktop2/package.json b/apps/desktop2/package.json index c8426162..7a9ee71b 100644 --- a/apps/desktop2/package.json +++ b/apps/desktop2/package.json @@ -1,46 +1,44 @@ { - "name": "@lume/desktop2", - "private": true, - "version": "0.0.0", - "type": "module", - "scripts": { - "dev": "vite", - "build": "tsc && vite build", - "preview": "vite preview" - }, - "dependencies": { - "@lume/ark": "workspace:^", - "@lume/icons": "workspace:^", - "@lume/storage": "workspace:^", - "@lume/ui": "workspace:^", - "@lume/utils": "workspace:^", - "@radix-ui/react-checkbox": "^1.0.4", - "@tanstack/react-query": "^5.20.5", - "@tanstack/react-router": "^1.16.2", - "i18next": "^23.8.2", - "i18next-resources-to-backend": "^1.2.0", - "jotai": "^2.6.4", - "react": "^18.2.0", - "react-dom": "^18.2.0", - "react-i18next": "^14.0.5", - "sonner": "^1.4.0", - "virtua": "^0.27.0" - }, - "devDependencies": { - "@lume/tailwindcss": "workspace:^", - "@lume/tsconfig": "workspace:^", - "@lume/types": "workspace:^", - "@tanstack/router-devtools": "^1.16.2", - "@tanstack/router-vite-plugin": "^1.16.3", - "@types/react": "^18.2.55", - "@types/react-dom": "^18.2.19", - "@vitejs/plugin-react-swc": "^3.6.0", - "autoprefixer": "^10.4.17", - "postcss": "^8.4.35", - "tailwindcss": "^3.4.1", - "typescript": "^5.3.3", - "vite": "^5.1.2", - "vite-plugin-top-level-await": "^1.4.1", - "vite-tsconfig-paths": "^4.3.1" - } + "name": "@lume/desktop2", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc && vite build", + "preview": "vite preview" + }, + "dependencies": { + "@lume/ark": "workspace:^", + "@lume/icons": "workspace:^", + "@lume/ui": "workspace:^", + "@lume/utils": "workspace:^", + "@radix-ui/react-checkbox": "^1.0.4", + "@tanstack/react-query": "^5.20.5", + "@tanstack/react-router": "^1.16.2", + "i18next": "^23.8.2", + "i18next-resources-to-backend": "^1.2.0", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "react-i18next": "^14.0.5", + "sonner": "^1.4.0", + "virtua": "^0.27.0" + }, + "devDependencies": { + "@lume/tailwindcss": "workspace:^", + "@lume/tsconfig": "workspace:^", + "@lume/types": "workspace:^", + "@tanstack/router-devtools": "^1.16.2", + "@tanstack/router-vite-plugin": "^1.16.3", + "@types/react": "^18.2.55", + "@types/react-dom": "^18.2.19", + "@vitejs/plugin-react-swc": "^3.6.0", + "autoprefixer": "^10.4.17", + "postcss": "^8.4.35", + "tailwindcss": "^3.4.1", + "typescript": "^5.3.3", + "vite": "^5.1.2", + "vite-plugin-top-level-await": "^1.4.1", + "vite-tsconfig-paths": "^4.3.1" + } } diff --git a/apps/desktop2/src/app.tsx b/apps/desktop2/src/app.tsx index f0853b8a..8a483ee6 100644 --- a/apps/desktop2/src/app.tsx +++ b/apps/desktop2/src/app.tsx @@ -1,4 +1,3 @@ -import { StorageProvider } from "@lume/storage"; import { useArk } from "@lume/ark"; import { ArkProvider } from "./ark"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; @@ -8,17 +7,21 @@ import ReactDOM from "react-dom/client"; import { I18nextProvider } from "react-i18next"; import "./app.css"; import i18n from "./locale"; - -// Import the generated route tree -import { routeTree } from "./router.gen"; +import { Toaster } from "sonner"; +import { locale, platform } from "@tauri-apps/plugin-os"; +import { routeTree } from "./router.gen"; // auto generated file const queryClient = new QueryClient(); +const platformName = await platform(); +const osLocale = (await locale()).slice(0, 2); // Set up a Router instance const router = createRouter({ routeTree, context: { ark: undefined!, + platform: platformName, + locale: osLocale, queryClient, }, }); @@ -51,11 +54,10 @@ if (!rootElement.innerHTML) { root.render( - - - - - + + + + , ); diff --git a/apps/desktop2/src/routes/__root.tsx b/apps/desktop2/src/routes/__root.tsx index e47b23e2..649e9ad0 100644 --- a/apps/desktop2/src/routes/__root.tsx +++ b/apps/desktop2/src/routes/__root.tsx @@ -6,10 +6,13 @@ import { } from "@tanstack/react-router"; import { type Ark } from "@lume/ark"; import { type QueryClient } from "@tanstack/react-query"; +import { type Platform } from "@tauri-apps/plugin-os"; interface RouterContext { ark: Ark; queryClient: QueryClient; + platform: Platform; + locale: string; } export const Route = createRootRouteWithContext()({ diff --git a/apps/desktop2/src/routes/app.tsx b/apps/desktop2/src/routes/app.tsx index 22088838..45b74937 100644 --- a/apps/desktop2/src/routes/app.tsx +++ b/apps/desktop2/src/routes/app.tsx @@ -6,7 +6,6 @@ import { SpaceFilledIcon, SpaceIcon, } from "@lume/icons"; -import { useStorage } from "@lume/storage"; import { Link } from "@tanstack/react-router"; import { Outlet, createFileRoute } from "@tanstack/react-router"; import { cn } from "@lume/utils"; @@ -17,15 +16,15 @@ export const Route = createFileRoute("/app")({ }); function App() { - const storage = useStorage(); + const context = Route.useRouteContext(); return (
-
+
diff --git a/apps/desktop2/src/routes/app/home.lazy.tsx b/apps/desktop2/src/routes/app/home.lazy.tsx index 051b8212..e654d418 100644 --- a/apps/desktop2/src/routes/app/home.lazy.tsx +++ b/apps/desktop2/src/routes/app/home.lazy.tsx @@ -18,7 +18,12 @@ function Home() { queryKey: ["timeline"], initialPageParam: 0, queryFn: async ({ pageParam }: { pageParam: number }) => { - const events = await ark.get_text_events(FETCH_LIMIT, pageParam, true); + const events = await ark.get_text_events( + FETCH_LIMIT, + pageParam, + undefined, + true, + ); return events; }, getNextPageParam: (lastPage) => { diff --git a/apps/desktop2/src/routes/auth/create/index.lazy.tsx b/apps/desktop2/src/routes/auth/create/index.lazy.tsx index cfdad8e0..fed2597e 100644 --- a/apps/desktop2/src/routes/auth/create/index.lazy.tsx +++ b/apps/desktop2/src/routes/auth/create/index.lazy.tsx @@ -28,7 +28,7 @@ function Screen() { return (
-
+

{t("signup.title")}

{t("signup.subtitle")} @@ -69,7 +69,7 @@ function Screen() {

-
- - setConfirm((state) => ({ ...state, c2: !state.c2 })) - } - className="flex size-7 appearance-none items-center justify-center rounded-lg bg-neutral-100 outline-none dark:bg-neutral-900" - id="confirm2" - > - - - - - -
+
+ + setConfirm((state) => ({ ...state, c2: !state.c2 })) + } + className="flex size-7 appearance-none items-center justify-center rounded-lg bg-neutral-100 outline-none dark:bg-neutral-900" + id="confirm2" + > + + + + + +
+ {isNip05 || isNip49 ? ( +
+ + setPassword(e.target.value)} + className="h-12 w-full resize-none rounded-xl border-transparent bg-neutral-100 pl-3 pr-10 placeholder:text-neutral-600 focus:border-blue-500 focus:ring focus:ring-blue-100 dark:bg-neutral-900 dark:focus:ring-blue-900" + /> +
+ ) : null}
{loading ? ( - + ) : ( <> {ark.accounts.map((account) => ( diff --git a/apps/desktop2/src/routes/landing/index.tsx b/apps/desktop2/src/routes/landing/index.tsx index 722f4ddf..4ad9f6c4 100644 --- a/apps/desktop2/src/routes/landing/index.tsx +++ b/apps/desktop2/src/routes/landing/index.tsx @@ -1,4 +1,3 @@ -import { useStorage } from "@lume/storage"; import { Link, createFileRoute } from "@tanstack/react-router"; import { useTranslation } from "react-i18next"; @@ -7,7 +6,7 @@ export const Route = createFileRoute("/landing/")({ }); function Screen() { - const storage = useStorage(); + const context = Route.useRouteContext(); const { t } = useTranslation(); return ( @@ -17,8 +16,8 @@ function Screen() {
lume @@ -29,13 +28,13 @@ function Screen() {
{t("welcome.signup")} {t("welcome.login")} diff --git a/apps/desktop2/src/routes/select.tsx b/apps/desktop2/src/routes/select.tsx deleted file mode 100644 index 8e785a4b..00000000 --- a/apps/desktop2/src/routes/select.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import { createFileRoute } from '@tanstack/react-router' - -export const Route = createFileRoute('/select')({ - component: () =>
Hello /select!
-}) \ No newline at end of file diff --git a/packages/ark/src/ark.ts b/packages/ark/src/ark.ts index ba5d79e4..bd33cb1e 100644 --- a/packages/ark/src/ark.ts +++ b/packages/ark/src/ark.ts @@ -13,7 +13,7 @@ export class Ark { public accounts: Array; constructor() { - this.account = { npub: "" }; + this.account = { npub: "", contacts: [] }; } public async get_all_accounts() { @@ -68,12 +68,12 @@ export class Ark { if (cmd) { await invoke("update_signer", { nsec: keys.nsec }); + const contacts: string[] = await invoke("get_contact_list"); this.account.npub = keys.npub; - - return true; + this.account.contacts = contacts; } - return false; + return cmd; } catch (e) { console.error(String(e)); } @@ -106,17 +106,24 @@ export class Ark { } } - public async get_text_events(limit: number, asOf?: number, dedup?: boolean) { + public async get_text_events( + limit: number, + asOf?: number, + authors?: string[], + dedup?: boolean, + ) { try { let until: string = undefined; if (asOf && asOf > 0) until = asOf.toString(); const seenIds = new Set(); const dedupQueue = new Set(); + const contact_list = authors ?? this.account.contacts; const nostrEvents: Event[] = await invoke("get_text_events", { limit, until, + contact_list, }); if (dedup) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 80323e1c..0e8dffd8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -66,9 +66,6 @@ importers: '@lume/icons': specifier: workspace:^ version: link:../../packages/icons - '@lume/storage': - specifier: workspace:^ - version: link:../../packages/storage '@lume/ui': specifier: workspace:^ version: link:../../packages/ui @@ -90,9 +87,6 @@ importers: i18next-resources-to-backend: specifier: ^1.2.0 version: 1.2.0 - jotai: - specifier: ^2.6.4 - version: 2.6.4(@types/react@18.2.55)(react@18.2.0) react: specifier: ^18.2.0 version: 18.2.0 diff --git a/src-tauri/locales/en.json b/src-tauri/locales/en.json index 9a494e0c..b81a4df8 100644 --- a/src-tauri/locales/en.json +++ b/src-tauri/locales/en.json @@ -105,6 +105,7 @@ }, "login": { "title": "Welcome back, anon!", + "subtitle": "We're so excited to see you again!", "footer": "Lume will put your Private Key in Secure Storage depended on your OS Platform. It will be secured by Password or Biometric ID", "loginWithAddress": "Login with Nostr Address", "loginWithBunker": "Login with nsecBunker",