Compare commits
75 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32843018aa | ||
|
|
9df4835be3 | ||
|
|
8e39bca57c | ||
|
|
8d9ec0dcfd | ||
|
|
cdeb5afd28 | ||
|
|
1f3ba09cec | ||
|
|
4915b833e7 | ||
|
|
674e5f0339 | ||
|
|
11ed618a7f | ||
|
|
a2e3247432 | ||
|
|
09b3eeda99 | ||
|
|
700f3eb85f | ||
|
|
2f87ed8949 | ||
|
|
cb3c95b133 | ||
|
|
4f4e2f5ccd | ||
|
|
0e6fc65b08 | ||
|
|
876d351358 | ||
|
|
c80414a72d | ||
|
|
7cef6efa6f | ||
|
|
74ff49b8db | ||
|
|
2b50fc438f | ||
|
|
b339e842ca | ||
|
|
1d93f8cf6a | ||
|
|
236131087a | ||
|
|
a66770989b | ||
|
|
9ff74599eb | ||
|
|
c049fa8865 | ||
|
|
41b12746a7 | ||
|
|
50f90ddcc2 | ||
|
|
c9bc7b81dd | ||
|
|
18a9ba3fb0 | ||
|
|
413571ee7f | ||
|
|
17fe3bb1f6 | ||
|
|
0e5adb246f | ||
|
|
296136203a | ||
|
|
1bbfebc2b8 | ||
|
|
d84e97b0d4 | ||
|
|
824aa8fa28 | ||
|
|
2b34ef3b7a | ||
|
|
4fa8f40e6a | ||
|
|
c1bddeb6ed | ||
|
|
5c2bfa0ea3 | ||
|
|
60e93965ea | ||
|
|
380d1fb930 | ||
|
|
53aa13c8aa | ||
|
|
13f5190ba1 | ||
|
|
c590e290e0 | ||
|
|
cdf86a2613 | ||
|
|
8726e22b38 | ||
|
|
1206486016 | ||
|
|
11ad281d72 | ||
|
|
fe4bfa1699 | ||
|
|
c6a0636e8c | ||
|
|
d3db6492d9 | ||
|
|
8f8617d8f9 | ||
|
|
8e513404c3 | ||
|
|
5a6dd172b1 | ||
|
|
fa0d7cac31 | ||
|
|
432b2ae185 | ||
|
|
fb8a6581dd | ||
|
|
a4f221f868 | ||
|
|
602d012efe | ||
|
|
5bf816eba2 | ||
|
|
a33c9d3517 | ||
|
|
1553f5ced2 | ||
|
|
41901b2174 | ||
|
|
177e4c1ff7 | ||
|
|
10036500cb | ||
|
|
a1fa777f8c | ||
|
|
472925bb05 | ||
|
|
8eb11efb34 | ||
|
|
48066a4018 | ||
|
|
5c8850ea8f | ||
|
|
09aea3cff5 | ||
|
|
45c5a890b9 |
1
.github/workflows/main.yml
vendored
@@ -59,6 +59,7 @@ jobs:
|
|||||||
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
|
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
|
||||||
APPLE_ID: ${{ secrets.APPLE_ID }}
|
APPLE_ID: ${{ secrets.APPLE_ID }}
|
||||||
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
|
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
|
||||||
|
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
|
||||||
with:
|
with:
|
||||||
tagName: v__VERSION__
|
tagName: v__VERSION__
|
||||||
releaseName: 'App v__VERSION__'
|
releaseName: 'App v__VERSION__'
|
||||||
|
|||||||
2
.gitignore
vendored
@@ -14,9 +14,9 @@ out
|
|||||||
*.local
|
*.local
|
||||||
.next
|
.next
|
||||||
.vscode
|
.vscode
|
||||||
pnpm-lock.yaml
|
|
||||||
*.db
|
*.db
|
||||||
*.db-journal
|
*.db-journal
|
||||||
|
bun.lockb
|
||||||
|
|
||||||
# Editor directories and files
|
# Editor directories and files
|
||||||
.vscode/*
|
.vscode/*
|
||||||
|
|||||||
16
README.md
@@ -8,6 +8,12 @@ Download Lume for your platform here: [https://github.com/luminous-devs/lume/rel
|
|||||||
|
|
||||||
Supported platform: macOS, Windows and Linux
|
Supported platform: macOS, Windows and Linux
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- PNPM or Bun (experiment)
|
||||||
|
|
||||||
|
- Tauri: https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-macos
|
||||||
|
|
||||||
### Develop
|
### Develop
|
||||||
|
|
||||||
Clone project
|
Clone project
|
||||||
@@ -22,20 +28,14 @@ Install packages
|
|||||||
pnpm install
|
pnpm install
|
||||||
```
|
```
|
||||||
|
|
||||||
Run dev
|
Run dev build
|
||||||
|
|
||||||
```
|
```
|
||||||
pnpm tauri dev
|
pnpm tauri dev
|
||||||
```
|
```
|
||||||
|
|
||||||
Build
|
Generate production build
|
||||||
|
|
||||||
```
|
```
|
||||||
pnpm tauri build
|
pnpm tauri build
|
||||||
```
|
```
|
||||||
|
|
||||||
(Advance) - Generate SQLite migration
|
|
||||||
|
|
||||||
```
|
|
||||||
pnpm add-migrate <migrate_name>
|
|
||||||
```
|
|
||||||
|
|||||||
90
package.json
@@ -2,7 +2,7 @@
|
|||||||
"name": "lume",
|
"name": "lume",
|
||||||
"description": "the communication app",
|
"description": "the communication app",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.2.2",
|
"version": "1.2.7",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
@@ -18,86 +18,88 @@
|
|||||||
"**/*.{ts, tsx, css, md, html, json}": "prettier --cache --write"
|
"**/*.{ts, tsx, css, md, html, json}": "prettier --cache --write"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ctrl/magnet-link": "^3.1.2",
|
"@dnd-kit/core": "^6.0.8",
|
||||||
"@getalby/sdk": "^2.4.0",
|
"@getalby/sdk": "^2.4.0",
|
||||||
"@nostr-dev-kit/ndk": "^0.8.23",
|
"@nostr-dev-kit/ndk": "^1.3.1",
|
||||||
|
"@nostr-dev-kit/ndk-cache-dexie": "^1.3.0",
|
||||||
"@nostr-fetch/adapter-ndk": "^0.12.2",
|
"@nostr-fetch/adapter-ndk": "^0.12.2",
|
||||||
"@radix-ui/react-alert-dialog": "^1.0.4",
|
"@radix-ui/react-alert-dialog": "^1.0.5",
|
||||||
|
"@radix-ui/react-avatar": "^1.0.4",
|
||||||
"@radix-ui/react-collapsible": "^1.0.3",
|
"@radix-ui/react-collapsible": "^1.0.3",
|
||||||
"@radix-ui/react-dialog": "^1.0.4",
|
"@radix-ui/react-dialog": "^1.0.5",
|
||||||
"@radix-ui/react-dropdown-menu": "^2.0.5",
|
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
||||||
"@radix-ui/react-popover": "^1.0.6",
|
"@radix-ui/react-hover-card": "^1.0.7",
|
||||||
"@radix-ui/react-tooltip": "^1.0.6",
|
"@radix-ui/react-popover": "^1.0.7",
|
||||||
"@tanstack/react-query": "^4.33.0",
|
"@radix-ui/react-tooltip": "^1.0.7",
|
||||||
"@tanstack/react-virtual": "3.0.0-beta.54",
|
"@tanstack/react-query": "^4.35.7",
|
||||||
"@tauri-apps/api": "^1.4.0",
|
"@tauri-apps/api": "^1.5.0",
|
||||||
"@tiptap/extension-image": "^2.1.8",
|
"@tiptap/extension-image": "^2.1.11",
|
||||||
"@tiptap/extension-mention": "^2.1.8",
|
"@tiptap/extension-mention": "^2.1.11",
|
||||||
"@tiptap/extension-placeholder": "^2.1.8",
|
"@tiptap/extension-placeholder": "^2.1.11",
|
||||||
"@tiptap/pm": "^2.1.8",
|
"@tiptap/pm": "^2.1.11",
|
||||||
"@tiptap/react": "^2.1.8",
|
"@tiptap/react": "^2.1.11",
|
||||||
"@tiptap/starter-kit": "^2.1.8",
|
"@tiptap/starter-kit": "^2.1.11",
|
||||||
"@tiptap/suggestion": "^2.1.8",
|
"@tiptap/suggestion": "^2.1.11",
|
||||||
"@void-cat/api": "^1.0.7",
|
"@vidstack/react": "^1.1.5",
|
||||||
"dayjs": "^1.11.9",
|
"dayjs": "^1.11.10",
|
||||||
"destr": "^2.0.1",
|
"destr": "^2.0.1",
|
||||||
"get-urls": "^12.1.0",
|
|
||||||
"html-to-text": "^9.0.5",
|
"html-to-text": "^9.0.5",
|
||||||
"light-bolt11-decoder": "^3.0.0",
|
"light-bolt11-decoder": "^3.0.0",
|
||||||
"lru-cache": "^10.0.1",
|
"lru-cache": "^10.0.1",
|
||||||
"minidenticons": "^4.2.0",
|
"minidenticons": "^4.2.0",
|
||||||
"nostr-fetch": "^0.13.0",
|
"nostr-fetch": "^0.13.0",
|
||||||
"nostr-tools": "^1.14.2",
|
"nostr-tools": "^1.16.0",
|
||||||
"qrcode.react": "^3.1.0",
|
"qrcode.react": "^3.1.0",
|
||||||
|
"re-resizable": "^6.9.11",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
|
"react-currency-input-field": "^3.6.11",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-hook-form": "^7.46.1",
|
"react-hook-form": "^7.47.0",
|
||||||
"react-hotkeys-hook": "^4.4.1",
|
|
||||||
"react-markdown": "^8.0.7",
|
"react-markdown": "^8.0.7",
|
||||||
"react-player": "^2.12.0",
|
"react-router-dom": "^6.16.0",
|
||||||
"react-router-dom": "^6.15.0",
|
|
||||||
"react-textarea-autosize": "^8.5.3",
|
"react-textarea-autosize": "^8.5.3",
|
||||||
"react-virtuoso": "^4.5.0",
|
"reactflow": "^11.9.2",
|
||||||
"remark-gfm": "^3.0.1",
|
"remark-gfm": "^3.0.1",
|
||||||
"tauri-plugin-sql-api": "github:tauri-apps/tauri-plugin-sql#v1",
|
"tauri-plugin-sql-api": "github:tauri-apps/tauri-plugin-sql#v1",
|
||||||
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store#v1",
|
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store#v1",
|
||||||
"tauri-plugin-stronghold-api": "github:tauri-apps/tauri-plugin-stronghold#v1",
|
"tauri-plugin-stronghold-api": "github:tauri-apps/tauri-plugin-stronghold#v1",
|
||||||
"tauri-plugin-upload-api": "github:tauri-apps/tauri-plugin-upload#v1",
|
"tauri-plugin-upload-api": "github:tauri-apps/tauri-plugin-upload#v1",
|
||||||
"tippy.js": "^6.3.7",
|
"tippy.js": "^6.3.7",
|
||||||
"zustand": "^4.4.1"
|
"virtua": "^0.9.1",
|
||||||
|
"zustand": "^4.4.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/typography": "^0.5.9",
|
"@tailwindcss/typography": "^0.5.10",
|
||||||
"@tauri-apps/cli": "^1.4.0",
|
"@tauri-apps/cli": "^1.5.1",
|
||||||
"@trivago/prettier-plugin-sort-imports": "^4.2.0",
|
"@trivago/prettier-plugin-sort-imports": "^4.2.0",
|
||||||
"@types/html-to-text": "^9.0.1",
|
"@types/html-to-text": "^9.0.2",
|
||||||
"@types/node": "^20.5.9",
|
"@types/node": "^20.8.2",
|
||||||
"@types/react": "^18.2.21",
|
"@types/react": "^18.2.24",
|
||||||
"@types/react-dom": "^18.2.7",
|
"@types/react-dom": "^18.2.8",
|
||||||
"@types/youtube-player": "^5.5.7",
|
"@types/youtube-player": "^5.5.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.6.0",
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
||||||
"@typescript-eslint/parser": "^6.6.0",
|
"@typescript-eslint/parser": "^6.7.4",
|
||||||
"@vitejs/plugin-react-swc": "^3.3.2",
|
"@vitejs/plugin-react-swc": "^3.4.0",
|
||||||
"autoprefixer": "^10.4.15",
|
"autoprefixer": "^10.4.16",
|
||||||
"clsx": "^2.0.0",
|
"clsx": "^2.0.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"csstype": "^3.1.2",
|
"csstype": "^3.1.2",
|
||||||
"encoding": "^0.1.13",
|
"encoding": "^0.1.13",
|
||||||
"eslint": "^8.48.0",
|
"eslint": "^8.50.0",
|
||||||
"eslint-config-prettier": "^9.0.0",
|
"eslint-config-prettier": "^9.0.0",
|
||||||
"eslint-plugin-jsx-a11y": "^6.7.1",
|
"eslint-plugin-jsx-a11y": "^6.7.1",
|
||||||
"eslint-plugin-react": "^7.33.2",
|
"eslint-plugin-react": "^7.33.2",
|
||||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||||
"husky": "^8.0.3",
|
"husky": "^8.0.3",
|
||||||
"lint-staged": "^14.0.1",
|
"lint-staged": "^14.0.1",
|
||||||
"postcss": "^8.4.29",
|
"postcss": "^8.4.31",
|
||||||
"prettier": "^3.0.3",
|
"prettier": "^3.0.3",
|
||||||
"prettier-plugin-tailwindcss": "^0.5.4",
|
"prettier-plugin-tailwindcss": "^0.5.5",
|
||||||
"prop-types": "^15.8.1",
|
"prop-types": "^15.8.1",
|
||||||
"tailwind-merge": "^1.14.0",
|
"tailwind-merge": "^1.14.0",
|
||||||
"tailwindcss": "^3.3.3",
|
"tailwindcss": "^3.3.3",
|
||||||
"typescript": "^5.2.2",
|
"typescript": "^5.2.2",
|
||||||
"vite": "^4.4.9",
|
"vite": "^4.4.10",
|
||||||
"vite-tsconfig-paths": "^4.2.0"
|
"vite-tsconfig-paths": "^4.2.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4001
pnpm-lock.yaml
generated
699
src-tauri/Cargo.lock
generated
@@ -1,22 +1,26 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lume"
|
name = "lume"
|
||||||
version = "1.2.2"
|
version = "1.2.7"
|
||||||
description = "the communication app"
|
description = "the communication app"
|
||||||
authors = ["Ren Amamiya"]
|
authors = ["Ren Amamiya"]
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
repository = "https://github.com/luminous-devs/lume"
|
repository = "https://github.com/luminous-devs/lume"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.71"
|
rust-version = "1.66"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tauri-build = { version = "1.4.0", features = [] }
|
tauri-build = { version = "1.5", features = [] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
tauri = { version = "1.4.0", features = [
|
tauri = { version = "1.5", features = [
|
||||||
|
"macos-private-api",
|
||||||
|
"window-close",
|
||||||
|
"window-print",
|
||||||
|
"window-create",
|
||||||
"fs-read-dir",
|
"fs-read-dir",
|
||||||
"fs-read-file",
|
"fs-read-file",
|
||||||
"window-start-dragging",
|
"window-start-dragging",
|
||||||
@@ -34,7 +38,6 @@ tauri = { version = "1.4.0", features = [
|
|||||||
"fs-remove-file",
|
"fs-remove-file",
|
||||||
"window-center",
|
"window-center",
|
||||||
"dialog-all",
|
"dialog-all",
|
||||||
"macos-private-api",
|
|
||||||
"http-multipart",
|
"http-multipart",
|
||||||
] }
|
] }
|
||||||
tauri-plugin-sql = { git = "hhttps://github.com/tauri-apps/plugins-workspace", branch = "v1", features = [
|
tauri-plugin-sql = { git = "hhttps://github.com/tauri-apps/plugins-workspace", branch = "v1", features = [
|
||||||
@@ -46,16 +49,22 @@ tauri-plugin-stronghold = { git = "https://github.com/tauri-apps/plugins-workspa
|
|||||||
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
|
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
|
||||||
tauri-plugin-upload = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
|
tauri-plugin-upload = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
|
||||||
window-vibrancy = { git = "https://github.com/tauri-apps/window-vibrancy", branch = "dev" }
|
window-vibrancy = { git = "https://github.com/tauri-apps/window-vibrancy", branch = "dev" }
|
||||||
window-shadows = { git = "https://github.com/tauri-apps/window-shadows", branch = "dev" }
|
|
||||||
sqlx-cli = { version = "0.7.0", default-features = false, features = [
|
sqlx-cli = { version = "0.7.0", default-features = false, features = [
|
||||||
"sqlite",
|
"sqlite",
|
||||||
] }
|
] }
|
||||||
rust-argon2 = "1.0"
|
rust-argon2 = "1.0"
|
||||||
webpage = { version = "1.6.0", features = ["serde"] }
|
webpage = { version = "1.6.0", features = ["serde"] }
|
||||||
|
|
||||||
|
[target.'cfg(any(target_os = "macos"))'.dependencies]
|
||||||
|
cocoa = "0.25.0"
|
||||||
|
objc = "0.2.7"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# this feature is used for production builds or when `devPath` points to the filesystem
|
# by default Tauri runs in production mode
|
||||||
# DO NOT REMOVE!!
|
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
|
||||||
|
default = ["custom-protocol"]
|
||||||
|
# this feature is used used for production builds where `devPath` points to the filesystem
|
||||||
|
# DO NOT remove this
|
||||||
custom-protocol = ["tauri/custom-protocol"]
|
custom-protocol = ["tauri/custom-protocol"]
|
||||||
|
|
||||||
# Optimized for bundle size. If you want faster builds comment out/delete this section.
|
# Optimized for bundle size. If you want faster builds comment out/delete this section.
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 731 B After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 709 B After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 921 B After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 29 KiB |
@@ -0,0 +1,2 @@
|
|||||||
|
-- Add migration script here
|
||||||
|
CREATE UNIQUE INDEX unique_relay ON relays (relay);
|
||||||
@@ -3,16 +3,25 @@
|
|||||||
windows_subsystem = "windows"
|
windows_subsystem = "windows"
|
||||||
)]
|
)]
|
||||||
|
|
||||||
use tauri::Manager;
|
#[cfg(target_os = "macos")]
|
||||||
|
#[macro_use]
|
||||||
|
extern crate objc;
|
||||||
|
|
||||||
|
use std::time::Duration;
|
||||||
|
use tauri::{Manager, WindowEvent};
|
||||||
use tauri_plugin_autostart::MacosLauncher;
|
use tauri_plugin_autostart::MacosLauncher;
|
||||||
use tauri_plugin_sql::{Migration, MigrationKind};
|
use tauri_plugin_sql::{Migration, MigrationKind};
|
||||||
use window_shadows::set_shadow;
|
|
||||||
use webpage::{Webpage, WebpageOptions};
|
use webpage::{Webpage, WebpageOptions};
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use window_vibrancy::{apply_vibrancy, NSVisualEffectMaterial};
|
use window_vibrancy::{apply_vibrancy, NSVisualEffectMaterial};
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
use traffic_light::TrafficLight;
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
mod traffic_light;
|
||||||
|
|
||||||
#[derive(Clone, serde::Serialize)]
|
#[derive(Clone, serde::Serialize)]
|
||||||
struct Payload {
|
struct Payload {
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
@@ -103,11 +112,18 @@ fn main() {
|
|||||||
apply_vibrancy(&window, NSVisualEffectMaterial::HudWindow, None, None)
|
apply_vibrancy(&window, NSVisualEffectMaterial::HudWindow, None, None)
|
||||||
.expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");
|
.expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");
|
||||||
|
|
||||||
// set native shadow
|
#[cfg(target_os = "macos")]
|
||||||
set_shadow(&window, true).expect("Unsupported platform!");
|
window.position_traffic_lights(16.0, 25.0);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
.on_window_event(|e| {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
if let WindowEvent::Resized(..) = e.event() {
|
||||||
|
let window = e.window();
|
||||||
|
window.position_traffic_lights(16.0, 25.0);
|
||||||
|
}
|
||||||
|
})
|
||||||
.plugin(
|
.plugin(
|
||||||
tauri_plugin_sql::Builder::default()
|
tauri_plugin_sql::Builder::default()
|
||||||
.add_migrations(
|
.add_migrations(
|
||||||
@@ -215,6 +231,12 @@ fn main() {
|
|||||||
sql: include_str!("../migrations/20230817014932_add_last_login_time_to_account.sql"),
|
sql: include_str!("../migrations/20230817014932_add_last_login_time_to_account.sql"),
|
||||||
kind: MigrationKind::Up,
|
kind: MigrationKind::Up,
|
||||||
},
|
},
|
||||||
|
Migration {
|
||||||
|
version: 20230918235335,
|
||||||
|
description: "add unique to relay",
|
||||||
|
sql: include_str!("../migrations/20230918235335_add_uniq_to_relay.sql"),
|
||||||
|
kind: MigrationKind::Up,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.build(),
|
.build(),
|
||||||
|
|||||||
60
src-tauri/src/traffic_light.rs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
use tauri::{Runtime, Window};
|
||||||
|
|
||||||
|
pub trait TrafficLight {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
fn set_transparent_titlebar(&self, transparent: bool);
|
||||||
|
fn position_traffic_lights(&self, x: f64, y: f64);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<R: Runtime> TrafficLight for Window<R> {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
fn set_transparent_titlebar(&self, transparent: bool) {
|
||||||
|
use cocoa::appkit::{NSWindow, NSWindowTitleVisibility};
|
||||||
|
|
||||||
|
let window = self.ns_window().unwrap() as cocoa::base::id;
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
window.setTitleVisibility_(NSWindowTitleVisibility::NSWindowTitleHidden);
|
||||||
|
|
||||||
|
if transparent {
|
||||||
|
window.setTitlebarAppearsTransparent_(cocoa::base::YES);
|
||||||
|
} else {
|
||||||
|
window.setTitlebarAppearsTransparent_(cocoa::base::NO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
fn position_traffic_lights(&self, x: f64, y: f64) {
|
||||||
|
use cocoa::appkit::{NSView, NSWindow, NSWindowButton};
|
||||||
|
use cocoa::foundation::NSRect;
|
||||||
|
|
||||||
|
let window = self.ns_window().unwrap() as cocoa::base::id;
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let close = window.standardWindowButton_(NSWindowButton::NSWindowCloseButton);
|
||||||
|
let miniaturize = window.standardWindowButton_(NSWindowButton::NSWindowMiniaturizeButton);
|
||||||
|
let zoom = window.standardWindowButton_(NSWindowButton::NSWindowZoomButton);
|
||||||
|
|
||||||
|
let title_bar_container_view = close.superview().superview();
|
||||||
|
|
||||||
|
let close_rect: NSRect = msg_send![close, frame];
|
||||||
|
let button_height = close_rect.size.height;
|
||||||
|
|
||||||
|
let title_bar_frame_height = button_height + y;
|
||||||
|
let mut title_bar_rect = NSView::frame(title_bar_container_view);
|
||||||
|
title_bar_rect.size.height = title_bar_frame_height;
|
||||||
|
title_bar_rect.origin.y = NSView::frame(window).size.height - title_bar_frame_height;
|
||||||
|
let _: () = msg_send![title_bar_container_view, setFrame: title_bar_rect];
|
||||||
|
|
||||||
|
let window_buttons = vec![close, miniaturize, zoom];
|
||||||
|
let space_between = NSView::frame(miniaturize).origin.x - NSView::frame(close).origin.x;
|
||||||
|
|
||||||
|
for (i, button) in window_buttons.into_iter().enumerate() {
|
||||||
|
let mut rect: NSRect = NSView::frame(button);
|
||||||
|
rect.origin.x = x + (i as f64 * space_between);
|
||||||
|
button.setFrameOrigin(rect.origin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
{
|
{
|
||||||
|
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeBuildCommand": "pnpm build",
|
"beforeBuildCommand": "pnpm run build",
|
||||||
"beforeDevCommand": "pnpm dev",
|
"beforeDevCommand": "pnpm run dev",
|
||||||
"devPath": "http://localhost:3000",
|
"devPath": "http://localhost:3000",
|
||||||
"distDir": "../dist",
|
"distDir": "../dist",
|
||||||
"withGlobalTauri": true
|
"withGlobalTauri": true
|
||||||
},
|
},
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "Lume",
|
"productName": "Lume",
|
||||||
"version": "1.2.2"
|
"version": "1.2.7"
|
||||||
},
|
},
|
||||||
"tauri": {
|
"tauri": {
|
||||||
"allowlist": {
|
"allowlist": {
|
||||||
@@ -66,7 +67,10 @@
|
|||||||
"center": true,
|
"center": true,
|
||||||
"setResizable": true,
|
"setResizable": true,
|
||||||
"setSize": true,
|
"setSize": true,
|
||||||
"startDragging": true
|
"startDragging": true,
|
||||||
|
"create": true,
|
||||||
|
"close": true,
|
||||||
|
"print": true
|
||||||
},
|
},
|
||||||
"clipboard": {
|
"clipboard": {
|
||||||
"all": false,
|
"all": false,
|
||||||
@@ -103,7 +107,8 @@
|
|||||||
"frameworks": [],
|
"frameworks": [],
|
||||||
"providerShortName": null,
|
"providerShortName": null,
|
||||||
"signingIdentity": null,
|
"signingIdentity": null,
|
||||||
"minimumSystemVersion": "10.15.0"
|
"minimumSystemVersion": "10.15.0",
|
||||||
|
"license": "../LICENSE"
|
||||||
},
|
},
|
||||||
"resources": [],
|
"resources": [],
|
||||||
"shortDescription": "",
|
"shortDescription": "",
|
||||||
@@ -121,9 +126,14 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"security": {
|
"security": {
|
||||||
"csp": {
|
"dangerousRemoteDomainIpcAccess": [
|
||||||
"content-security-policy": "upgrade-insecure-requests"
|
{
|
||||||
}
|
"scheme": "https",
|
||||||
|
"domain": "nwc.getalby.com",
|
||||||
|
"windows": ["alby"],
|
||||||
|
"enableTauriAPI": true
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
{
|
{
|
||||||
|
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
|
||||||
"tauri": {
|
"tauri": {
|
||||||
"windows": [
|
"windows": [
|
||||||
{
|
{
|
||||||
"width": 400,
|
"width": 300,
|
||||||
"height": 500,
|
"height": 300,
|
||||||
"decorations": false,
|
"decorations": false,
|
||||||
"title": "Lume",
|
"title": "Lume",
|
||||||
"center": true,
|
"center": true,
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
|
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
|
||||||
"tauri": {
|
"tauri": {
|
||||||
"macOSPrivateApi": true,
|
"macOSPrivateApi": true,
|
||||||
"windows": [
|
"windows": [
|
||||||
{
|
{
|
||||||
"width": 400,
|
"width": 300,
|
||||||
"height": 500,
|
"height": 300,
|
||||||
"decorations": true,
|
"decorations": false,
|
||||||
"title": "Lume",
|
"title": "Lume",
|
||||||
"titleBarStyle": "Overlay",
|
"titleBarStyle": "Overlay",
|
||||||
"hiddenTitle": true,
|
"hiddenTitle": true,
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
{
|
{
|
||||||
|
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
|
||||||
"tauri": {
|
"tauri": {
|
||||||
"windows": [
|
"windows": [
|
||||||
{
|
{
|
||||||
"width": 400,
|
"width": 300,
|
||||||
"height": 500,
|
"height": 300,
|
||||||
"decorations": false,
|
"decorations": false,
|
||||||
"title": "Lume",
|
"title": "Lume",
|
||||||
"center": true,
|
"center": true,
|
||||||
|
|||||||
543
src/app.tsx
@@ -1,9 +1,15 @@
|
|||||||
import { RouterProvider, createBrowserRouter, redirect } from 'react-router-dom';
|
import { message } from '@tauri-apps/api/dialog';
|
||||||
|
import { fetch } from '@tauri-apps/api/http';
|
||||||
|
import { RouterProvider, createBrowserRouter, defer, redirect } from 'react-router-dom';
|
||||||
|
import { ReactFlowProvider } from 'reactflow';
|
||||||
|
|
||||||
import { AuthCreateScreen } from '@app/auth/create';
|
import { AuthCreateScreen } from '@app/auth/create';
|
||||||
import { AuthImportScreen } from '@app/auth/import';
|
import { AuthImportScreen } from '@app/auth/import';
|
||||||
import { OnboardingScreen } from '@app/auth/onboarding';
|
import { OnboardingScreen } from '@app/auth/onboarding';
|
||||||
import { ErrorScreen } from '@app/error';
|
import { ErrorScreen } from '@app/error';
|
||||||
|
import { ExploreScreen } from '@app/explore';
|
||||||
|
|
||||||
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
import { Frame } from '@shared/frame';
|
import { Frame } from '@shared/frame';
|
||||||
import { LoaderIcon } from '@shared/icons';
|
import { LoaderIcon } from '@shared/icons';
|
||||||
@@ -12,252 +18,300 @@ import { AuthLayout } from '@shared/layouts/auth';
|
|||||||
import { NoteLayout } from '@shared/layouts/note';
|
import { NoteLayout } from '@shared/layouts/note';
|
||||||
import { SettingsLayout } from '@shared/layouts/settings';
|
import { SettingsLayout } from '@shared/layouts/settings';
|
||||||
|
|
||||||
import { checkActiveAccount } from '@utils/checkActiveAccount';
|
|
||||||
|
|
||||||
import './index.css';
|
import './index.css';
|
||||||
|
|
||||||
async function Loader() {
|
|
||||||
try {
|
|
||||||
const account = await checkActiveAccount();
|
|
||||||
const stronghold = sessionStorage.getItem('stronghold');
|
|
||||||
const privkey = JSON.parse(stronghold).state.privkey || null;
|
|
||||||
const onboarding = localStorage.getItem('onboarding');
|
|
||||||
const step = JSON.parse(onboarding).state.step || null;
|
|
||||||
|
|
||||||
if (step) {
|
|
||||||
return redirect(step);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!account) {
|
|
||||||
return redirect('/auth/welcome');
|
|
||||||
} else {
|
|
||||||
if (!privkey) {
|
|
||||||
return redirect('/auth/unlock');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
} catch (e) {
|
|
||||||
throw new Error('App failed to load');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const router = createBrowserRouter([
|
|
||||||
{
|
|
||||||
path: '/',
|
|
||||||
element: <AppLayout />,
|
|
||||||
errorElement: <ErrorScreen />,
|
|
||||||
loader: Loader,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: '',
|
|
||||||
async lazy() {
|
|
||||||
const { SpaceScreen } = await import('@app/space');
|
|
||||||
return { Component: SpaceScreen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'users/:pubkey',
|
|
||||||
async lazy() {
|
|
||||||
const { UserScreen } = await import('@app/users');
|
|
||||||
return { Component: UserScreen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'chats/:pubkey',
|
|
||||||
async lazy() {
|
|
||||||
const { ChatScreen } = await import('@app/chats');
|
|
||||||
return { Component: ChatScreen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'notifications',
|
|
||||||
async lazy() {
|
|
||||||
const { NotificationScreen } = await import('@app/notifications');
|
|
||||||
return { Component: NotificationScreen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/notes',
|
|
||||||
element: <NoteLayout />,
|
|
||||||
errorElement: <ErrorScreen />,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: 'text/:id',
|
|
||||||
async lazy() {
|
|
||||||
const { TextNoteScreen } = await import('@app/notes/text');
|
|
||||||
return { Component: TextNoteScreen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'article/:id',
|
|
||||||
async lazy() {
|
|
||||||
const { ArticleNoteScreen } = await import('@app/notes/article');
|
|
||||||
return { Component: ArticleNoteScreen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/splashscreen',
|
|
||||||
errorElement: <ErrorScreen />,
|
|
||||||
async lazy() {
|
|
||||||
const { SplashScreen } = await import('@app/splash');
|
|
||||||
return { Component: SplashScreen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/auth',
|
|
||||||
element: <AuthLayout />,
|
|
||||||
errorElement: <ErrorScreen />,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: 'welcome',
|
|
||||||
async lazy() {
|
|
||||||
const { WelcomeScreen } = await import('@app/auth/welcome');
|
|
||||||
return { Component: WelcomeScreen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'import',
|
|
||||||
element: <AuthImportScreen />,
|
|
||||||
errorElement: <ErrorScreen />,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: '',
|
|
||||||
async lazy() {
|
|
||||||
const { ImportStep1Screen } = await import('@app/auth/import/step-1');
|
|
||||||
return { Component: ImportStep1Screen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'step-2',
|
|
||||||
async lazy() {
|
|
||||||
const { ImportStep2Screen } = await import('@app/auth/import/step-2');
|
|
||||||
return { Component: ImportStep2Screen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'step-3',
|
|
||||||
async lazy() {
|
|
||||||
const { ImportStep3Screen } = await import('@app/auth/import/step-3');
|
|
||||||
return { Component: ImportStep3Screen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'create',
|
|
||||||
element: <AuthCreateScreen />,
|
|
||||||
errorElement: <ErrorScreen />,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: '',
|
|
||||||
async lazy() {
|
|
||||||
const { CreateStep1Screen } = await import('@app/auth/create/step-1');
|
|
||||||
return { Component: CreateStep1Screen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'step-2',
|
|
||||||
async lazy() {
|
|
||||||
const { CreateStep2Screen } = await import('@app/auth/create/step-2');
|
|
||||||
return { Component: CreateStep2Screen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'step-3',
|
|
||||||
async lazy() {
|
|
||||||
const { CreateStep3Screen } = await import('@app/auth/create/step-3');
|
|
||||||
return { Component: CreateStep3Screen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'onboarding',
|
|
||||||
element: <OnboardingScreen />,
|
|
||||||
errorElement: <ErrorScreen />,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: '',
|
|
||||||
async lazy() {
|
|
||||||
const { OnboardStep1Screen } = await import('@app/auth/onboarding/step-1');
|
|
||||||
return { Component: OnboardStep1Screen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'step-2',
|
|
||||||
async lazy() {
|
|
||||||
const { OnboardStep2Screen } = await import('@app/auth/onboarding/step-2');
|
|
||||||
return { Component: OnboardStep2Screen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'step-3',
|
|
||||||
async lazy() {
|
|
||||||
const { OnboardStep3Screen } = await import('@app/auth/onboarding/step-3');
|
|
||||||
return { Component: OnboardStep3Screen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'unlock',
|
|
||||||
async lazy() {
|
|
||||||
const { UnlockScreen } = await import('@app/auth/unlock');
|
|
||||||
return { Component: UnlockScreen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'migrate',
|
|
||||||
async lazy() {
|
|
||||||
const { MigrateScreen } = await import('@app/auth/migrate');
|
|
||||||
return { Component: MigrateScreen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'reset',
|
|
||||||
async lazy() {
|
|
||||||
const { ResetScreen } = await import('@app/auth/reset');
|
|
||||||
return { Component: ResetScreen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'hard-reset',
|
|
||||||
async lazy() {
|
|
||||||
const { HardResetScreen } = await import('@app/auth/hardReset');
|
|
||||||
return { Component: HardResetScreen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/settings',
|
|
||||||
element: <SettingsLayout />,
|
|
||||||
errorElement: <ErrorScreen />,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: '',
|
|
||||||
async lazy() {
|
|
||||||
const { GeneralSettingsScreen } = await import('@app/settings/general');
|
|
||||||
return { Component: GeneralSettingsScreen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'backup',
|
|
||||||
async lazy() {
|
|
||||||
const { AccountSettingsScreen } = await import('@app/settings/account');
|
|
||||||
return { Component: AccountSettingsScreen };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
|
const { db } = useStorage();
|
||||||
|
|
||||||
|
const accountLoader = async () => {
|
||||||
|
try {
|
||||||
|
const totalAccount = await db.checkAccount();
|
||||||
|
|
||||||
|
const stronghold = sessionStorage.getItem('stronghold');
|
||||||
|
const privkey = JSON.parse(stronghold).state.privkey || null;
|
||||||
|
|
||||||
|
const onboarding = localStorage.getItem('onboarding');
|
||||||
|
const step = JSON.parse(onboarding).state.step || null;
|
||||||
|
|
||||||
|
if (totalAccount === 0) {
|
||||||
|
return redirect('/auth/welcome');
|
||||||
|
} else {
|
||||||
|
if (step) {
|
||||||
|
return redirect(step);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!privkey) {
|
||||||
|
return redirect('/auth/unlock');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
} catch (e) {
|
||||||
|
await message(e, { title: 'An unexpected error has occurred', type: 'error' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const relayLoader = async ({ params }) => {
|
||||||
|
return defer({
|
||||||
|
relay: fetch(`https://${params.url}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/nostr+json',
|
||||||
|
},
|
||||||
|
}).then((res) => res.data),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const router = createBrowserRouter([
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
element: <AppLayout />,
|
||||||
|
errorElement: <ErrorScreen />,
|
||||||
|
loader: accountLoader,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
async lazy() {
|
||||||
|
const { SpaceScreen } = await import('@app/space');
|
||||||
|
return { Component: SpaceScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'users/:pubkey',
|
||||||
|
async lazy() {
|
||||||
|
const { UserScreen } = await import('@app/users');
|
||||||
|
return { Component: UserScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'chats/:pubkey',
|
||||||
|
async lazy() {
|
||||||
|
const { ChatScreen } = await import('@app/chats');
|
||||||
|
return { Component: ChatScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'notifications',
|
||||||
|
async lazy() {
|
||||||
|
const { NotificationScreen } = await import('@app/notifications');
|
||||||
|
return { Component: NotificationScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'nwc',
|
||||||
|
async lazy() {
|
||||||
|
const { NWCScreen } = await import('@app/nwc');
|
||||||
|
return { Component: NWCScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'explore',
|
||||||
|
element: (
|
||||||
|
<ReactFlowProvider>
|
||||||
|
<ExploreScreen />
|
||||||
|
</ReactFlowProvider>
|
||||||
|
),
|
||||||
|
errorElement: <ErrorScreen />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'relays',
|
||||||
|
async lazy() {
|
||||||
|
const { RelaysScreen } = await import('@app/relays');
|
||||||
|
return { Component: RelaysScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'relays/:url',
|
||||||
|
loader: relayLoader,
|
||||||
|
async lazy() {
|
||||||
|
const { RelayScreen } = await import('@app/relays/relay');
|
||||||
|
return { Component: RelayScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/notes',
|
||||||
|
element: <NoteLayout />,
|
||||||
|
errorElement: <ErrorScreen />,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: 'text/:id',
|
||||||
|
async lazy() {
|
||||||
|
const { TextNoteScreen } = await import('@app/notes/text');
|
||||||
|
return { Component: TextNoteScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'article/:id',
|
||||||
|
async lazy() {
|
||||||
|
const { ArticleNoteScreen } = await import('@app/notes/article');
|
||||||
|
return { Component: ArticleNoteScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/splashscreen',
|
||||||
|
errorElement: <ErrorScreen />,
|
||||||
|
async lazy() {
|
||||||
|
const { SplashScreen } = await import('@app/splash');
|
||||||
|
return { Component: SplashScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/auth',
|
||||||
|
element: <AuthLayout />,
|
||||||
|
errorElement: <ErrorScreen />,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: 'welcome',
|
||||||
|
async lazy() {
|
||||||
|
const { WelcomeScreen } = await import('@app/auth/welcome');
|
||||||
|
return { Component: WelcomeScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'import',
|
||||||
|
element: <AuthImportScreen />,
|
||||||
|
errorElement: <ErrorScreen />,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
async lazy() {
|
||||||
|
const { ImportStep1Screen } = await import('@app/auth/import/step-1');
|
||||||
|
return { Component: ImportStep1Screen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'step-2',
|
||||||
|
async lazy() {
|
||||||
|
const { ImportStep2Screen } = await import('@app/auth/import/step-2');
|
||||||
|
return { Component: ImportStep2Screen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'step-3',
|
||||||
|
async lazy() {
|
||||||
|
const { ImportStep3Screen } = await import('@app/auth/import/step-3');
|
||||||
|
return { Component: ImportStep3Screen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'create',
|
||||||
|
element: <AuthCreateScreen />,
|
||||||
|
errorElement: <ErrorScreen />,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
async lazy() {
|
||||||
|
const { CreateStep1Screen } = await import('@app/auth/create/step-1');
|
||||||
|
return { Component: CreateStep1Screen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'step-2',
|
||||||
|
async lazy() {
|
||||||
|
const { CreateStep2Screen } = await import('@app/auth/create/step-2');
|
||||||
|
return { Component: CreateStep2Screen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'step-3',
|
||||||
|
async lazy() {
|
||||||
|
const { CreateStep3Screen } = await import('@app/auth/create/step-3');
|
||||||
|
return { Component: CreateStep3Screen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'onboarding',
|
||||||
|
element: <OnboardingScreen />,
|
||||||
|
errorElement: <ErrorScreen />,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
async lazy() {
|
||||||
|
const { OnboardStep1Screen } = await import(
|
||||||
|
'@app/auth/onboarding/step-1'
|
||||||
|
);
|
||||||
|
return { Component: OnboardStep1Screen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'step-2',
|
||||||
|
async lazy() {
|
||||||
|
const { OnboardStep2Screen } = await import(
|
||||||
|
'@app/auth/onboarding/step-2'
|
||||||
|
);
|
||||||
|
return { Component: OnboardStep2Screen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'complete',
|
||||||
|
async lazy() {
|
||||||
|
const { CompleteScreen } = await import('@app/auth/complete');
|
||||||
|
return { Component: CompleteScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'unlock',
|
||||||
|
async lazy() {
|
||||||
|
const { UnlockScreen } = await import('@app/auth/unlock');
|
||||||
|
return { Component: UnlockScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'lock',
|
||||||
|
async lazy() {
|
||||||
|
const { LockScreen } = await import('@app/auth/lock');
|
||||||
|
return { Component: LockScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'migrate',
|
||||||
|
async lazy() {
|
||||||
|
const { MigrateScreen } = await import('@app/auth/migrate');
|
||||||
|
return { Component: MigrateScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'reset',
|
||||||
|
async lazy() {
|
||||||
|
const { ResetScreen } = await import('@app/auth/reset');
|
||||||
|
return { Component: ResetScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/settings',
|
||||||
|
element: <SettingsLayout />,
|
||||||
|
errorElement: <ErrorScreen />,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
async lazy() {
|
||||||
|
const { GeneralSettingsScreen } = await import('@app/settings/general');
|
||||||
|
return { Component: GeneralSettingsScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'backup',
|
||||||
|
async lazy() {
|
||||||
|
const { AccountSettingsScreen } = await import('@app/settings/account');
|
||||||
|
return { Component: AccountSettingsScreen };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RouterProvider
|
<RouterProvider
|
||||||
router={router}
|
router={router}
|
||||||
@@ -266,6 +320,7 @@ export default function App() {
|
|||||||
<LoaderIcon className="h-6 w-6 animate-spin text-white" />
|
<LoaderIcon className="h-6 w-6 animate-spin text-white" />
|
||||||
</Frame>
|
</Frame>
|
||||||
}
|
}
|
||||||
|
future={{ v7_startTransition: true }}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
42
src/app/auth/complete.tsx
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
|
export function CompleteScreen() {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [count, setCount] = useState(5);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let counter: NodeJS.Timeout;
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
counter = setTimeout(() => setCount(count - 1), 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count === 0) {
|
||||||
|
navigate('/', { replace: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearTimeout(counter);
|
||||||
|
};
|
||||||
|
}, [count]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="relative flex h-full w-full flex-col items-center justify-center">
|
||||||
|
<div className="mx-auto flex max-w-xl flex-col gap-1.5 text-center">
|
||||||
|
<h1 className="text-2xl font-light leading-none text-white">
|
||||||
|
<span className="font-semibold">You're ready</span>, redirecting in {count}
|
||||||
|
</h1>
|
||||||
|
<p className="text-white/70">
|
||||||
|
Thank you for using Lume. Lume doesn't use telemetry. If you encounter any
|
||||||
|
problems, please submit a report via the "Report Issue" button.
|
||||||
|
<br />
|
||||||
|
You can find it while using the application.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="absolute bottom-6 left-1/2 flex -translate-x-1/2 transform items-center justify-center">
|
||||||
|
<img src="/lume.png" alt="lume" className="h-auto w-1/5" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import { Image } from '@shared/image';
|
|
||||||
|
|
||||||
import { useProfile } from '@utils/hooks/useProfile';
|
|
||||||
import { displayNpub } from '@utils/shortenKey';
|
|
||||||
|
|
||||||
export function User({ pubkey, fallback }: { pubkey: string; fallback?: string }) {
|
|
||||||
const { status, user } = useProfile(pubkey, fallback);
|
|
||||||
|
|
||||||
if (status === 'loading') {
|
|
||||||
return (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<div className="relative h-10 w-10 shrink-0 animate-pulse rounded-md bg-white/10 backdrop-blur-xl" />
|
|
||||||
<div className="flex w-full flex-1 flex-col items-start gap-1 text-start">
|
|
||||||
<span className="h-4 w-1/2 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
|
||||||
<span className="h-3 w-1/3 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="flex items-center gap-2.5">
|
|
||||||
<Image
|
|
||||||
src={user?.picture || user?.image}
|
|
||||||
alt={pubkey}
|
|
||||||
className="h-10 w-10 shrink-0 rounded-lg object-cover"
|
|
||||||
/>
|
|
||||||
<div className="flex w-full flex-1 flex-col items-start text-start">
|
|
||||||
<p className="max-w-[15rem] truncate font-medium leading-tight text-white">
|
|
||||||
{user?.name || user?.display_name}
|
|
||||||
</p>
|
|
||||||
<span className="max-w-[15rem] truncate leading-tight text-white/50">
|
|
||||||
{displayNpub(pubkey, 16)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import { Image } from '@shared/image';
|
|
||||||
|
|
||||||
import { useProfile } from '@utils/hooks/useProfile';
|
|
||||||
import { displayNpub } from '@utils/shortenKey';
|
|
||||||
|
|
||||||
export function UserRelay({ pubkey }: { pubkey: string }) {
|
|
||||||
const { status, user } = useProfile(pubkey);
|
|
||||||
|
|
||||||
if (status === 'loading') {
|
|
||||||
return (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<div className="relative h-10 w-10 shrink-0 animate-pulse rounded-md bg-white/10 backdrop-blur-xl" />
|
|
||||||
<div className="flex w-full flex-1 flex-col items-start gap-1 text-start">
|
|
||||||
<span className="h-4 w-1/2 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
|
||||||
<span className="h-3 w-1/3 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="inline-flex items-center gap-2 text-white/50">
|
|
||||||
<span className="text-sm">Use by</span>
|
|
||||||
<div className="inline-flex items-center gap-1">
|
|
||||||
<Image
|
|
||||||
src={user?.picture || user?.image}
|
|
||||||
alt={pubkey}
|
|
||||||
className="h-5 w-5 shrink-0 rounded object-cover"
|
|
||||||
/>
|
|
||||||
<span className="truncate text-sm font-medium leading-none text-white">
|
|
||||||
{user?.name || user?.display_name || displayNpub(pubkey, 16)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
import { BaseDirectory, writeTextFile } from '@tauri-apps/api/fs';
|
import { writeText } from '@tauri-apps/api/clipboard';
|
||||||
|
import { message, save } from '@tauri-apps/api/dialog';
|
||||||
|
import { writeTextFile } from '@tauri-apps/api/fs';
|
||||||
|
import { downloadDir } from '@tauri-apps/api/path';
|
||||||
import { generatePrivateKey, getPublicKey, nip19 } from 'nostr-tools';
|
import { generatePrivateKey, getPublicKey, nip19 } from 'nostr-tools';
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
import { Button } from '@shared/button';
|
import { CopyIcon } from '@shared/icons';
|
||||||
import { EyeOffIcon, EyeOnIcon, LoaderIcon } from '@shared/icons';
|
|
||||||
import { ArrowRightCircleIcon } from '@shared/icons/arrowRightCircle';
|
|
||||||
|
|
||||||
import { useOnboarding } from '@stores/onboarding';
|
import { useOnboarding } from '@stores/onboarding';
|
||||||
import { useStronghold } from '@stores/stronghold';
|
import { useStronghold } from '@stores/stronghold';
|
||||||
@@ -21,8 +22,8 @@ export function CreateStep1Screen() {
|
|||||||
const setPubkey = useOnboarding((state) => state.setPubkey);
|
const setPubkey = useOnboarding((state) => state.setPubkey);
|
||||||
const setStep = useOnboarding((state) => state.setStep);
|
const setStep = useOnboarding((state) => state.setStep);
|
||||||
|
|
||||||
const [privkeyInput, setPrivkeyInput] = useState('password');
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [copied, setCopied] = useState(false);
|
||||||
const [downloaded, setDownloaded] = useState(false);
|
const [downloaded, setDownloaded] = useState(false);
|
||||||
|
|
||||||
const privkey = useMemo(() => generatePrivateKey(), []);
|
const privkey = useMemo(() => generatePrivateKey(), []);
|
||||||
@@ -30,27 +31,39 @@ export function CreateStep1Screen() {
|
|||||||
const npub = nip19.npubEncode(pubkey);
|
const npub = nip19.npubEncode(pubkey);
|
||||||
const nsec = nip19.nsecEncode(privkey);
|
const nsec = nip19.nsecEncode(privkey);
|
||||||
|
|
||||||
// toggle private key
|
const download = async () => {
|
||||||
const showPrivateKey = () => {
|
try {
|
||||||
if (privkeyInput === 'password') {
|
const downloadPath = await downloadDir();
|
||||||
setPrivkeyInput('text');
|
const fileName = `nostr_keys_${new Date().toISOString()}.txt`;
|
||||||
} else {
|
const filePath = await save({
|
||||||
setPrivkeyInput('password');
|
defaultPath: downloadPath + '/' + fileName,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (filePath) {
|
||||||
|
await writeTextFile(
|
||||||
|
filePath,
|
||||||
|
`Generated by Lume (lume.nu)\nPublic key: ${npub}\nPrivate key: ${nsec}`
|
||||||
|
);
|
||||||
|
|
||||||
|
setDownloaded(true);
|
||||||
|
} // else { user cancel action }
|
||||||
|
} catch (e) {
|
||||||
|
await message(e, { title: 'Cannot download account keys', type: 'error' });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const download = async () => {
|
const copyPrivkey = async () => {
|
||||||
await writeTextFile(
|
try {
|
||||||
`nostr_keys_${new Date().toISOString().slice(0, 10)}.txt`,
|
await writeText(nsec);
|
||||||
`Generated by Lume (lume.nu)\nPublic key: ${npub}\nPrivate key: ${nsec}`,
|
setCopied(true);
|
||||||
{
|
|
||||||
dir: BaseDirectory.Download,
|
setTimeout(() => setCopied(false), 3000);
|
||||||
}
|
} catch (e) {
|
||||||
);
|
await message(e, { title: 'Cannot copy private key', type: 'error' });
|
||||||
setDownloaded(true);
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const submit = () => {
|
const submit = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
// update state
|
// update state
|
||||||
@@ -59,7 +72,7 @@ export function CreateStep1Screen() {
|
|||||||
setPubkey(pubkey);
|
setPubkey(pubkey);
|
||||||
|
|
||||||
// save to database
|
// save to database
|
||||||
db.createAccount(npub, pubkey);
|
await db.createAccount(npub, pubkey);
|
||||||
|
|
||||||
// redirect to next step
|
// redirect to next step
|
||||||
navigate('/auth/create/step-2', { replace: true });
|
navigate('/auth/create/step-2', { replace: true });
|
||||||
@@ -67,81 +80,73 @@ export function CreateStep1Screen() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// save current step, if user close app and reopen it
|
// save current step, if user close app and reopen it
|
||||||
setStep('/auth/create/step-1');
|
setStep('/auth/create');
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="mx-auto w-full max-w-md">
|
||||||
<div className="mb-8 text-center">
|
<div className="mb-4 border-b border-white/10 pb-4">
|
||||||
<h1 className="text-xl font-semibold text-white">Save your access key!</h1>
|
<h1 className="mb-2 text-center text-2xl font-semibold text-white">
|
||||||
|
This is your new Nostr account
|
||||||
|
</h1>
|
||||||
|
<p className="mb-2 text-white/70">
|
||||||
|
Your private key is your password. If you lose this key, you will lose access to
|
||||||
|
your account! Copy it and keep it in a safe place. There is no way to reset your
|
||||||
|
private key.
|
||||||
|
</p>
|
||||||
|
<p className="text-white/70">
|
||||||
|
Public key is used for sharing with other people so that they can find you using
|
||||||
|
the public key.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-8">
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-3">
|
||||||
<span className="text-base font-semibold text-white/50">Public Key</span>
|
<div className="flex flex-col gap-1">
|
||||||
<input
|
<span className="font-medium text-white">Private Key</span>
|
||||||
readOnly
|
<div className="relative">
|
||||||
value={npub}
|
<input
|
||||||
className="relative h-11 w-full rounded-lg bg-white/10 px-3.5 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
readOnly
|
||||||
/>
|
value={nsec.substring(0, 5) + '**************************************'}
|
||||||
</div>
|
className="relative h-12 w-full rounded-lg border-t border-white/10 bg-white/20 py-1 pl-3.5 pr-11 text-white !outline-none backdrop-blur-xl placeholder:text-white/70"
|
||||||
<div className="flex flex-col gap-1">
|
/>
|
||||||
<span className="text-base font-semibold text-white/50">Private Key</span>
|
<button
|
||||||
<div className="relative">
|
type="button"
|
||||||
|
onClick={() => copyPrivkey()}
|
||||||
|
className="group absolute right-2 top-1/2 inline-flex h-7 -translate-y-1/2 transform items-center gap-1.5 rounded-md bg-white/20 px-2.5 text-sm hover:bg-white/30"
|
||||||
|
>
|
||||||
|
<CopyIcon className="h-4 w-4 text-white/70 group-hover:text-white" />
|
||||||
|
{copied ? 'Copied' : 'Copy'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<span className="font-medium text-white">Public Key</span>
|
||||||
<input
|
<input
|
||||||
readOnly
|
readOnly
|
||||||
type={privkeyInput}
|
value={npub}
|
||||||
value={nsec}
|
className="relative h-12 w-full rounded-lg border-t border-white/10 bg-white/20 px-3.5 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/70"
|
||||||
className="relative h-11 w-full rounded-lg bg-white/10 py-1 pl-3.5 pr-11 text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
|
||||||
/>
|
/>
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => showPrivateKey()}
|
|
||||||
className="group absolute right-2 top-1/2 -translate-y-1/2 transform rounded p-1 backdrop-blur-xl hover:bg-white/10"
|
|
||||||
>
|
|
||||||
{privkeyInput === 'password' ? (
|
|
||||||
<EyeOffIcon className="h-4 w-4 text-white/50 group-hover:text-white" />
|
|
||||||
) : (
|
|
||||||
<EyeOnIcon className="h-4 w-4 text-white/50 group-hover:text-white" />
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div className="mt-2 text-sm text-white/50">
|
|
||||||
<p>
|
|
||||||
Your private key is your password. If you lose this key, you will lose
|
|
||||||
access to your account! Copy it and keep it in a safe place. There is no way
|
|
||||||
to reset your private key.
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => submit()}
|
onClick={() => download()}
|
||||||
className="inline-flex h-11 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
className="inline-flex h-12 w-full items-center justify-center rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
||||||
>
|
>
|
||||||
{loading ? (
|
{downloaded ? 'Downloaded' : 'Download account keys'}
|
||||||
<>
|
|
||||||
<span className="w-5" />
|
|
||||||
<span>Creating...</span>
|
|
||||||
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<span className="w-5" />
|
|
||||||
<span>I have saved my key, continue</span>
|
|
||||||
<ArrowRightCircleIcon className="h-5 w-5" />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</button>
|
</button>
|
||||||
{downloaded ? (
|
<button
|
||||||
<span className="inline-flex h-11 w-full items-center justify-center text-sm text-white/50">
|
type="button"
|
||||||
Saved in Download folder
|
onClick={() => submit()}
|
||||||
</span>
|
className="inline-flex h-12 w-full items-center justify-center rounded-lg border-t border-white/10 bg-white/20 px-6 font-medium leading-none text-white hover:bg-white/30 focus:outline-none"
|
||||||
) : (
|
>
|
||||||
<Button preset="large-alt" onClick={() => download()}>
|
{loading ? 'Creating...' : 'Continue'}
|
||||||
Download
|
</button>
|
||||||
</Button>
|
<span className="text-center text-sm text-white/50">
|
||||||
)}
|
By clicking 'Continue', you are ensuring that your keys are saved in
|
||||||
|
a safe place. You cannot recover these keys if they are lost.
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ export function CreateStep2Screen() {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
if (data.password.length > 3) {
|
if (data.password.length > 3) {
|
||||||
const dir = await appConfigDir();
|
const dir = await appConfigDir();
|
||||||
const stronghold = await Stronghold.load(`${dir}/lume.stronghold`, data.password);
|
const stronghold = await Stronghold.load(`${dir}lume.stronghold`, data.password);
|
||||||
|
|
||||||
db.secureDB = stronghold;
|
if (!db.secureDB) db.secureDB = stronghold;
|
||||||
|
|
||||||
// save privkey to secure storage
|
// save privkey to secure storage
|
||||||
await db.secureSave(pubkey, privkey);
|
await db.secureSave(pubkey, privkey);
|
||||||
@@ -86,10 +86,16 @@ export function CreateStep2Screen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="mx-auto w-full max-w-md">
|
||||||
<div className="mb-8 text-center">
|
<div className="mb-4 border-b border-white/10 pb-4">
|
||||||
<h1 className="text-xl font-semibold text-white">
|
<h1 className="mb-2 text-center text-2xl font-semibold text-white">
|
||||||
Set password to secure your key
|
Set password to secure your key
|
||||||
</h1>
|
</h1>
|
||||||
|
<p className="text-white/70">
|
||||||
|
Password is not related to your Nostr account. It is only used to secure your
|
||||||
|
keys stored on your local machine and to unlock the app (like unlocking your
|
||||||
|
phone with a passcode). When you move to other Nostr clients, you just need to
|
||||||
|
copy your private key.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-3">
|
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-3">
|
||||||
@@ -98,12 +104,13 @@ export function CreateStep2Screen() {
|
|||||||
<input
|
<input
|
||||||
{...register('password', { required: true })}
|
{...register('password', { required: true })}
|
||||||
type={passwordInput}
|
type={passwordInput}
|
||||||
className="relative h-11 w-full rounded-lg bg-white/10 px-3.5 py-1 text-center text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
placeholder="Enter password"
|
||||||
|
className="relative h-12 w-full rounded-lg border-t border-white/10 bg-white/20 px-3.5 py-1 text-center tracking-widest text-white !outline-none backdrop-blur-xl placeholder:tracking-normal placeholder:text-white/70"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => showPassword()}
|
onClick={() => showPassword()}
|
||||||
className="group absolute right-2 top-1/2 -translate-y-1/2 transform rounded p-1 backdrop-blur-xl hover:bg-white/10"
|
className="group absolute right-2 top-1/2 -translate-y-1/2 transform rounded p-1 backdrop-blur-xl hover:bg-white/20"
|
||||||
>
|
>
|
||||||
{passwordInput === 'password' ? (
|
{passwordInput === 'password' ? (
|
||||||
<EyeOffIcon className="h-4 w-4 text-white/50 group-hover:text-white" />
|
<EyeOffIcon className="h-4 w-4 text-white/50 group-hover:text-white" />
|
||||||
@@ -112,13 +119,6 @@ export function CreateStep2Screen() {
|
|||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-sm text-white/50">
|
|
||||||
<p>
|
|
||||||
Password is use to secure your key store in local machine, when you move
|
|
||||||
to other clients, you just need to copy your private key as nsec or
|
|
||||||
hexstring
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<span className="text-sm text-red-400">
|
<span className="text-sm text-red-400">
|
||||||
{errors.password && <p>{errors.password.message}</p>}
|
{errors.password && <p>{errors.password.message}</p>}
|
||||||
</span>
|
</span>
|
||||||
@@ -127,12 +127,12 @@ export function CreateStep2Screen() {
|
|||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={!isDirty || !isValid}
|
disabled={!isDirty || !isValid}
|
||||||
className="inline-flex h-11 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
className="inline-flex h-12 w-full items-center justify-between gap-2 rounded-lg border-t border-white/10 bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
||||||
>
|
>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<>
|
<>
|
||||||
<span className="w-5" />
|
<span className="w-5" />
|
||||||
<span>Creating...</span>
|
<span>Securing your account...</span>
|
||||||
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { useEffect, useState } from 'react';
|
|||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
import { AvatarUploader } from '@shared/avatarUploader';
|
import { AvatarUploader } from '@shared/avatarUploader';
|
||||||
import { BannerUploader } from '@shared/bannerUploader';
|
import { BannerUploader } from '@shared/bannerUploader';
|
||||||
import { LoaderIcon } from '@shared/icons';
|
import { LoaderIcon } from '@shared/icons';
|
||||||
@@ -10,6 +12,7 @@ import { ArrowRightCircleIcon } from '@shared/icons/arrowRightCircle';
|
|||||||
import { Image } from '@shared/image';
|
import { Image } from '@shared/image';
|
||||||
|
|
||||||
import { useOnboarding } from '@stores/onboarding';
|
import { useOnboarding } from '@stores/onboarding';
|
||||||
|
import { WidgetKinds } from '@stores/widgets';
|
||||||
|
|
||||||
import { useNostr } from '@utils/hooks/useNostr';
|
import { useNostr } from '@utils/hooks/useNostr';
|
||||||
|
|
||||||
@@ -21,6 +24,7 @@ export function CreateStep3Screen() {
|
|||||||
const [picture, setPicture] = useState('https://void.cat/d/5VKmKyuHyxrNMf9bWSVPih');
|
const [picture, setPicture] = useState('https://void.cat/d/5VKmKyuHyxrNMf9bWSVPih');
|
||||||
const [banner, setBanner] = useState('');
|
const [banner, setBanner] = useState('');
|
||||||
|
|
||||||
|
const { db } = useStorage();
|
||||||
const { publish } = useNostr();
|
const { publish } = useNostr();
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
@@ -45,6 +49,9 @@ export function CreateStep3Screen() {
|
|||||||
tags: [],
|
tags: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// create default widget
|
||||||
|
await db.createWidget(WidgetKinds.other.learnNostr, 'Learn Nostr', '');
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
navigate('/auth/onboarding', { replace: true });
|
navigate('/auth/onboarding', { replace: true });
|
||||||
}
|
}
|
||||||
@@ -61,15 +68,22 @@ export function CreateStep3Screen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="mx-auto w-full max-w-md">
|
||||||
<div className="mb-8 text-center">
|
<div className="mb-4 border-b border-white/10 pb-4">
|
||||||
<h1 className="text-xl font-semibold text-white">Create your profile</h1>
|
<h1 className="mb-2 text-center text-2xl font-semibold text-white">
|
||||||
|
Personalize your Nostr profile
|
||||||
|
</h1>
|
||||||
|
<p className="text-white/70">
|
||||||
|
Nostr profile is synchronous across all Nostr clients. If you create a profile
|
||||||
|
on Lume, it will also work well with other Nostr clients. If you update your
|
||||||
|
profile on another Nostr client, it will also sync to Lume.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full overflow-hidden rounded-xl bg-white/10 backdrop-blur-xl">
|
<div className="w-full overflow-hidden rounded-xl bg-white/10 backdrop-blur-xl">
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="mb-0 flex flex-col">
|
<form onSubmit={handleSubmit(onSubmit)} className="mb-0 flex flex-col">
|
||||||
<input type={'hidden'} {...register('picture')} value={picture} />
|
<input type={'hidden'} {...register('picture')} value={picture} />
|
||||||
<input type={'hidden'} {...register('banner')} value={banner} />
|
<input type={'hidden'} {...register('banner')} value={banner} />
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<div className="relative h-44 w-full bg-white/10 backdrop-blur-xl">
|
<div className="relative h-36 w-full bg-white/10 backdrop-blur-xl">
|
||||||
{banner ? (
|
{banner ? (
|
||||||
<Image
|
<Image
|
||||||
src={banner}
|
src={banner}
|
||||||
@@ -77,18 +91,18 @@ export function CreateStep3Screen() {
|
|||||||
className="h-full w-full object-cover"
|
className="h-full w-full object-cover"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="h-full w-full bg-black/50" />
|
<div className="h-full w-full bg-white/20" />
|
||||||
)}
|
)}
|
||||||
<div className="absolute left-1/2 top-1/2 z-10 h-full w-full -translate-x-1/2 -translate-y-1/2 transform">
|
<div className="absolute left-1/2 top-1/2 z-10 h-full w-full -translate-x-1/2 -translate-y-1/2 transform">
|
||||||
<BannerUploader setBanner={setBanner} />
|
<BannerUploader setBanner={setBanner} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mb-5 px-4">
|
<div className="mb-5 px-4">
|
||||||
<div className="relative z-10 -mt-7 h-14 w-14">
|
<div className="relative z-10 -mt-8 h-16 w-16">
|
||||||
<Image
|
<Image
|
||||||
src={picture}
|
src={picture}
|
||||||
alt="user's avatar"
|
alt="user's avatar"
|
||||||
className="h-14 w-14 rounded-lg object-cover ring-2 ring-white/10"
|
className="h-16 w-16 rounded-lg object-cover ring-2 ring-white/20"
|
||||||
/>
|
/>
|
||||||
<div className="absolute left-1/2 top-1/2 z-10 h-full w-full -translate-x-1/2 -translate-y-1/2 transform">
|
<div className="absolute left-1/2 top-1/2 z-10 h-full w-full -translate-x-1/2 -translate-y-1/2 transform">
|
||||||
<AvatarUploader setPicture={setPicture} />
|
<AvatarUploader setPicture={setPicture} />
|
||||||
@@ -98,55 +112,45 @@ export function CreateStep3Screen() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-4 px-4 pb-4">
|
<div className="flex flex-col gap-4 px-4 pb-4">
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<label
|
<label htmlFor="name" className="font-medium text-white">
|
||||||
htmlFor="name"
|
|
||||||
className="text-sm font-semibold uppercase tracking-wider text-white/50"
|
|
||||||
>
|
|
||||||
Name *
|
Name *
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type={'text'}
|
type={'text'}
|
||||||
{...register('name', {
|
{...register('name', {
|
||||||
required: true,
|
required: true,
|
||||||
minLength: 4,
|
minLength: 1,
|
||||||
})}
|
})}
|
||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
className="relative h-11 w-full rounded-lg bg-white/10 px-3 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
className="relative h-12 w-full rounded-lg bg-white/20 px-3 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/70"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<label
|
<label htmlFor="about" className="font-medium text-white">
|
||||||
htmlFor="about"
|
|
||||||
className="text-sm font-semibold uppercase tracking-wider text-white/50"
|
|
||||||
>
|
|
||||||
Bio
|
Bio
|
||||||
</label>
|
</label>
|
||||||
<textarea
|
<textarea
|
||||||
{...register('about')}
|
{...register('about')}
|
||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
className="relative h-20 w-full resize-none rounded-lg bg-white/10 px-3 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
className="relative h-20 w-full resize-none rounded-lg bg-white/20 px-3 py-2 text-white !outline-none backdrop-blur-xl placeholder:text-white/70"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<label
|
<label htmlFor="website" className="font-medium text-white">
|
||||||
htmlFor="website"
|
|
||||||
className="text-sm font-semibold uppercase tracking-wider text-white/50"
|
|
||||||
>
|
|
||||||
Website
|
Website
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type={'text'}
|
|
||||||
{...register('website', {
|
{...register('website', {
|
||||||
required: false,
|
required: false,
|
||||||
})}
|
})}
|
||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
className="relative h-11 w-full rounded-lg bg-white/10 px-3 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
className="relative h-12 w-full rounded-lg bg-white/20 px-3 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/70"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={!isDirty || !isValid}
|
disabled={!isDirty || !isValid}
|
||||||
className="inline-flex h-11 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
className="inline-flex h-12 w-full items-center justify-between gap-2 rounded-lg border-t border-white/10 bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
||||||
>
|
>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
export function HardResetScreen() {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<p>hard reset</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,7 @@ import { useNavigate } from 'react-router-dom';
|
|||||||
|
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
import { LoaderIcon } from '@shared/icons';
|
import { EyeOffIcon, EyeOnIcon, LoaderIcon } from '@shared/icons';
|
||||||
import { ArrowRightCircleIcon } from '@shared/icons/arrowRightCircle';
|
import { ArrowRightCircleIcon } from '@shared/icons/arrowRightCircle';
|
||||||
|
|
||||||
import { useOnboarding } from '@stores/onboarding';
|
import { useOnboarding } from '@stores/onboarding';
|
||||||
@@ -37,6 +37,7 @@ export function ImportStep1Screen() {
|
|||||||
const setStep = useOnboarding((state) => state.setStep);
|
const setStep = useOnboarding((state) => state.setStep);
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [passwordInput, setPasswordInput] = useState('password');
|
||||||
|
|
||||||
const { db } = useStorage();
|
const { db } = useStorage();
|
||||||
const {
|
const {
|
||||||
@@ -64,12 +65,13 @@ export function ImportStep1Screen() {
|
|||||||
setPubkey(pubkey);
|
setPubkey(pubkey);
|
||||||
|
|
||||||
// add account to local database
|
// add account to local database
|
||||||
db.createAccount(npub, pubkey);
|
await db.createAccount(npub, pubkey);
|
||||||
|
|
||||||
// redirect to step 2
|
// redirect to step 2 with delay 1.2s
|
||||||
navigate('/auth/import/step-2', { replace: true });
|
setTimeout(() => navigate('/auth/import/step-2', { replace: true }), 1200);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
setLoading(false);
|
||||||
setError('privkey', {
|
setError('privkey', {
|
||||||
type: 'custom',
|
type: 'custom',
|
||||||
message: 'Private key is invalid, please check again',
|
message: 'Private key is invalid, please check again',
|
||||||
@@ -77,27 +79,53 @@ export function ImportStep1Screen() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// toggle private key
|
||||||
|
const showPassword = () => {
|
||||||
|
if (passwordInput === 'password') {
|
||||||
|
setPasswordInput('text');
|
||||||
|
} else {
|
||||||
|
setPasswordInput('password');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// save current step, if user close app and reopen it
|
// save current step, if user close app and reopen it
|
||||||
setStep('/auth/import/step-1');
|
setStep('/auth/import');
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="mx-auto w-full max-w-md">
|
||||||
<div className="mb-8 text-center">
|
<div className="mb-4 pb-4">
|
||||||
<h1 className="text-xl font-semibold text-white">Import your key</h1>
|
<h1 className="text-center text-2xl font-semibold text-white">
|
||||||
|
Import your Nostr key
|
||||||
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="mb-0 flex flex-col gap-3">
|
<form onSubmit={handleSubmit(onSubmit)} className="mb-0 flex flex-col gap-3">
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<span className="text-base font-semibold text-white/50">Private key</span>
|
<label htmlFor="privkey" className="font-medium text-white">
|
||||||
<input
|
Insert your nostr private key, in nsec or hex format
|
||||||
{...register('privkey', { required: true, minLength: 32 })}
|
</label>
|
||||||
type={'password'}
|
<div className="relative">
|
||||||
placeholder="nsec or hexstring"
|
<input
|
||||||
className="relative h-11 w-full rounded-lg bg-white/10 px-3 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
{...register('privkey', { required: true, minLength: 32 })}
|
||||||
/>
|
type={passwordInput}
|
||||||
<span className="text-sm text-red-400">
|
placeholder="nsec1..."
|
||||||
|
className="relative h-12 w-full rounded-lg border-t border-white/10 bg-white/20 px-3 py-1 text-white backdrop-blur-xl placeholder:text-white/70 focus:outline-none"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => showPassword()}
|
||||||
|
className="group absolute right-2 top-1/2 -translate-y-1/2 transform rounded p-1 backdrop-blur-xl hover:bg-white/20"
|
||||||
|
>
|
||||||
|
{passwordInput === 'password' ? (
|
||||||
|
<EyeOffIcon className="h-4 w-4 text-white/50 group-hover:text-white" />
|
||||||
|
) : (
|
||||||
|
<EyeOnIcon className="h-4 w-4 text-white/50 group-hover:text-white" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<span className="text-sm text-red-500">
|
||||||
{errors.privkey && <p>{errors.privkey.message}</p>}
|
{errors.privkey && <p>{errors.privkey.message}</p>}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -105,12 +133,12 @@ export function ImportStep1Screen() {
|
|||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={!isDirty || !isValid}
|
disabled={!isDirty || !isValid}
|
||||||
className="inline-flex h-11 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
className="inline-flex h-12 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
||||||
>
|
>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<>
|
<>
|
||||||
<span className="w-5" />
|
<span className="w-5" />
|
||||||
<span>Creating...</span>
|
<span>Importing...</span>
|
||||||
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ export function ImportStep2Screen() {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
if (data.password.length > 3) {
|
if (data.password.length > 3) {
|
||||||
const dir = await appConfigDir();
|
const dir = await appConfigDir();
|
||||||
const stronghold = await Stronghold.load(`${dir}/lume.stronghold`, data.password);
|
const stronghold = await Stronghold.load(`${dir}lume.stronghold`, data.password);
|
||||||
|
|
||||||
db.secureDB = stronghold;
|
if (!db.secureDB) db.secureDB = stronghold;
|
||||||
|
|
||||||
// save privkey to secure storage
|
// save privkey to secure storage
|
||||||
await db.secureSave(pubkey, privkey);
|
await db.secureSave(pubkey, privkey);
|
||||||
@@ -86,10 +86,16 @@ export function ImportStep2Screen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="mx-auto w-full max-w-md">
|
||||||
<div className="mb-8 text-center">
|
<div className="mb-4 border-b border-white/10 pb-4">
|
||||||
<h1 className="text-xl font-semibold text-white">
|
<h1 className="mb-2 text-center text-2xl font-semibold text-white">
|
||||||
Set password to secure your key
|
Set password to secure your key
|
||||||
</h1>
|
</h1>
|
||||||
|
<p className="text-white/70">
|
||||||
|
Password is not related to your Nostr account. It is only used to secure your
|
||||||
|
keys stored on your local machine and to unlock the app (like unlocking your
|
||||||
|
phone with a passcode). When you move to other Nostr clients, you only need to
|
||||||
|
copy your private key.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-3">
|
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-3">
|
||||||
@@ -98,12 +104,13 @@ export function ImportStep2Screen() {
|
|||||||
<input
|
<input
|
||||||
{...register('password', { required: true })}
|
{...register('password', { required: true })}
|
||||||
type={passwordInput}
|
type={passwordInput}
|
||||||
className="relative h-11 w-full rounded-lg bg-white/10 px-3.5 py-1 text-center text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
placeholder="Enter password"
|
||||||
|
className="relative h-12 w-full rounded-lg border-t border-white/10 bg-white/20 px-3.5 py-1 text-center tracking-widest text-white !outline-none backdrop-blur-xl placeholder:tracking-normal placeholder:text-white/70"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => showPassword()}
|
onClick={() => showPassword()}
|
||||||
className="group absolute right-2 top-1/2 -translate-y-1/2 transform rounded p-1 backdrop-blur-xl hover:bg-white/10"
|
className="group absolute right-2 top-1/2 -translate-y-1/2 transform rounded p-1 backdrop-blur-xl hover:bg-white/20"
|
||||||
>
|
>
|
||||||
{passwordInput === 'password' ? (
|
{passwordInput === 'password' ? (
|
||||||
<EyeOffIcon className="h-4 w-4 text-white/50 group-hover:text-white" />
|
<EyeOffIcon className="h-4 w-4 text-white/50 group-hover:text-white" />
|
||||||
@@ -112,11 +119,6 @@ export function ImportStep2Screen() {
|
|||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-sm text-white/50">
|
|
||||||
Password is use to unlock app and secure your key store in local machine.
|
|
||||||
When you move to other clients, you just need to copy your private key as
|
|
||||||
nsec or hexstring
|
|
||||||
</p>
|
|
||||||
<span className="text-sm text-red-400">
|
<span className="text-sm text-red-400">
|
||||||
{errors.password && <p>{errors.password.message}</p>}
|
{errors.password && <p>{errors.password.message}</p>}
|
||||||
</span>
|
</span>
|
||||||
@@ -125,12 +127,12 @@ export function ImportStep2Screen() {
|
|||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={!isDirty || !isValid}
|
disabled={!isDirty || !isValid}
|
||||||
className="inline-flex h-11 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
className="inline-flex h-12 w-full items-center justify-between gap-2 rounded-lg border-t border-white/10 bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
||||||
>
|
>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<>
|
<>
|
||||||
<span className="w-5" />
|
<span className="w-5" />
|
||||||
<span>Creating...</span>
|
<span>Securing your account...</span>
|
||||||
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { User } from '@app/auth/components/user';
|
|
||||||
|
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
import { ArrowRightCircleIcon, LoaderIcon } from '@shared/icons';
|
import { ArrowRightCircleIcon, LoaderIcon } from '@shared/icons';
|
||||||
|
import { User } from '@shared/user';
|
||||||
|
|
||||||
import { useOnboarding } from '@stores/onboarding';
|
import { useOnboarding } from '@stores/onboarding';
|
||||||
|
import { WidgetKinds } from '@stores/widgets';
|
||||||
|
|
||||||
import { useNostr } from '@utils/hooks/useNostr';
|
import { useNostr } from '@utils/hooks/useNostr';
|
||||||
|
|
||||||
@@ -15,10 +15,10 @@ export function ImportStep3Screen() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const setStep = useOnboarding((state) => state.setStep);
|
const setStep = useOnboarding((state) => state.setStep);
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
|
|
||||||
const { db } = useStorage();
|
const { db } = useStorage();
|
||||||
const { fetchUserData, prefetchEvents } = useNostr();
|
const { fetchUserData } = useNostr();
|
||||||
|
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -27,13 +27,14 @@ export function ImportStep3Screen() {
|
|||||||
|
|
||||||
// prefetch data
|
// prefetch data
|
||||||
const user = await fetchUserData();
|
const user = await fetchUserData();
|
||||||
const data = await prefetchEvents();
|
|
||||||
|
// create default widget
|
||||||
|
await db.createWidget(WidgetKinds.other.learnNostr, 'Learn Nostr', '');
|
||||||
|
|
||||||
// redirect to next step
|
// redirect to next step
|
||||||
if (user.status === 'ok' && data.status === 'ok') {
|
if (user.status === 'ok') {
|
||||||
navigate('/auth/onboarding/step-2', { replace: true });
|
navigate('/auth/onboarding/step-2', { replace: true });
|
||||||
} else {
|
} else {
|
||||||
console.log('error: ', data.message);
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -49,17 +50,19 @@ export function ImportStep3Screen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="mx-auto w-full max-w-md">
|
||||||
<div className="mb-8 text-center">
|
<div className="mb-4 pb-4">
|
||||||
<h1 className="text-xl font-semibold">
|
<h1 className="text-center text-2xl font-semibold text-white">
|
||||||
{loading ? 'Prefetching data...' : 'Continue with'}
|
{loading ? 'Downloading...' : 'Your Nostr profile'}
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full rounded-xl bg-white/10 p-4 backdrop-blur-xl">
|
<div className="flex flex-col gap-3">
|
||||||
<div className="flex flex-col gap-3">
|
<div className="rounded-lg border-t border-white/10 bg-white/20 px-3 py-3">
|
||||||
<User pubkey={db.account.pubkey} />
|
<User pubkey={db.account.pubkey} variant="simple" />
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="inline-flex h-11 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
className="inline-flex h-12 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
||||||
onClick={() => submit()}
|
onClick={() => submit()}
|
||||||
>
|
>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
@@ -76,6 +79,10 @@ export function ImportStep3Screen() {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
|
<span className="text-center text-sm text-white/50">
|
||||||
|
By clicking 'Continue', Lume will download your old relay list and
|
||||||
|
metadata. It may take a bit
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
10
src/app/auth/lock.tsx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
export function LockScreen() {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="h-full w-full bg-cover bg-center"
|
||||||
|
style={{ backgroundImage: 'url(/wallpapers/1.png)' }}
|
||||||
|
>
|
||||||
|
<p>TODO</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,11 +2,10 @@ import { useQuery } from '@tanstack/react-query';
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Link, useNavigate } from 'react-router-dom';
|
import { Link, useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { User } from '@app/auth/components/user';
|
|
||||||
|
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
import { ArrowRightCircleIcon, CheckCircleIcon, LoaderIcon } from '@shared/icons';
|
import { ArrowRightCircleIcon, CheckCircleIcon, LoaderIcon } from '@shared/icons';
|
||||||
|
import { User } from '@shared/user';
|
||||||
|
|
||||||
import { useOnboarding } from '@stores/onboarding';
|
import { useOnboarding } from '@stores/onboarding';
|
||||||
|
|
||||||
@@ -17,9 +16,9 @@ export function OnboardStep1Screen() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const setStep = useOnboarding((state) => state.setStep);
|
const setStep = useOnboarding((state) => state.setStep);
|
||||||
|
|
||||||
const { publish, fetchUserData, prefetchEvents } = useNostr();
|
const { publish, fetchUserData } = useNostr();
|
||||||
const { db } = useStorage();
|
const { db } = useStorage();
|
||||||
const { status, data } = useQuery(['trending-profiles'], async () => {
|
const { status, data } = useQuery(['trending-profiles-widget'], async () => {
|
||||||
const res = await fetch('https://api.nostr.band/v0/trending/profiles');
|
const res = await fetch('https://api.nostr.band/v0/trending/profiles');
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error('Error');
|
throw new Error('Error');
|
||||||
@@ -47,14 +46,12 @@ export function OnboardStep1Screen() {
|
|||||||
|
|
||||||
// prefetch data
|
// prefetch data
|
||||||
const user = await fetchUserData(follows);
|
const user = await fetchUserData(follows);
|
||||||
const data = await prefetchEvents();
|
|
||||||
|
|
||||||
// redirect to next step
|
// redirect to next step
|
||||||
if (event && user.status === 'ok' && data.status === 'ok') {
|
if (event && user.status === 'ok') {
|
||||||
navigate('/auth/onboarding/step-2', { replace: true });
|
navigate('/auth/onboarding/step-2', { replace: true });
|
||||||
} else {
|
} else {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
console.log('error: ', data.message);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -68,45 +65,51 @@ export function OnboardStep1Screen() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="flex h-full w-full flex-col justify-center">
|
||||||
<div className="mb-8 text-center">
|
<div className="mx-auto mb-4 w-full max-w-md border-b border-white/10 pb-4">
|
||||||
<h1 className="text-xl font-semibold text-white">
|
<h1 className="mb-2 text-center text-2xl font-semibold text-white">
|
||||||
{loading ? 'Prefetching data...' : 'Enrich your network'}
|
{loading ? 'Loading...' : 'Enrich your network'}
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-sm text-white/50">Choose account you want to follow</p>
|
<p className="text-white/70">
|
||||||
|
Choose the account you want to follow. These accounts are trending in the last
|
||||||
|
24 hours. If none of the accounts interest you, you can explore more options and
|
||||||
|
add them later.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="scrollbar-hide flex w-full flex-nowrap items-center gap-4 overflow-x-auto px-4">
|
||||||
<div className="scrollbar-hide flex h-[500px] w-full flex-col overflow-y-auto rounded-xl bg-white/10 py-2 backdrop-blur-xl">
|
{status === 'loading' ? (
|
||||||
{status === 'loading' ? (
|
<div className="flex h-full w-full items-center justify-center">
|
||||||
<div className="flex h-full w-full items-center justify-center">
|
<LoaderIcon className="h-4 w-4 animate-spin text-white" />
|
||||||
<LoaderIcon className="h-4 w-4 animate-spin text-white" />
|
</div>
|
||||||
</div>
|
) : (
|
||||||
) : (
|
data?.profiles.map((item: { pubkey: string; profile: { content: string } }) => (
|
||||||
data?.profiles.map(
|
<button
|
||||||
(item: { pubkey: string; profile: { content: string } }) => (
|
key={item.pubkey}
|
||||||
<button
|
type="button"
|
||||||
key={item.pubkey}
|
onClick={() => toggleFollow(item.pubkey)}
|
||||||
type="button"
|
className="relative h-[300px] shrink-0 grow-0 basis-[250px] rounded-lg border-t border-white/10 bg-white/20 px-4 py-4 hover:bg-white/30"
|
||||||
onClick={() => toggleFollow(item.pubkey)}
|
>
|
||||||
className="inline-flex transform items-center justify-between px-4 py-2 hover:bg-white/20"
|
<User
|
||||||
>
|
pubkey={item.pubkey}
|
||||||
<User pubkey={item.pubkey} fallback={item.profile?.content} />
|
variant="large"
|
||||||
{follows.includes(item.pubkey) && (
|
embedProfile={item.profile?.content}
|
||||||
<div>
|
/>
|
||||||
<CheckCircleIcon className="h-4 w-4 text-green-400" />
|
{follows.includes(item.pubkey) && (
|
||||||
</div>
|
<div className="absolute right-2 top-2">
|
||||||
)}
|
<CheckCircleIcon className="h-4 w-4 text-green-400" />
|
||||||
</button>
|
</div>
|
||||||
)
|
)}
|
||||||
)
|
</button>
|
||||||
)}
|
))
|
||||||
</div>
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="mx-auto mt-4 w-full max-w-md">
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
disabled={loading || follows.length === 0}
|
disabled={loading || follows.length === 0}
|
||||||
className="inline-flex h-11 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none disabled:opacity-50"
|
className="inline-flex h-12 w-full items-center justify-between gap-2 rounded-lg border-t border-white/10 bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none disabled:opacity-50"
|
||||||
>
|
>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<>
|
<>
|
||||||
@@ -124,7 +127,7 @@ export function OnboardStep1Screen() {
|
|||||||
</button>
|
</button>
|
||||||
<Link
|
<Link
|
||||||
to="/auth/onboarding/step-2"
|
to="/auth/onboarding/step-2"
|
||||||
className="inline-flex h-11 w-full items-center justify-center rounded-lg px-6 font-medium leading-none text-white backdrop-blur-xl hover:bg-white/10 focus:outline-none"
|
className="inline-flex h-12 w-full items-center justify-center rounded-lg border-t border-white/10 bg-white/20 px-6 font-medium leading-none text-white backdrop-blur-xl hover:bg-white/30 focus:outline-none"
|
||||||
>
|
>
|
||||||
Skip, you can add later
|
Skip, you can add later
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import { message } from '@tauri-apps/api/dialog';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Link, useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ import { WidgetKinds } from '@stores/widgets';
|
|||||||
const data = [
|
const data = [
|
||||||
{ hashtag: '#bitcoin' },
|
{ hashtag: '#bitcoin' },
|
||||||
{ hashtag: '#nostr' },
|
{ hashtag: '#nostr' },
|
||||||
|
{ hashtag: '#nostrdesign' },
|
||||||
{ hashtag: '#zap' },
|
{ hashtag: '#zap' },
|
||||||
{ hashtag: '#LFG' },
|
{ hashtag: '#LFG' },
|
||||||
{ hashtag: '#zapchain' },
|
{ hashtag: '#zapchain' },
|
||||||
@@ -19,6 +21,10 @@ const data = [
|
|||||||
{ hashtag: '#hodl' },
|
{ hashtag: '#hodl' },
|
||||||
{ hashtag: '#stacksats' },
|
{ hashtag: '#stacksats' },
|
||||||
{ hashtag: '#nokyc' },
|
{ hashtag: '#nokyc' },
|
||||||
|
{ hashtag: '#meme' },
|
||||||
|
{ hashtag: '#memes' },
|
||||||
|
{ hashtag: '#memestr' },
|
||||||
|
{ hashtag: '#penisbutter' },
|
||||||
{ hashtag: '#anime' },
|
{ hashtag: '#anime' },
|
||||||
{ hashtag: '#waifu' },
|
{ hashtag: '#waifu' },
|
||||||
{ hashtag: '#manga' },
|
{ hashtag: '#manga' },
|
||||||
@@ -28,8 +34,8 @@ const data = [
|
|||||||
|
|
||||||
export function OnboardStep2Screen() {
|
export function OnboardStep2Screen() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const setStep = useOnboarding((state) => state.setStep);
|
|
||||||
|
|
||||||
|
const [setStep, clearStep] = useOnboarding((state) => [state.setStep, state.clearStep]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [tags, setTags] = useState(new Set<string>());
|
const [tags, setTags] = useState(new Set<string>());
|
||||||
|
|
||||||
@@ -47,17 +53,34 @@ export function OnboardStep2Screen() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const skip = async () => {
|
||||||
|
// update last login
|
||||||
|
await db.updateLastLogin();
|
||||||
|
|
||||||
|
// clear local storage
|
||||||
|
clearStep();
|
||||||
|
|
||||||
|
navigate('/auth/complete', { replace: true });
|
||||||
|
};
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
for (const tag of tags) {
|
for (const tag of tags) {
|
||||||
await db.createWidget(WidgetKinds.hashtag, tag, tag.replace('#', ''));
|
await db.createWidget(WidgetKinds.global.hashtag, tag, tag.replace('#', ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
navigate('/auth/onboarding/step-3', { replace: true });
|
// update last login
|
||||||
} catch {
|
await db.updateLastLogin();
|
||||||
console.log('error');
|
|
||||||
|
// clear local storage
|
||||||
|
clearStep();
|
||||||
|
|
||||||
|
navigate('/auth/complete', { replace: true });
|
||||||
|
} catch (e) {
|
||||||
|
setLoading(false);
|
||||||
|
await message(e, { title: 'Lume', type: 'error' });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -68,20 +91,23 @@ export function OnboardStep2Screen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="mx-auto w-full max-w-md">
|
||||||
<div className="mb-8 text-center">
|
<div className="mb-4 border-b border-white/10 pb-4">
|
||||||
<h1 className="text-xl font-semibold text-white">
|
<h1 className="mb-2 text-center text-2xl font-semibold text-white">
|
||||||
Choose {tags.size}/3 your favorite tags
|
Choose {tags.size}/3 your favorite hashtags
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-sm text-white/50">Customize your space which hashtag widget</p>
|
<p className="text-white/70">
|
||||||
|
Hashtags are an easy way to discover more content. By adding a hashtag, Lume
|
||||||
|
will show all related posts. You can always add more later.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<div className="scrollbar-hide flex h-[500px] w-full flex-col overflow-y-auto rounded-xl bg-white/10 backdrop-blur-xl">
|
<div className="scrollbar-hide flex h-[450px] w-full flex-col divide-y divide-white/5 overflow-y-auto rounded-xl bg-white/20 backdrop-blur-xl">
|
||||||
{data.map((item: { hashtag: string }) => (
|
{data.map((item: { hashtag: string }) => (
|
||||||
<button
|
<button
|
||||||
key={item.hashtag}
|
key={item.hashtag}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => toggleTag(item.hashtag)}
|
onClick={() => toggleTag(item.hashtag)}
|
||||||
className="inline-flex transform items-center justify-between bg-white/10 px-4 py-2 backdrop-blur-xl hover:bg-white/20"
|
className="inline-flex transform items-center justify-between px-4 py-2 hover:bg-white/10"
|
||||||
>
|
>
|
||||||
<p className="text-white">{item.hashtag}</p>
|
<p className="text-white">{item.hashtag}</p>
|
||||||
{tags.has(item.hashtag) && (
|
{tags.has(item.hashtag) && (
|
||||||
@@ -97,7 +123,7 @@ export function OnboardStep2Screen() {
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
disabled={loading || tags.size === 0 || tags.size > 3}
|
disabled={loading || tags.size === 0 || tags.size > 3}
|
||||||
className="inline-flex h-11 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none disabled:opacity-50"
|
className="inline-flex h-12 w-full items-center justify-between gap-2 rounded-lg border-t border-white/10 bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none disabled:opacity-50"
|
||||||
>
|
>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<>
|
<>
|
||||||
@@ -113,12 +139,15 @@ export function OnboardStep2Screen() {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
<Link
|
{!loading ? (
|
||||||
to="/auth/onboarding/step-3"
|
<button
|
||||||
className="inline-flex h-11 w-full items-center justify-center rounded-lg px-6 font-medium leading-none text-white backdrop-blur-xl hover:bg-white/10 focus:outline-none"
|
type="button"
|
||||||
>
|
onClick={() => skip()}
|
||||||
Skip, you can add later
|
className="inline-flex h-12 w-full items-center justify-center rounded-lg border-t border-white/10 bg-white/20 font-medium leading-none text-white backdrop-blur-xl hover:bg-white/30 focus:outline-none"
|
||||||
</Link>
|
>
|
||||||
|
Skip, you can add later
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,12 +2,11 @@ import { useQuery } from '@tanstack/react-query';
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { UserRelay } from '@app/auth/components/userRelay';
|
|
||||||
|
|
||||||
import { useNDK } from '@libs/ndk/provider';
|
import { useNDK } from '@libs/ndk/provider';
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
import { ArrowRightCircleIcon, CheckCircleIcon, LoaderIcon } from '@shared/icons';
|
import { ArrowRightCircleIcon, CheckCircleIcon, LoaderIcon } from '@shared/icons';
|
||||||
|
import { User } from '@shared/user';
|
||||||
|
|
||||||
import { FULL_RELAYS } from '@stores/constants';
|
import { FULL_RELAYS } from '@stores/constants';
|
||||||
import { useOnboarding } from '@stores/onboarding';
|
import { useOnboarding } from '@stores/onboarding';
|
||||||
@@ -49,6 +48,8 @@ export function OnboardStep3Screen() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const relaysAsArray = Array.from(data?.keys() || []);
|
||||||
|
|
||||||
const toggleRelay = (relay: string) => {
|
const toggleRelay = (relay: string) => {
|
||||||
if (relays.has(relay)) {
|
if (relays.has(relay)) {
|
||||||
setRelays((prev) => {
|
setRelays((prev) => {
|
||||||
@@ -61,8 +62,9 @@ export function OnboardStep3Screen() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const submit = async (skip?: boolean) => {
|
const submit = async (skip?: boolean) => {
|
||||||
setLoading(true);
|
|
||||||
try {
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
if (!skip) {
|
if (!skip) {
|
||||||
for (const relay of relays) {
|
for (const relay of relays) {
|
||||||
await db.createRelay(relay);
|
await db.createRelay(relay);
|
||||||
@@ -87,8 +89,6 @@ export function OnboardStep3Screen() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const relaysAsArray = Array.from(data?.keys() || []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// save current step, if user close app and reopen it
|
// save current step, if user close app and reopen it
|
||||||
setStep('/auth/onboarding/step-3');
|
setStep('/auth/onboarding/step-3');
|
||||||
@@ -118,10 +118,11 @@ export function OnboardStep3Screen() {
|
|||||||
<LoaderIcon className="h-4 w-4 animate-spin text-white" />
|
<LoaderIcon className="h-4 w-4 animate-spin text-white" />
|
||||||
</div>
|
</div>
|
||||||
) : relaysAsArray.length === 0 ? (
|
) : relaysAsArray.length === 0 ? (
|
||||||
<div className="flex h-full w-full items-center justify-center">
|
<div className="flex h-full w-full items-center justify-center px-6">
|
||||||
<p className="text-center text-white/50">
|
<p className="text-center text-white/50">
|
||||||
Can't found any relays, you can skip this step and use default relays
|
Lume couldn't find any relays from your follows.
|
||||||
instead
|
<br />
|
||||||
|
You can skip this step and use default relays instead.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
@@ -134,7 +135,7 @@ export function OnboardStep3Screen() {
|
|||||||
>
|
>
|
||||||
<div className="flex flex-col items-start gap-1">
|
<div className="flex flex-col items-start gap-1">
|
||||||
<p className="max-w-[15rem] truncate">{item.replace(/\/+$/, '')}</p>
|
<p className="max-w-[15rem] truncate">{item.replace(/\/+$/, '')}</p>
|
||||||
<UserRelay pubkey={data.get(item)} />
|
<User pubkey={data.get(item)} variant="mention" />
|
||||||
</div>
|
</div>
|
||||||
{relays.has(item) && (
|
{relays.has(item) && (
|
||||||
<div className="pt-1.5">
|
<div className="pt-1.5">
|
||||||
@@ -145,7 +146,7 @@ export function OnboardStep3Screen() {
|
|||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
{relays.size > 5 && (
|
{relays.size > 5 && (
|
||||||
<div className="sticky bottom-0 left-0 inline-flex w-full items-center justify-center bg-white/10 px-4 py-2 backdrop-blur-2xl backdrop-blur-xl">
|
<div className="sticky bottom-0 left-0 inline-flex w-full items-center justify-center bg-white/10 px-4 py-2 backdrop-blur-2xl">
|
||||||
<p className="text-sm text-orange-400">
|
<p className="text-sm text-orange-400">
|
||||||
Using too much relay can cause high resource usage
|
Using too much relay can cause high resource usage
|
||||||
</p>
|
</p>
|
||||||
@@ -178,7 +179,7 @@ export function OnboardStep3Screen() {
|
|||||||
onClick={() => submit(true)}
|
onClick={() => submit(true)}
|
||||||
className="inline-flex h-11 w-full items-center justify-center rounded-lg px-6 font-medium leading-none text-white backdrop-blur-xl hover:bg-white/10 focus:outline-none"
|
className="inline-flex h-11 w-full items-center justify-center rounded-lg px-6 font-medium leading-none text-white backdrop-blur-xl hover:bg-white/10 focus:outline-none"
|
||||||
>
|
>
|
||||||
Skip, use default relays
|
Skip, use Lume default relays
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -116,28 +116,28 @@ export function ResetScreen() {
|
|||||||
</div>
|
</div>
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="mb-0 flex flex-col gap-3">
|
<form onSubmit={handleSubmit(onSubmit)} className="mb-0 flex flex-col gap-3">
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<label htmlFor="privkey" className="font-medium text-white/50">
|
<label htmlFor="privkey" className="font-medium text-white">
|
||||||
Private key
|
Private key
|
||||||
</label>
|
</label>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<input
|
<input
|
||||||
{...register('privkey', { required: true })}
|
{...register('privkey', { required: true })}
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="nsec..."
|
placeholder="nsec1..."
|
||||||
className="relative h-12 w-full rounded-lg bg-white/10 px-3.5 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
className="relative h-12 w-full rounded-lg border-t border-white/10 bg-white/20 px-3.5 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/70"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<label htmlFor="password" className="font-medium text-white/50">
|
<label htmlFor="password" className="font-medium text-white">
|
||||||
Set a new password to protect your key
|
Set a new password to protect your key
|
||||||
</label>
|
</label>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<input
|
<input
|
||||||
{...register('password', { required: true })}
|
{...register('password', { required: true })}
|
||||||
type={passwordInput}
|
type={passwordInput}
|
||||||
placeholder="min. 4 characters"
|
placeholder="Min. 4 characters"
|
||||||
className="relative h-12 w-full rounded-lg bg-white/10 px-3.5 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
className="relative h-12 w-full rounded-lg border-t border-white/10 bg-white/20 px-3.5 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/70"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -169,7 +169,7 @@ export function ResetScreen() {
|
|||||||
</button>
|
</button>
|
||||||
<Link
|
<Link
|
||||||
to="/auth/unlock"
|
to="/auth/unlock"
|
||||||
className="mt-1 inline-flex h-11 w-full items-center justify-center rounded-lg text-center text-white/50 hover:bg-white/10"
|
className="mt-1 inline-flex h-12 w-full items-center justify-center rounded-lg text-center text-white/70 hover:bg-white/20"
|
||||||
>
|
>
|
||||||
Back
|
Back
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ import { Resolver, useForm } from 'react-hook-form';
|
|||||||
import { Link, useNavigate } from 'react-router-dom';
|
import { Link, useNavigate } from 'react-router-dom';
|
||||||
import { Stronghold } from 'tauri-plugin-stronghold-api';
|
import { Stronghold } from 'tauri-plugin-stronghold-api';
|
||||||
|
|
||||||
import { User } from '@app/auth/components/user';
|
|
||||||
|
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
import { ArrowRightCircleIcon, EyeOffIcon, EyeOnIcon, LoaderIcon } from '@shared/icons';
|
import { ArrowRightCircleIcon, EyeOffIcon, EyeOnIcon, LoaderIcon } from '@shared/icons';
|
||||||
|
import { User } from '@shared/user';
|
||||||
|
|
||||||
import { useStronghold } from '@stores/stronghold';
|
import { useStronghold } from '@stores/stronghold';
|
||||||
|
|
||||||
@@ -33,6 +32,8 @@ const resolver: Resolver<FormValues> = async (values) => {
|
|||||||
export function UnlockScreen() {
|
export function UnlockScreen() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const setPrivkey = useStronghold((state) => state.setPrivkey);
|
const setPrivkey = useStronghold((state) => state.setPrivkey);
|
||||||
|
const setWalletConnectURL = useStronghold((state) => state.setWalletConnectURL);
|
||||||
|
const resetStronghold = useStronghold((state) => state.reset);
|
||||||
|
|
||||||
const [showPassword, setShowPassword] = useState<boolean>(false);
|
const [showPassword, setShowPassword] = useState<boolean>(false);
|
||||||
const [loading, setLoading] = useState<boolean>(false);
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
@@ -55,8 +56,10 @@ export function UnlockScreen() {
|
|||||||
if (!db.secureDB) db.secureDB = stronghold;
|
if (!db.secureDB) db.secureDB = stronghold;
|
||||||
|
|
||||||
const privkey = await db.secureLoad(db.account.pubkey);
|
const privkey = await db.secureLoad(db.account.pubkey);
|
||||||
|
const uri = await db.secureLoad('walletConnectURL', 'nwc');
|
||||||
|
|
||||||
setPrivkey(privkey);
|
if (privkey) setPrivkey(privkey);
|
||||||
|
if (uri) setWalletConnectURL(uri);
|
||||||
// redirect to home
|
// redirect to home
|
||||||
navigate('/', { replace: true });
|
navigate('/', { replace: true });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -68,23 +71,34 @@ export function UnlockScreen() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const logout = async () => {
|
||||||
|
// remove account
|
||||||
|
db.accountLogout();
|
||||||
|
// reset stronghold
|
||||||
|
resetStronghold();
|
||||||
|
// redirect to welcome screen
|
||||||
|
navigate('/auth/welcome');
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-full w-full items-center justify-center">
|
<div className="flex h-full w-full items-center justify-center">
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="mx-auto w-full max-w-md">
|
||||||
<div className="mb-6 text-center">
|
<div className="mb-4 pb-4">
|
||||||
<h1 className="text-2xl font-semibold text-white">Enter password to unlock</h1>
|
<h1 className="text-center text-2xl font-semibold text-white">
|
||||||
|
Enter password to unlock
|
||||||
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="mb-0 flex flex-col">
|
<form onSubmit={handleSubmit(onSubmit)} className="mb-0 flex flex-col">
|
||||||
<div className="flex flex-col rounded-lg bg-white/5">
|
<div className="flex flex-col rounded-lg bg-white/5">
|
||||||
<div className="w-full rounded-t-lg border-b border-white/10 bg-white/5 p-4">
|
<div className="w-full rounded-t-lg border-b border-white/10 bg-white/5 p-4">
|
||||||
<User pubkey={db.account.pubkey} />
|
<User pubkey={db.account.pubkey} variant="simple" />
|
||||||
</div>
|
</div>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<input
|
<input
|
||||||
{...register('password', { required: true, minLength: 4 })}
|
{...register('password', { required: true, minLength: 4 })}
|
||||||
type={showPassword ? 'text' : 'password'}
|
type={showPassword ? 'text' : 'password'}
|
||||||
placeholder="Password"
|
placeholder="Password"
|
||||||
className="relative h-12 w-full rounded-b-lg bg-white/10 py-1 text-center text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
className="relative h-12 w-full rounded-b-lg bg-white/10 py-1 text-center tracking-widest text-white !outline-none backdrop-blur-xl placeholder:tracking-normal placeholder:text-white/50"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -106,12 +120,12 @@ export function UnlockScreen() {
|
|||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={!isDirty || !isValid}
|
disabled={!isDirty || !isValid}
|
||||||
className="inline-flex h-11 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none disabled:opacity-50"
|
className="inline-flex h-12 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none disabled:opacity-50"
|
||||||
>
|
>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<>
|
<>
|
||||||
<span className="w-5" />
|
<span className="w-5" />
|
||||||
<span>Decryting...</span>
|
<span>Unlocking...</span>
|
||||||
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
@@ -122,12 +136,30 @@ export function UnlockScreen() {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
<Link
|
<div className="mt-8 w-full">
|
||||||
to="/auth/reset"
|
<div className="flex items-center gap-2.5">
|
||||||
className="mt-1 inline-flex h-11 w-full items-center justify-center rounded-lg text-center text-white/50 hover:bg-white/10"
|
<div className="h-px flex-1 bg-white/10" />
|
||||||
>
|
<p className="shrink-0 text-sm font-medium text-white/50">
|
||||||
Reset password
|
Forgot password?
|
||||||
</Link>
|
</p>
|
||||||
|
<div className="h-px flex-1 bg-white/10" />
|
||||||
|
</div>
|
||||||
|
<div className="mt-2 flex flex-col">
|
||||||
|
<Link
|
||||||
|
to="/auth/reset"
|
||||||
|
className="inline-flex h-10 w-full items-center justify-center rounded-lg text-center text-sm font-medium text-white/70 hover:bg-white/20"
|
||||||
|
>
|
||||||
|
Reset password if you still have a private key
|
||||||
|
</Link>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={logout}
|
||||||
|
className="inline-flex h-10 w-full items-center justify-center rounded-lg text-center text-sm font-medium text-white/70 hover:bg-white/20"
|
||||||
|
>
|
||||||
|
Login with another account
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,35 +1,10 @@
|
|||||||
import { LogicalSize, getCurrent } from '@tauri-apps/api/window';
|
|
||||||
import { useEffect } from 'react';
|
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import { Frame } from '@shared/frame';
|
|
||||||
import { ArrowRightCircleIcon } from '@shared/icons/arrowRightCircle';
|
import { ArrowRightCircleIcon } from '@shared/icons/arrowRightCircle';
|
||||||
|
|
||||||
export function WelcomeScreen() {
|
export function WelcomeScreen() {
|
||||||
const appWindow = getCurrent();
|
|
||||||
|
|
||||||
async function setWindow() {
|
|
||||||
await appWindow.setSize(new LogicalSize(400, 500));
|
|
||||||
await appWindow.setResizable(false);
|
|
||||||
await appWindow.center();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function resetWindow() {
|
|
||||||
await appWindow.setSize(new LogicalSize(1080, 800));
|
|
||||||
await appWindow.setResizable(false);
|
|
||||||
await appWindow.center();
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setWindow();
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
resetWindow();
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Frame className="flex h-screen w-full flex-col justify-between">
|
<div className="mx-auto flex h-screen w-full max-w-md flex-col justify-center">
|
||||||
<div className="flex flex-col gap-10 pt-16">
|
<div className="flex flex-col gap-10 pt-16">
|
||||||
<div className="flex flex-col gap-1.5 text-center">
|
<div className="flex flex-col gap-1.5 text-center">
|
||||||
<h1 className="text-3xl font-semibold text-white">Welcome to Lume</h1>
|
<h1 className="text-3xl font-semibold text-white">Welcome to Lume</h1>
|
||||||
@@ -38,10 +13,10 @@ export function WelcomeScreen() {
|
|||||||
Nostr
|
Nostr
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="inline-flex w-full flex-col items-center gap-2 px-4 pb-10">
|
<div className="inline-flex w-full flex-col items-center gap-3 px-4 pb-10">
|
||||||
<Link
|
<Link
|
||||||
to="/auth/import"
|
to="/auth/import"
|
||||||
className="inline-flex h-11 w-2/3 items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
className="inline-flex h-12 w-3/4 items-center justify-between gap-2 rounded-lg border-t border-white/10 bg-fuchsia-500 px-4 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
||||||
>
|
>
|
||||||
<span className="w-5" />
|
<span className="w-5" />
|
||||||
<span>Login with private key</span>
|
<span>Login with private key</span>
|
||||||
@@ -49,15 +24,15 @@ export function WelcomeScreen() {
|
|||||||
</Link>
|
</Link>
|
||||||
<Link
|
<Link
|
||||||
to="/auth/create"
|
to="/auth/create"
|
||||||
className="inline-flex h-11 w-2/3 items-center justify-center gap-2 rounded-lg bg-white/10 px-6 font-medium leading-none text-white backdrop-blur-xl hover:bg-white/20 focus:outline-none"
|
className="inline-flex h-12 w-3/4 items-center justify-center gap-2 rounded-lg border-t border-white/10 bg-white/20 font-medium leading-none text-white backdrop-blur-xl hover:bg-white/30 focus:outline-none"
|
||||||
>
|
>
|
||||||
Create new key
|
Create new key
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-1 items-end justify-center pb-10">
|
<div className="absolute bottom-6 left-1/2 -translate-x-1/2 transform">
|
||||||
<img src="/lume.png" alt="lume" className="h-auto w-1/3" />
|
<img src="/lume.png" alt="lume" className="mx-auto h-auto w-1/4" />
|
||||||
</div>
|
</div>
|
||||||
</Frame>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export function ChatsListItem({ pubkey }: { pubkey: string }) {
|
|||||||
|
|
||||||
if (status === 'loading') {
|
if (status === 'loading') {
|
||||||
return (
|
return (
|
||||||
<div className="inline-flex h-10 items-center gap-2.5 rounded-md px-2">
|
<div className="inline-flex h-10 items-center gap-2.5 rounded-md px-3">
|
||||||
<div className="relative h-7 w-7 shrink-0 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
<div className="relative h-7 w-7 shrink-0 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
||||||
<div className="h-2.5 w-2/3 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
<div className="h-2.5 w-2/3 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
||||||
</div>
|
</div>
|
||||||
@@ -24,10 +24,10 @@ export function ChatsListItem({ pubkey }: { pubkey: string }) {
|
|||||||
preventScrollReset={true}
|
preventScrollReset={true}
|
||||||
className={({ isActive }) =>
|
className={({ isActive }) =>
|
||||||
twMerge(
|
twMerge(
|
||||||
'flex h-10 items-center gap-2.5 rounded-r-lg border-l-2 pl-4 pr-2',
|
'flex h-10 items-center gap-2.5 rounded-r-lg border-l-2 pl-4 pr-3',
|
||||||
isActive
|
isActive
|
||||||
? 'border-fuchsia-500 bg-white/5 text-white'
|
? 'border-fuchsia-500 bg-white/5 text-white'
|
||||||
: 'border-transparent text-white/80'
|
: 'border-transparent text-white/70'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -38,7 +38,10 @@ export function ChatsListItem({ pubkey }: { pubkey: string }) {
|
|||||||
/>
|
/>
|
||||||
<div className="inline-flex w-full flex-1 items-center justify-between">
|
<div className="inline-flex w-full flex-1 items-center justify-between">
|
||||||
<h5 className="max-w-[10rem] truncate">
|
<h5 className="max-w-[10rem] truncate">
|
||||||
{user?.name || user?.display_name || displayNpub(pubkey, 16)}
|
{user?.name ||
|
||||||
|
user?.display_name ||
|
||||||
|
user?.displayName ||
|
||||||
|
displayNpub(pubkey, 16)}
|
||||||
</h5>
|
</h5>
|
||||||
</div>
|
</div>
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import { UnknownsModal } from '@app/chats/components/unknowns';
|
|||||||
|
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
|
import { LoaderIcon } from '@shared/icons';
|
||||||
|
|
||||||
import { useNostr } from '@utils/hooks/useNostr';
|
import { useNostr } from '@utils/hooks/useNostr';
|
||||||
|
|
||||||
export function ChatsList() {
|
export function ChatsList() {
|
||||||
@@ -33,8 +35,10 @@ export function ChatsList() {
|
|||||||
return (
|
return (
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<div className="inline-flex h-10 items-center gap-2.5 border-l-2 border-transparent pl-4">
|
<div className="inline-flex h-10 items-center gap-2.5 border-l-2 border-transparent pl-4">
|
||||||
<div className="relative h-7 w-7 shrink-0 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
<div className="relative inline-flex h-7 w-7 shrink-0 items-center justify-center">
|
||||||
<div className="h-4 w-full animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
<LoaderIcon className="h-4 w-4 animate-spin text-white" />
|
||||||
|
</div>
|
||||||
|
<h5 className="text-white/50">Loading messages...</h5>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -42,8 +46,8 @@ export function ChatsList() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
{chats.follows.map((item) => renderItem(item))}
|
{chats?.follows?.map((item) => renderItem(item))}
|
||||||
{chats.unknowns.length > 0 && <UnknownsModal data={chats.unknowns} />}
|
{chats?.unknowns?.length > 0 && <UnknownsModal data={chats.unknowns} />}
|
||||||
<NewMessageModal />
|
<NewMessageModal />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { NDKEvent } from '@nostr-dev-kit/ndk';
|
|||||||
|
|
||||||
import { useDecryptMessage } from '@app/chats/hooks/useDecryptMessage';
|
import { useDecryptMessage } from '@app/chats/hooks/useDecryptMessage';
|
||||||
|
|
||||||
|
import { TextNote } from '@shared/notes';
|
||||||
import { User } from '@shared/user';
|
import { User } from '@shared/user';
|
||||||
|
|
||||||
export function ChatMessageItem({
|
export function ChatMessageItem({
|
||||||
@@ -20,13 +21,12 @@ export function ChatMessageItem({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-min min-h-min w-full select-text flex-col px-5 py-3 backdrop-blur-xl hover:bg-white/10">
|
<div className="flex h-min min-h-min w-full select-text flex-col px-5 py-3 hover:bg-white/10">
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<User pubkey={message.pubkey} time={message.created_at} isChat={true} />
|
<User pubkey={message.pubkey} time={message.created_at} variant="chat" />
|
||||||
<div className="-mt-[20px] pl-[49px]">
|
<div className="-mt-5 flex items-start gap-3">
|
||||||
<p className="select-text whitespace-pre-line break-words text-base text-white">
|
<div className="w-10 shrink-0" />
|
||||||
{message.content}
|
<TextNote content={message.content} />
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ import { Dispatch, SetStateAction, useState } from 'react';
|
|||||||
|
|
||||||
import { LoaderIcon, MediaIcon } from '@shared/icons';
|
import { LoaderIcon, MediaIcon } from '@shared/icons';
|
||||||
|
|
||||||
import { useImageUploader } from '@utils/hooks/useUploader';
|
import { useNostr } from '@utils/hooks/useNostr';
|
||||||
|
|
||||||
export function MediaUploader({
|
export function MediaUploader({
|
||||||
setState,
|
setState,
|
||||||
}: {
|
}: {
|
||||||
setState: Dispatch<SetStateAction<string>>;
|
setState: Dispatch<SetStateAction<string>>;
|
||||||
}) {
|
}) {
|
||||||
const upload = useImageUploader();
|
const { upload } = useNostr();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const uploadMedia = async () => {
|
const uploadMedia = async () => {
|
||||||
|
|||||||
@@ -2,11 +2,10 @@ import * as Dialog from '@radix-ui/react-dialog';
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { User } from '@app/auth/components/user';
|
|
||||||
|
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
import { CancelIcon, PlusIcon } from '@shared/icons';
|
import { CancelIcon, PlusIcon } from '@shared/icons';
|
||||||
|
import { User } from '@shared/user';
|
||||||
|
|
||||||
export function NewMessageModal() {
|
export function NewMessageModal() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -24,7 +23,7 @@ export function NewMessageModal() {
|
|||||||
<Dialog.Trigger asChild>
|
<Dialog.Trigger asChild>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="inline-flex h-10 items-center gap-2.5 rounded-r-lg border-l-2 border-transparent pl-4 pr-2"
|
className="inline-flex h-10 items-center gap-2.5 rounded-r-lg border-l-2 border-transparent pl-4 pr-3"
|
||||||
>
|
>
|
||||||
<div className="inline-flex h-7 w-7 shrink-0 items-center justify-center rounded bg-white/10 backdrop-blur-xl">
|
<div className="inline-flex h-7 w-7 shrink-0 items-center justify-center rounded bg-white/10 backdrop-blur-xl">
|
||||||
<PlusIcon className="h-4 w-4 text-white" />
|
<PlusIcon className="h-4 w-4 text-white" />
|
||||||
@@ -44,7 +43,7 @@ export function NewMessageModal() {
|
|||||||
<Dialog.Title className="text-lg font-semibold leading-none text-white">
|
<Dialog.Title className="text-lg font-semibold leading-none text-white">
|
||||||
New chat
|
New chat
|
||||||
</Dialog.Title>
|
</Dialog.Title>
|
||||||
<Dialog.Close className="inline-flex h-6 w-6 items-center justify-center rounded-md backdrop-blur-xl hover:bg-white/10">
|
<Dialog.Close className="inline-flex h-6 w-6 items-center justify-center rounded-md hover:bg-white/10">
|
||||||
<CancelIcon className="h-4 w-4 text-white/50" />
|
<CancelIcon className="h-4 w-4 text-white/50" />
|
||||||
</Dialog.Close>
|
</Dialog.Close>
|
||||||
</div>
|
</div>
|
||||||
@@ -54,17 +53,17 @@ export function NewMessageModal() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex h-[500px] flex-col overflow-y-auto overflow-x-hidden pb-2 pt-2">
|
<div className="flex h-[500px] flex-col overflow-y-auto overflow-x-hidden pb-2 pt-2">
|
||||||
{db.account?.follows?.map((follow) => (
|
{db.account?.follows?.map((pubkey) => (
|
||||||
<div
|
<div
|
||||||
key={follow}
|
key={pubkey}
|
||||||
className="group flex items-center justify-between px-4 py-2 backdrop-blur-xl hover:bg-white/10"
|
className="group flex items-center justify-between px-4 py-2 hover:bg-white/10"
|
||||||
>
|
>
|
||||||
<User pubkey={follow} />
|
<User pubkey={pubkey} variant="simple" />
|
||||||
<div>
|
<div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => openChat(follow)}
|
onClick={() => openChat(pubkey)}
|
||||||
className="hidden w-max rounded bg-white/10 px-3 py-1 text-sm font-medium backdrop-blur-xl hover:bg-fuchsia-500 group-hover:inline-flex"
|
className="hidden w-max rounded bg-white/10 px-3 py-1 text-sm font-medium hover:bg-fuchsia-500 group-hover:inline-flex"
|
||||||
>
|
>
|
||||||
Chat
|
Chat
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export function ChatSidebar({ pubkey }: { pubkey: string }) {
|
|||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<h3 className="text-lg font-semibold leading-none">
|
<h3 className="text-lg font-semibold leading-none">
|
||||||
{user?.display_name || user?.name}
|
{user?.name || user?.display_name || user?.displayName}
|
||||||
</h3>
|
</h3>
|
||||||
{user?.nip05 ? (
|
{user?.nip05 ? (
|
||||||
<NIP05
|
<NIP05
|
||||||
|
|||||||
@@ -2,9 +2,8 @@ import * as Dialog from '@radix-ui/react-dialog';
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { User } from '@app/auth/components/user';
|
|
||||||
|
|
||||||
import { CancelIcon, StrangersIcon } from '@shared/icons';
|
import { CancelIcon, StrangersIcon } from '@shared/icons';
|
||||||
|
import { User } from '@shared/user';
|
||||||
|
|
||||||
import { compactNumber } from '@utils/number';
|
import { compactNumber } from '@utils/number';
|
||||||
|
|
||||||
@@ -22,7 +21,7 @@ export function UnknownsModal({ data }: { data: string[] }) {
|
|||||||
<Dialog.Trigger asChild>
|
<Dialog.Trigger asChild>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="inline-flex h-10 items-center gap-2.5 rounded-r-lg border-l-2 border-transparent pl-4 pr-2"
|
className="inline-flex h-10 items-center gap-2.5 rounded-r-lg border-l-2 border-transparent pl-4 pr-3"
|
||||||
>
|
>
|
||||||
<div className="inline-flex h-7 w-7 shrink-0 items-center justify-center rounded bg-white/10 backdrop-blur-xl">
|
<div className="inline-flex h-7 w-7 shrink-0 items-center justify-center rounded bg-white/10 backdrop-blur-xl">
|
||||||
<StrangersIcon className="h-4 w-4 text-white" />
|
<StrangersIcon className="h-4 w-4 text-white" />
|
||||||
@@ -44,7 +43,7 @@ export function UnknownsModal({ data }: { data: string[] }) {
|
|||||||
<Dialog.Title className="text-lg font-semibold leading-none text-white">
|
<Dialog.Title className="text-lg font-semibold leading-none text-white">
|
||||||
{data.length} unknowns
|
{data.length} unknowns
|
||||||
</Dialog.Title>
|
</Dialog.Title>
|
||||||
<Dialog.Close className="inline-flex h-6 w-6 items-center justify-center rounded-md backdrop-blur-xl hover:bg-white/10">
|
<Dialog.Close className="inline-flex h-6 w-6 items-center justify-center rounded-md hover:bg-white/10">
|
||||||
<CancelIcon className="h-4 w-4 text-white/50" />
|
<CancelIcon className="h-4 w-4 text-white/50" />
|
||||||
</Dialog.Close>
|
</Dialog.Close>
|
||||||
</div>
|
</div>
|
||||||
@@ -57,14 +56,14 @@ export function UnknownsModal({ data }: { data: string[] }) {
|
|||||||
{data.map((pubkey) => (
|
{data.map((pubkey) => (
|
||||||
<div
|
<div
|
||||||
key={pubkey}
|
key={pubkey}
|
||||||
className="group flex items-center justify-between px-4 py-2 backdrop-blur-xl hover:bg-white/10"
|
className="group flex items-center justify-between px-4 py-2 hover:bg-white/10"
|
||||||
>
|
>
|
||||||
<User pubkey={pubkey} />
|
<User pubkey={pubkey} variant="simple" />
|
||||||
<div>
|
<div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => openChat(pubkey)}
|
onClick={() => openChat(pubkey)}
|
||||||
className="hidden w-max rounded bg-white/10 px-3 py-1 text-sm font-medium backdrop-blur-xl hover:bg-fuchsia-500 group-hover:inline-flex"
|
className="hidden w-max rounded bg-white/10 px-3 py-1 text-sm font-medium hover:bg-fuchsia-500 group-hover:inline-flex"
|
||||||
>
|
>
|
||||||
Chat
|
Chat
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { NDKSubscription } from '@nostr-dev-kit/ndk';
|
import { NDKEvent, NDKSubscription } from '@nostr-dev-kit/ndk';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useCallback, useEffect, useRef } from 'react';
|
import { useCallback, useEffect, useRef } from 'react';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { Virtuoso } from 'react-virtuoso';
|
import { VList, VListHandle } from 'virtua';
|
||||||
|
|
||||||
import { ChatMessageForm } from '@app/chats/components/messages/form';
|
import { ChatMessageForm } from '@app/chats/components/messages/form';
|
||||||
import { ChatMessageItem } from '@app/chats/components/messages/item';
|
import { ChatMessageItem } from '@app/chats/components/messages/item';
|
||||||
@@ -18,7 +18,7 @@ import { useStronghold } from '@stores/stronghold';
|
|||||||
import { useNostr } from '@utils/hooks/useNostr';
|
import { useNostr } from '@utils/hooks/useNostr';
|
||||||
|
|
||||||
export function ChatScreen() {
|
export function ChatScreen() {
|
||||||
const virtuosoRef = useRef(null);
|
const listRef = useRef<VListHandle>(null);
|
||||||
const userPrivkey = useStronghold((state) => state.privkey);
|
const userPrivkey = useStronghold((state) => state.privkey);
|
||||||
|
|
||||||
const { db } = useStorage();
|
const { db } = useStorage();
|
||||||
@@ -29,10 +29,8 @@ export function ChatScreen() {
|
|||||||
return await fetchNIP04Messages(pubkey);
|
return await fetchNIP04Messages(pubkey);
|
||||||
});
|
});
|
||||||
|
|
||||||
const itemContent = useCallback(
|
const renderItem = useCallback(
|
||||||
(index: string | number) => {
|
(message: NDKEvent) => {
|
||||||
const message = data[index];
|
|
||||||
if (!message) return;
|
|
||||||
return (
|
return (
|
||||||
<ChatMessageItem
|
<ChatMessageItem
|
||||||
message={message}
|
message={message}
|
||||||
@@ -44,12 +42,9 @@ export function ChatScreen() {
|
|||||||
[data]
|
[data]
|
||||||
);
|
);
|
||||||
|
|
||||||
const computeItemKey = useCallback(
|
useEffect(() => {
|
||||||
(index: string | number) => {
|
if (data.length > 0) listRef.current?.scrollToIndex(data.length);
|
||||||
return data[index].id;
|
}, [data]);
|
||||||
},
|
|
||||||
[data]
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const sub: NDKSubscription = ndk.subscribe(
|
const sub: NDKSubscription = ndk.subscribe(
|
||||||
@@ -86,22 +81,17 @@ export function ChatScreen() {
|
|||||||
<p className="text-sm font-medium text-white/50">Loading messages</p>
|
<p className="text-sm font-medium text-white/50">Loading messages</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
) : data.length === 0 ? (
|
||||||
|
<div className="absolute left-1/2 top-1/2 flex w-full -translate-x-1/2 -translate-y-1/2 transform flex-col gap-1 text-center">
|
||||||
|
<h3 className="mb-2 text-4xl">🙌</h3>
|
||||||
|
<p className="leading-none text-white/50">
|
||||||
|
You two didn't talk yet, let's send first message
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<Virtuoso
|
<VList ref={listRef} className="scrollbar-hide h-full" mode="reverse">
|
||||||
ref={virtuosoRef}
|
{data.map((message) => renderItem(message))}
|
||||||
data={data}
|
</VList>
|
||||||
itemContent={itemContent}
|
|
||||||
computeItemKey={computeItemKey}
|
|
||||||
initialTopMostItemIndex={data.length - 1}
|
|
||||||
alignToBottom={true}
|
|
||||||
followOutput={true}
|
|
||||||
overscan={50}
|
|
||||||
increaseViewportBy={{ top: 200, bottom: 200 }}
|
|
||||||
className="scrollbar-hide relative overflow-y-auto"
|
|
||||||
components={{
|
|
||||||
EmptyPlaceholder: () => Empty,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="z-50 shrink-0 rounded-b-xl border-t border-white/5 bg-white/10 p-3 px-5 backdrop-blur-xl">
|
<div className="z-50 shrink-0 rounded-b-xl border-t border-white/5 bg-white/10 p-3 px-5 backdrop-blur-xl">
|
||||||
@@ -120,12 +110,3 @@ export function ChatScreen() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Empty = (
|
|
||||||
<div className="absolute left-1/2 top-1/2 flex w-full -translate-x-1/2 -translate-y-1/2 transform flex-col gap-1 text-center">
|
|
||||||
<h3 className="mb-2 text-4xl">🙌</h3>
|
|
||||||
<p className="leading-none text-white/50">
|
|
||||||
You two didn't talk yet, let's send first message
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|||||||
29
src/app/explore/components/edge.tsx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { BaseEdge, EdgeProps, getBezierPath } from 'reactflow';
|
||||||
|
|
||||||
|
export function Edge({
|
||||||
|
sourceX,
|
||||||
|
sourceY,
|
||||||
|
targetX,
|
||||||
|
targetY,
|
||||||
|
sourcePosition,
|
||||||
|
targetPosition,
|
||||||
|
style = {},
|
||||||
|
markerEnd,
|
||||||
|
}: EdgeProps) {
|
||||||
|
const [edgePath] = getBezierPath({
|
||||||
|
sourceX,
|
||||||
|
sourceY,
|
||||||
|
sourcePosition,
|
||||||
|
targetX,
|
||||||
|
targetY,
|
||||||
|
targetPosition,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BaseEdge
|
||||||
|
path={edgePath}
|
||||||
|
markerEnd={markerEnd}
|
||||||
|
style={{ ...style, stroke: '#71717a' }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
17
src/app/explore/components/groupTitle.tsx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { memo } from 'react';
|
||||||
|
|
||||||
|
import { useProfile } from '@utils/hooks/useProfile';
|
||||||
|
|
||||||
|
export const GroupTitle = memo(function GroupTitle({ pubkey }: { pubkey: string }) {
|
||||||
|
const { status, user } = useProfile(pubkey);
|
||||||
|
|
||||||
|
if (status === 'loading') {
|
||||||
|
return <div className="h-3 w-24 animate-pulse rounded bg-white/10" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<h3 className="text-sm font-semibold text-fuchsia-500">{`${
|
||||||
|
user.name || user.display_name
|
||||||
|
}'s network`}</h3>
|
||||||
|
);
|
||||||
|
});
|
||||||
14
src/app/explore/components/line.tsx
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
export function Line({ fromX, fromY, toX, toY }) {
|
||||||
|
return (
|
||||||
|
<g>
|
||||||
|
<path
|
||||||
|
fill="none"
|
||||||
|
stroke="#f5d0fe"
|
||||||
|
strokeWidth={1.5}
|
||||||
|
className="animated"
|
||||||
|
d={`M${fromX},${fromY} C ${fromX} ${toY} ${fromX} ${toY} ${toX},${toY}`}
|
||||||
|
/>
|
||||||
|
<circle cx={toX} cy={toY} fill="#fff" r={3} stroke="#f5d0fe" strokeWidth={1.5} />
|
||||||
|
</g>
|
||||||
|
);
|
||||||
|
}
|
||||||
34
src/app/explore/components/userGroupNode.tsx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { Handle, Position } from 'reactflow';
|
||||||
|
|
||||||
|
import { UserWithDrawer } from '@app/explore/components/userWithDrawer';
|
||||||
|
|
||||||
|
import { GroupTitle } from './groupTitle';
|
||||||
|
|
||||||
|
export function UserGroupNode({ data }) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Handle
|
||||||
|
type="target"
|
||||||
|
position={Position.Top}
|
||||||
|
className="h-2 w-5 rounded-full border-none !bg-fuchsia-400"
|
||||||
|
/>
|
||||||
|
<div className="relative mx-3 my-3 flex flex-col gap-1">
|
||||||
|
{data.title ? (
|
||||||
|
<h3 className="text-sm font-semibold text-fuchsia-500">{data.title}</h3>
|
||||||
|
) : (
|
||||||
|
<GroupTitle pubkey={data.pubkey} />
|
||||||
|
)}
|
||||||
|
<div className="grid grid-cols-5 gap-6 rounded-lg border border-fuchsia-500/50 bg-fuchsia-500/10 p-4">
|
||||||
|
{data.list.map((user: string) => (
|
||||||
|
<UserWithDrawer key={user} pubkey={user} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Handle
|
||||||
|
type="source"
|
||||||
|
position={Position.Bottom}
|
||||||
|
className="h-2 w-5 rounded-full border-none !bg-fuchsia-400"
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
80
src/app/explore/components/userLatestPosts.tsx
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
|
import { LoaderIcon } from '@shared/icons';
|
||||||
|
import {
|
||||||
|
ArticleNote,
|
||||||
|
FileNote,
|
||||||
|
NoteWrapper,
|
||||||
|
Repost,
|
||||||
|
TextNote,
|
||||||
|
UnknownNote,
|
||||||
|
} from '@shared/notes';
|
||||||
|
|
||||||
|
import { useNostr } from '@utils/hooks/useNostr';
|
||||||
|
|
||||||
|
export function UserLatestPosts({ pubkey }: { pubkey: string }) {
|
||||||
|
const { getEventsByPubkey } = useNostr();
|
||||||
|
const { status, data } = useQuery(['user-posts', pubkey], async () => {
|
||||||
|
return await getEventsByPubkey(pubkey);
|
||||||
|
});
|
||||||
|
|
||||||
|
const renderItem = useCallback(
|
||||||
|
(event: NDKEvent) => {
|
||||||
|
switch (event.kind) {
|
||||||
|
case NDKKind.Text:
|
||||||
|
return (
|
||||||
|
<NoteWrapper key={event.id} event={event}>
|
||||||
|
<TextNote />
|
||||||
|
</NoteWrapper>
|
||||||
|
);
|
||||||
|
case NDKKind.Repost:
|
||||||
|
return <Repost key={event.id} event={event} />;
|
||||||
|
case 1063:
|
||||||
|
return (
|
||||||
|
<NoteWrapper key={event.id} event={event}>
|
||||||
|
<FileNote />
|
||||||
|
</NoteWrapper>
|
||||||
|
);
|
||||||
|
case NDKKind.Article:
|
||||||
|
return (
|
||||||
|
<NoteWrapper key={event.id} event={event}>
|
||||||
|
<ArticleNote />
|
||||||
|
</NoteWrapper>
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return (
|
||||||
|
<NoteWrapper key={event.id} event={event}>
|
||||||
|
<UnknownNote />
|
||||||
|
</NoteWrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[data]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mt-4 border-t border-white/5 pt-3">
|
||||||
|
<h3 className="mb-4 px-3 font-semibold text-white">Latest post</h3>
|
||||||
|
<div>
|
||||||
|
{status === 'loading' ? (
|
||||||
|
<div className="px-3">
|
||||||
|
<div className="inline-flex h-16 w-full items-center justify-center gap-1.5 rounded-lg bg-white/10 text-sm font-medium text-white/70">
|
||||||
|
<LoaderIcon className="h-4 w-4 animate-spin text-white" />
|
||||||
|
Loading latest posts...
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : data.length < 1 ? (
|
||||||
|
<div className="px-3">
|
||||||
|
<div className="inline-flex h-16 w-full items-center justify-center rounded-lg bg-white/10 text-sm font-medium text-white/70">
|
||||||
|
No posts from 24 hours ago
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
data.map((event) => renderItem(event))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
21
src/app/explore/components/userNode.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { Handle, Position } from 'reactflow';
|
||||||
|
|
||||||
|
import { User } from '@shared/user';
|
||||||
|
|
||||||
|
export function UserNode({ data }) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="relative mx-3 my-3 inline-flex h-12 w-12 shrink-0 items-center justify-center">
|
||||||
|
<span className="absolute inline-flex h-8 w-8 animate-ping rounded-lg bg-green-400 opacity-75"></span>
|
||||||
|
<div className="relative z-10">
|
||||||
|
<User pubkey={data.pubkey} variant="avatar" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Handle
|
||||||
|
type="source"
|
||||||
|
position={Position.Bottom}
|
||||||
|
className="h-2 w-2 rounded-full border-none !bg-white/20"
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
130
src/app/explore/components/userWithDrawer.tsx
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
import * as Dialog from '@radix-ui/react-dialog';
|
||||||
|
import { memo, useEffect, useState } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
|
import { Image } from '@shared/image';
|
||||||
|
import { NIP05 } from '@shared/nip05';
|
||||||
|
import { TextNote } from '@shared/notes';
|
||||||
|
import { User } from '@shared/user';
|
||||||
|
|
||||||
|
import { useNostr } from '@utils/hooks/useNostr';
|
||||||
|
import { useProfile } from '@utils/hooks/useProfile';
|
||||||
|
import { displayNpub } from '@utils/shortenKey';
|
||||||
|
|
||||||
|
import { UserLatestPosts } from './userLatestPosts';
|
||||||
|
|
||||||
|
export const UserWithDrawer = memo(function UserWithDrawer({
|
||||||
|
pubkey,
|
||||||
|
}: {
|
||||||
|
pubkey: string;
|
||||||
|
}) {
|
||||||
|
const { addContact, removeContact } = useNostr();
|
||||||
|
const { db } = useStorage();
|
||||||
|
const { status, user } = useProfile(pubkey);
|
||||||
|
|
||||||
|
const [followed, setFollowed] = useState(false);
|
||||||
|
|
||||||
|
const followUser = (pubkey: string) => {
|
||||||
|
try {
|
||||||
|
addContact(pubkey);
|
||||||
|
// update state
|
||||||
|
setFollowed(true);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const unfollowUser = (pubkey: string) => {
|
||||||
|
try {
|
||||||
|
removeContact(pubkey);
|
||||||
|
// update state
|
||||||
|
setFollowed(false);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (db.account.follows.includes(pubkey)) {
|
||||||
|
setFollowed(true);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog.Root>
|
||||||
|
<Dialog.Trigger asChild>
|
||||||
|
<button type="button">
|
||||||
|
<User pubkey={pubkey} variant="avatar" />
|
||||||
|
</button>
|
||||||
|
</Dialog.Trigger>
|
||||||
|
<Dialog.Portal>
|
||||||
|
<Dialog.Content className="fixed right-0 top-0 z-50 flex h-full w-[400px] animate-slideRightAndFade items-center justify-center px-4 pb-4 pt-16 transition-all">
|
||||||
|
<div className="h-full w-full overflow-y-auto rounded-lg border-t border-white/10 bg-white/20 py-3 backdrop-blur-3xl">
|
||||||
|
{status === 'loading' ? (
|
||||||
|
<div>
|
||||||
|
<p>Loading...</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="flex flex-col gap-3 px-3">
|
||||||
|
<Image
|
||||||
|
src={user?.picture || user?.image}
|
||||||
|
alt={pubkey}
|
||||||
|
className="h-12 w-12 rounded-lg"
|
||||||
|
/>
|
||||||
|
<div className="flex flex-1 flex-col gap-2">
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<h5 className="text-lg font-semibold leading-none">
|
||||||
|
{user?.displayName || user?.name || 'No name'}
|
||||||
|
</h5>
|
||||||
|
{user?.nip05 ? (
|
||||||
|
<NIP05
|
||||||
|
pubkey={pubkey}
|
||||||
|
nip05={user?.nip05}
|
||||||
|
className="max-w-[15rem] truncate text-sm leading-none text-white/50"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span className="max-w-[15rem] truncate text-sm leading-none text-white/50">
|
||||||
|
{displayNpub(pubkey, 16)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{user?.about ? <TextNote content={user?.about} /> : null}
|
||||||
|
</div>
|
||||||
|
<div className="mt-3 inline-flex items-center gap-2">
|
||||||
|
{followed ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => unfollowUser(pubkey)}
|
||||||
|
className="inline-flex h-10 w-36 items-center justify-center rounded-md bg-white/10 text-sm font-medium backdrop-blur-xl hover:bg-fuchsia-500"
|
||||||
|
>
|
||||||
|
Unfollow
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => followUser(pubkey)}
|
||||||
|
className="inline-flex h-10 w-36 items-center justify-center rounded-md bg-white/10 text-sm font-medium backdrop-blur-xl hover:bg-fuchsia-500"
|
||||||
|
>
|
||||||
|
Follow
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<Link
|
||||||
|
to={`/chats/${pubkey}`}
|
||||||
|
className="inline-flex h-10 w-36 items-center justify-center rounded-md bg-white/10 text-sm font-medium backdrop-blur-xl hover:bg-fuchsia-500"
|
||||||
|
>
|
||||||
|
Message
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<UserLatestPosts pubkey={pubkey} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Dialog.Content>
|
||||||
|
</Dialog.Portal>
|
||||||
|
</Dialog.Root>
|
||||||
|
);
|
||||||
|
});
|
||||||
116
src/app/explore/index.tsx
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
import { useCallback, useMemo, useRef } from 'react';
|
||||||
|
import ReactFlow, {
|
||||||
|
Background,
|
||||||
|
ConnectionMode,
|
||||||
|
addEdge,
|
||||||
|
useEdgesState,
|
||||||
|
useNodesState,
|
||||||
|
useReactFlow,
|
||||||
|
} from 'reactflow';
|
||||||
|
|
||||||
|
import { Edge } from '@app/explore/components/edge';
|
||||||
|
import { Line } from '@app/explore/components/line';
|
||||||
|
import { UserGroupNode } from '@app/explore/components/userGroupNode';
|
||||||
|
import { UserNode } from '@app/explore/components/userNode';
|
||||||
|
|
||||||
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
|
import { useNostr } from '@utils/hooks/useNostr';
|
||||||
|
import { getMultipleRandom } from '@utils/transform';
|
||||||
|
|
||||||
|
let id = 2;
|
||||||
|
const getId = () => `${id++}`;
|
||||||
|
const nodeTypes = { user: UserNode, userGroup: UserGroupNode };
|
||||||
|
const edgeTypes = { buttonedge: Edge };
|
||||||
|
|
||||||
|
export function ExploreScreen() {
|
||||||
|
const { db } = useStorage();
|
||||||
|
const { getContactsByPubkey } = useNostr();
|
||||||
|
const { project } = useReactFlow();
|
||||||
|
|
||||||
|
const defaultContacts = useMemo(() => getMultipleRandom(db.account.follows, 10), []);
|
||||||
|
const reactFlowWrapper = useRef(null);
|
||||||
|
const connectingNodeId = useRef(null);
|
||||||
|
|
||||||
|
const initialNodes = [
|
||||||
|
{
|
||||||
|
id: '0',
|
||||||
|
type: 'user',
|
||||||
|
position: { x: 141, y: 0 },
|
||||||
|
data: { list: [], title: '', pubkey: db.account.pubkey },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
type: 'userGroup',
|
||||||
|
position: { x: 0, y: 200 },
|
||||||
|
data: { list: defaultContacts, title: 'Starting Point', pubkey: '' },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const initialEdges = [{ id: 'e0-1', type: 'buttonedge', source: '0', target: '1' }];
|
||||||
|
|
||||||
|
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
|
||||||
|
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
|
||||||
|
|
||||||
|
const onConnect = useCallback((params) => setEdges((eds) => addEdge(params, eds)), []);
|
||||||
|
|
||||||
|
const onConnectStart = useCallback((_, { nodeId }) => {
|
||||||
|
connectingNodeId.current = nodeId;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onConnectEnd = useCallback(
|
||||||
|
async (event) => {
|
||||||
|
const targetIsPane = event.target.classList.contains('react-flow__pane');
|
||||||
|
|
||||||
|
if (targetIsPane) {
|
||||||
|
const { top, left } = reactFlowWrapper.current.getBoundingClientRect();
|
||||||
|
|
||||||
|
const id = getId();
|
||||||
|
const prevData = nodes.slice(-1)[0];
|
||||||
|
const randomPubkey = getMultipleRandom(prevData.data.list, 1)[0];
|
||||||
|
|
||||||
|
const newContactList = await getContactsByPubkey(randomPubkey);
|
||||||
|
const newNode = {
|
||||||
|
id,
|
||||||
|
type: 'userGroup',
|
||||||
|
position: project({ x: event.clientX - left, y: event.clientY - top }),
|
||||||
|
data: { list: newContactList, title: null, pubkey: randomPubkey },
|
||||||
|
};
|
||||||
|
|
||||||
|
setNodes((nds) => nds.concat(newNode));
|
||||||
|
setEdges((eds) =>
|
||||||
|
eds.concat({
|
||||||
|
id,
|
||||||
|
type: 'buttonedge',
|
||||||
|
source: connectingNodeId.current,
|
||||||
|
target: id,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[project]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="h-full w-full" ref={reactFlowWrapper}>
|
||||||
|
<ReactFlow
|
||||||
|
proOptions={{ hideAttribution: true }}
|
||||||
|
nodes={nodes}
|
||||||
|
edges={edges}
|
||||||
|
nodeTypes={nodeTypes}
|
||||||
|
edgeTypes={edgeTypes}
|
||||||
|
connectionLineComponent={Line}
|
||||||
|
onNodesChange={onNodesChange}
|
||||||
|
onEdgesChange={onEdgesChange}
|
||||||
|
onConnect={onConnect}
|
||||||
|
onConnectStart={onConnectStart}
|
||||||
|
onConnectEnd={onConnectEnd}
|
||||||
|
connectionMode={ConnectionMode.Loose}
|
||||||
|
minZoom={0.8}
|
||||||
|
maxZoom={1.2}
|
||||||
|
fitView
|
||||||
|
>
|
||||||
|
<Background color="#3f3f46" />
|
||||||
|
</ReactFlow>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
|
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
|
||||||
import { writeText } from '@tauri-apps/api/clipboard';
|
import { writeText } from '@tauri-apps/api/clipboard';
|
||||||
import { nip19 } from 'nostr-tools';
|
import { nip19 } from 'nostr-tools';
|
||||||
import { EventPointer } from 'nostr-tools/lib/nip19';
|
import { AddressPointer, EventPointer } from 'nostr-tools/lib/nip19';
|
||||||
import { useRef, useState } from 'react';
|
import { useRef, useState } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
|
|
||||||
@@ -13,11 +13,11 @@ import {
|
|||||||
NoteActions,
|
NoteActions,
|
||||||
NoteReplyForm,
|
NoteReplyForm,
|
||||||
NoteStats,
|
NoteStats,
|
||||||
ThreadUser,
|
|
||||||
UnknownNote,
|
UnknownNote,
|
||||||
} from '@shared/notes';
|
} from '@shared/notes';
|
||||||
import { RepliesList } from '@shared/notes/replies/list';
|
import { RepliesList } from '@shared/notes/replies/list';
|
||||||
import { NoteSkeleton } from '@shared/notes/skeleton';
|
import { NoteSkeleton } from '@shared/notes/skeleton';
|
||||||
|
import { User } from '@shared/user';
|
||||||
|
|
||||||
import { useEvent } from '@utils/hooks/useEvent';
|
import { useEvent } from '@utils/hooks/useEvent';
|
||||||
|
|
||||||
@@ -27,13 +27,15 @@ export function ArticleNoteScreen() {
|
|||||||
|
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const { db } = useStorage();
|
const { db } = useStorage();
|
||||||
const { status, data } = useEvent(id);
|
|
||||||
|
const naddr = id.startsWith('naddr') ? (nip19.decode(id).data as AddressPointer) : null;
|
||||||
|
const { status, data } = useEvent(id, naddr);
|
||||||
|
|
||||||
const [isCopy, setIsCopy] = useState(false);
|
const [isCopy, setIsCopy] = useState(false);
|
||||||
|
|
||||||
const share = async () => {
|
const share = async () => {
|
||||||
await writeText(
|
await writeText(
|
||||||
'https://nostr.com/' +
|
'https://njump.me/' +
|
||||||
nip19.neventEncode({ id: data.id, author: data.pubkey } as EventPointer)
|
nip19.neventEncode({ id: data.id, author: data.pubkey } as EventPointer)
|
||||||
);
|
);
|
||||||
// update state
|
// update state
|
||||||
@@ -98,21 +100,27 @@ export function ArticleNoteScreen() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="h-min w-full px-3">
|
<>
|
||||||
<div className="rounded-xl bg-white/10 px-3 pt-3 backdrop-blur-xl">
|
<div className="h-min w-full px-3">
|
||||||
<ThreadUser pubkey={data.pubkey} time={data.created_at} />
|
<div className="rounded-xl border-t border-white/10 bg-white/20 px-3 pt-3">
|
||||||
<div className="mt-2">{renderKind(data)}</div>
|
<User pubkey={data.pubkey} time={data.created_at} variant="thread" />
|
||||||
<div>
|
<div className="mt-2">{renderKind(data)}</div>
|
||||||
<NoteActions id={id} pubkey={data.pubkey} extraButtons={false} />
|
<div>
|
||||||
<NoteStats id={id} />
|
<NoteActions
|
||||||
|
id={data.id}
|
||||||
|
pubkey={data.pubkey}
|
||||||
|
extraButtons={false}
|
||||||
|
/>
|
||||||
|
<NoteStats id={data.id} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div ref={replyRef} className="px-3">
|
||||||
|
<NoteReplyForm id={data.id} pubkey={db.account.pubkey} />
|
||||||
|
<RepliesList id={data.id} />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
<div ref={replyRef} className="px-3">
|
|
||||||
<NoteReplyForm id={id} pubkey={db.account.pubkey} />
|
|
||||||
<RepliesList id={id} />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="col-span-1" />
|
<div className="col-span-1" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ import {
|
|||||||
NoteReplyForm,
|
NoteReplyForm,
|
||||||
NoteStats,
|
NoteStats,
|
||||||
TextNote,
|
TextNote,
|
||||||
ThreadUser,
|
|
||||||
UnknownNote,
|
UnknownNote,
|
||||||
} from '@shared/notes';
|
} from '@shared/notes';
|
||||||
import { RepliesList } from '@shared/notes/replies/list';
|
import { RepliesList } from '@shared/notes/replies/list';
|
||||||
import { NoteSkeleton } from '@shared/notes/skeleton';
|
import { NoteSkeleton } from '@shared/notes/skeleton';
|
||||||
|
import { User } from '@shared/user';
|
||||||
|
|
||||||
import { useEvent } from '@utils/hooks/useEvent';
|
import { useEvent } from '@utils/hooks/useEvent';
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ export function TextNoteScreen() {
|
|||||||
|
|
||||||
const share = async () => {
|
const share = async () => {
|
||||||
await writeText(
|
await writeText(
|
||||||
'https://nostr.com/' +
|
'https://njump.me/' +
|
||||||
nip19.neventEncode({ id: data.id, author: data.pubkey } as EventPointer)
|
nip19.neventEncode({ id: data.id, author: data.pubkey } as EventPointer)
|
||||||
);
|
);
|
||||||
// update state
|
// update state
|
||||||
@@ -106,7 +106,7 @@ export function TextNoteScreen() {
|
|||||||
) : (
|
) : (
|
||||||
<div className="h-min w-full px-3">
|
<div className="h-min w-full px-3">
|
||||||
<div className="rounded-xl bg-white/10 px-3 pt-3 backdrop-blur-xl">
|
<div className="rounded-xl bg-white/10 px-3 pt-3 backdrop-blur-xl">
|
||||||
<ThreadUser pubkey={data.pubkey} time={data.created_at} />
|
<User pubkey={data.pubkey} time={data.created_at} variant="thread" />
|
||||||
<div className="mt-2">{renderKind(data)}</div>
|
<div className="mt-2">{renderKind(data)}</div>
|
||||||
<div>
|
<div>
|
||||||
<NoteActions id={id} pubkey={data.pubkey} extraButtons={false} />
|
<NoteActions id={id} pubkey={data.pubkey} extraButtons={false} />
|
||||||
|
|||||||
@@ -1,32 +1,25 @@
|
|||||||
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
||||||
import { useMemo } from 'react';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import { NotiContent } from '@app/notifications/components/content';
|
|
||||||
import { NotiUser } from '@app/notifications/components/user';
|
import { NotiUser } from '@app/notifications/components/user';
|
||||||
|
|
||||||
import { formatCreatedAt } from '@utils/createdAt';
|
import { formatCreatedAt } from '@utils/createdAt';
|
||||||
import { parser } from '@utils/parser';
|
|
||||||
|
|
||||||
export function NotiMention({ event }: { event: NDKEvent }) {
|
export function NotiMention({ event }: { event: NDKEvent }) {
|
||||||
const createdAt = formatCreatedAt(event.created_at);
|
const createdAt = formatCreatedAt(event.created_at);
|
||||||
const content = useMemo(() => parser(event), [event]);
|
const rootId = event.tags.find((el) => el[0])?.[1];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-min w-full px-3 py-1.5">
|
<Link to={`/notes/text/${rootId}`} className="h-min w-full px-3">
|
||||||
<div className="relative overflow-hidden rounded-xl bg-white/10 px-3 pt-3 backdrop-blur-xl">
|
<div className="group flex items-center justify-between rounded-xl px-3 py-3 hover:bg-white/10">
|
||||||
<div className="flex items-start justify-between">
|
<div className="flex items-center gap-2">
|
||||||
<div className="flex items-start gap-1">
|
<NotiUser pubkey={event.pubkey} />
|
||||||
<NotiUser pubkey={event.pubkey} />
|
<p className="leading-none text-white/50">has mention you · {createdAt}</p>
|
||||||
<p className="leading-none text-white/50">has reply you post · {createdAt}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="f- relative z-10 -mt-6 flex gap-3">
|
|
||||||
<div className="h-11 w-11 shrink-0" />
|
|
||||||
<div className="mb-2 mt-3 w-full cursor-default rounded-lg bg-white/10 px-3 py-3 backdrop-blur-xl">
|
|
||||||
<NotiContent content={content} />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<span className="hidden text-sm font-semibold text-fuchsia-500 group-hover:block">
|
||||||
|
View
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Link>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +1,27 @@
|
|||||||
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import { SimpleNote } from '@app/notifications/components/simpleNote';
|
|
||||||
import { NotiUser } from '@app/notifications/components/user';
|
import { NotiUser } from '@app/notifications/components/user';
|
||||||
|
|
||||||
import { formatCreatedAt } from '@utils/createdAt';
|
import { formatCreatedAt } from '@utils/createdAt';
|
||||||
|
|
||||||
export function NotiReaction({ event }: { event: NDKEvent }) {
|
export function NotiReaction({ event }: { event: NDKEvent }) {
|
||||||
const root = event.tags.find((e) => e[0] === 'e')?.[1];
|
|
||||||
const createdAt = formatCreatedAt(event.created_at);
|
const createdAt = formatCreatedAt(event.created_at);
|
||||||
|
const rootId = event.tags.find((el) => el[0])?.[1];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-min w-full px-3 py-1.5">
|
<Link to={`/notes/text/${rootId}`} className="h-min w-full px-3">
|
||||||
<div className="relative overflow-hidden rounded-xl bg-white/10 px-3 pt-3 backdrop-blur-xl">
|
<div className="group flex items-center justify-between rounded-xl px-3 py-3 hover:bg-white/10">
|
||||||
<div className="flex items-start justify-between">
|
<div className="flex items-center gap-2">
|
||||||
<div className="flex items-start gap-1">
|
<NotiUser pubkey={event.pubkey} />
|
||||||
<NotiUser pubkey={event.pubkey} />
|
<p className="leading-none text-white/50">
|
||||||
<p className="leading-none text-white/50">
|
reacted {event.content} · {createdAt}
|
||||||
reacted {event.content} · {createdAt}
|
</p>
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="relative z-10 -mt-6 flex gap-3">
|
|
||||||
<div className="h-11 w-11 shrink-0" />
|
|
||||||
<div className="flex-1">{root && <SimpleNote id={root} />}</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<span className="hidden text-sm font-semibold text-fuchsia-500 group-hover:block">
|
||||||
|
View
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Link>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import { SimpleNote } from '@app/notifications/components/simpleNote';
|
|
||||||
import { NotiUser } from '@app/notifications/components/user';
|
import { NotiUser } from '@app/notifications/components/user';
|
||||||
|
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
@@ -10,29 +10,24 @@ import { formatCreatedAt } from '@utils/createdAt';
|
|||||||
export function NotiRepost({ event }: { event: NDKEvent }) {
|
export function NotiRepost({ event }: { event: NDKEvent }) {
|
||||||
const { db } = useStorage();
|
const { db } = useStorage();
|
||||||
|
|
||||||
const root = event.tags.find((e) => e[0] === 'e')?.[1];
|
|
||||||
const createdAt = formatCreatedAt(event.created_at);
|
const createdAt = formatCreatedAt(event.created_at);
|
||||||
|
const rootId = event.tags.find((el) => el[0])?.[1];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-min w-full px-3 py-1.5">
|
<Link to={`/notes/text/${rootId}`} className="h-min w-full px-3">
|
||||||
<div className="relative overflow-hidden rounded-xl bg-white/10 px-3 pt-3 backdrop-blur-xl">
|
<div className="group flex items-center justify-between rounded-xl px-3 py-3 hover:bg-white/10">
|
||||||
<div className="flex items-start justify-between">
|
<div className="flex items-center gap-2">
|
||||||
<div className="flex items-start gap-1">
|
<NotiUser pubkey={event.pubkey} />
|
||||||
<NotiUser pubkey={event.pubkey} />
|
<p className="leading-none text-white/50">
|
||||||
<p className="leading-none text-white/50">
|
repost{' '}
|
||||||
repost{' '}
|
{event.pubkey !== db.account.pubkey ? 'a post that mention you' : 'your post'}{' '}
|
||||||
{event.pubkey !== db.account.pubkey
|
· {createdAt}
|
||||||
? 'a post that mention you'
|
</p>
|
||||||
: 'your post'}{' '}
|
|
||||||
· {createdAt}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="relative z-10 -mt-6 flex gap-3">
|
|
||||||
<div className="h-11 w-11 shrink-0" />
|
|
||||||
<div className="flex-1">{root && <SimpleNote id={root} />}</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<span className="hidden text-sm font-semibold text-fuchsia-500 group-hover:block">
|
||||||
|
View
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Link>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export const SimpleNote = memo(function SimpleNote({ id }: { id: string }) {
|
|||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
className="mb-2 mt-3 cursor-default rounded-lg bg-white/10 px-3 py-3 backdrop-blur-xl"
|
className="mb-2 mt-3 cursor-default rounded-lg bg-white/10 px-3 py-3 backdrop-blur-xl"
|
||||||
>
|
>
|
||||||
<User pubkey={data.pubkey} time={data.created_at} size="small" />
|
<User pubkey={data.pubkey} time={data.created_at} variant="mention" />
|
||||||
<div className="markdown">
|
<div className="markdown">
|
||||||
<p>
|
<p>
|
||||||
{data.content.length > 200
|
{data.content.length > 200
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ export function NotiUser({ pubkey }: { pubkey: string }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex shrink-0 items-start justify-start gap-3">
|
<div className="flex shrink-0 items-center justify-start gap-2">
|
||||||
<Image
|
<Image
|
||||||
src={user?.picture || user?.image}
|
src={user?.picture || user?.image}
|
||||||
alt={pubkey}
|
alt={pubkey}
|
||||||
className="h-11 w-11 shrink-0 rounded-lg object-cover"
|
className="h-8 w-8 shrink-0 rounded-md object-cover"
|
||||||
/>
|
/>
|
||||||
<span className="max-w-[10rem] flex-1 truncate font-medium leading-none text-white">
|
<span className="max-w-[10rem] truncate font-medium leading-none text-white">
|
||||||
{user?.name || user?.display_name || displayNpub(pubkey, 16)}
|
{user?.name || user?.display_name || user?.displayName || displayNpub(pubkey, 16)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useCallback, useEffect } from 'react';
|
||||||
import { useCallback } from 'react';
|
|
||||||
|
|
||||||
import { NotiMention } from '@app/notifications/components/mention';
|
import { NotiMention } from '@app/notifications/components/mention';
|
||||||
import { NotiReaction } from '@app/notifications/components/reaction';
|
import { NotiReaction } from '@app/notifications/components/reaction';
|
||||||
@@ -11,18 +10,19 @@ import { useStorage } from '@libs/storage/provider';
|
|||||||
import { LoaderIcon } from '@shared/icons';
|
import { LoaderIcon } from '@shared/icons';
|
||||||
import { TitleBar } from '@shared/titleBar';
|
import { TitleBar } from '@shared/titleBar';
|
||||||
|
|
||||||
|
import { useActivities } from '@stores/activities';
|
||||||
|
|
||||||
import { useNostr } from '@utils/hooks/useNostr';
|
import { useNostr } from '@utils/hooks/useNostr';
|
||||||
|
|
||||||
export function NotificationScreen() {
|
export function NotificationScreen() {
|
||||||
const { db } = useStorage();
|
const { db } = useStorage();
|
||||||
const { fetchActivities } = useNostr();
|
const { fetchActivities } = useNostr();
|
||||||
const { status, data } = useQuery(
|
|
||||||
['notifications', db.account.pubkey],
|
const [activities, setActivities, clearTotalNewActivities] = useActivities((state) => [
|
||||||
async () => {
|
state.activities,
|
||||||
return await fetchActivities();
|
state.setActivities,
|
||||||
},
|
state.clearTotalNewActivities,
|
||||||
{ refetchOnWindowFocus: false }
|
]);
|
||||||
);
|
|
||||||
|
|
||||||
const renderItem = useCallback(
|
const renderItem = useCallback(
|
||||||
(event: NDKEvent) => {
|
(event: NDKEvent) => {
|
||||||
@@ -37,34 +37,44 @@ export function NotificationScreen() {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[data]
|
[activities]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function getActivities() {
|
||||||
|
const events = await fetchActivities();
|
||||||
|
setActivities(events, db.account.last_login_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
getActivities();
|
||||||
|
|
||||||
|
// clear total new activities
|
||||||
|
clearTotalNewActivities();
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="scrollbar-hide h-full w-full overflow-y-auto bg-white/10 backdrop-blur-xl">
|
<div className="scrollbar-hide h-full w-full overflow-y-auto bg-white/10 backdrop-blur-xl">
|
||||||
<div className="grid h-full grid-cols-3">
|
<div className="grid h-full grid-cols-3">
|
||||||
<div className="col-span-2 flex flex-col border-r border-white/5">
|
<div className="col-span-2 flex flex-col border-r border-white/5">
|
||||||
<TitleBar title="Activities in the last 24 hours" />
|
<TitleBar title="Activities in the last 24 hours" />
|
||||||
<div className="flex h-full flex-col gap-1.5">
|
<div className="flex h-full flex-col">
|
||||||
<div className="flex h-full flex-col">
|
{!activities ? (
|
||||||
{status === 'loading' ? (
|
<div className="flex h-full w-full items-center justify-center">
|
||||||
<div className="flex h-full w-full items-center justify-center">
|
<div className="flex flex-col items-center gap-1.5">
|
||||||
<div className="flex flex-col items-center gap-1.5">
|
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
||||||
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
<p className="text-sm font-medium text-white/50">Loading</p>
|
||||||
<p className="text-sm font-medium text-white/50">Loading</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
) : data?.length < 1 ? (
|
</div>
|
||||||
<div className="flex h-full w-full flex-col items-center justify-center">
|
) : activities.length <= 1 ? (
|
||||||
<p className="mb-1 text-4xl">🎉</p>
|
<div className="flex h-full w-full flex-col items-center justify-center">
|
||||||
<p className="font-medium text-white/50">
|
<p className="mb-1 text-4xl">🎉</p>
|
||||||
Yo!, no new activities around you in the last 24 hours
|
<p className="font-medium text-white/50">
|
||||||
</p>
|
Yo!, no new activities around you in the last 24 hours
|
||||||
</div>
|
</p>
|
||||||
) : (
|
</div>
|
||||||
data.map((event) => renderItem(event))
|
) : (
|
||||||
)}
|
activities.map((event) => renderItem(event))
|
||||||
</div>
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
152
src/app/nwc/components/alby.tsx
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
import { webln } from '@getalby/sdk';
|
||||||
|
import * as Dialog from '@radix-ui/react-dialog';
|
||||||
|
import { message } from '@tauri-apps/api/dialog';
|
||||||
|
import { WebviewWindow } from '@tauri-apps/api/window';
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
|
import {
|
||||||
|
AlbyIcon,
|
||||||
|
ArrowRightCircleIcon,
|
||||||
|
CancelIcon,
|
||||||
|
CheckCircleIcon,
|
||||||
|
LoaderIcon,
|
||||||
|
} from '@shared/icons';
|
||||||
|
|
||||||
|
import { useStronghold } from '@stores/stronghold';
|
||||||
|
|
||||||
|
export function NWCAlby() {
|
||||||
|
const { db } = useStorage();
|
||||||
|
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
const [isLoading, setIsloading] = useState(false);
|
||||||
|
const [isConnected, setIsConnected] = useState(false);
|
||||||
|
|
||||||
|
const setWalletConnectURL = useStronghold((state) => state.setWalletConnectURL);
|
||||||
|
|
||||||
|
const initAlby = async () => {
|
||||||
|
try {
|
||||||
|
setIsloading(true);
|
||||||
|
|
||||||
|
const provider = webln.NostrWebLNProvider.withNewSecret();
|
||||||
|
const walletConnectURL = provider.getNostrWalletConnectUrl(true);
|
||||||
|
|
||||||
|
// get auth url
|
||||||
|
const authURL = provider.getAuthorizationUrl({ name: 'Lume' });
|
||||||
|
|
||||||
|
// open auth window
|
||||||
|
const webview = new WebviewWindow('alby', {
|
||||||
|
title: 'Connect Alby',
|
||||||
|
url: authURL.href,
|
||||||
|
center: true,
|
||||||
|
width: 400,
|
||||||
|
height: 650,
|
||||||
|
});
|
||||||
|
|
||||||
|
webview.listen('tauri://close-requested', async () => {
|
||||||
|
await db.secureSave('walletConnectURL', walletConnectURL, 'nwc');
|
||||||
|
setWalletConnectURL(walletConnectURL);
|
||||||
|
setIsConnected(true);
|
||||||
|
setIsloading(false);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
setIsloading(false);
|
||||||
|
await message(e.toString(), { title: 'Connect Alby', type: 'error' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog.Root open={isOpen} onOpenChange={setIsOpen}>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="inline-flex items-center gap-2.5">
|
||||||
|
<div className="inline-flex h-11 w-11 items-center justify-center rounded-md bg-orange-200">
|
||||||
|
<AlbyIcon className="h-8 w-8" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h5 className="font-semibold leading-tight text-white">Alby</h5>
|
||||||
|
<p className="text-sm leading-tight text-white/50">Require alby account</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Dialog.Trigger asChild>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="inline-flex h-9 w-min items-center justify-center rounded-md border-t border-white/10 bg-white/20 px-3 text-sm font-medium text-white hover:bg-green-500"
|
||||||
|
>
|
||||||
|
Connect
|
||||||
|
</button>
|
||||||
|
</Dialog.Trigger>
|
||||||
|
</div>
|
||||||
|
<Dialog.Portal className="relative z-10">
|
||||||
|
<Dialog.Overlay className="fixed inset-0 z-50 bg-black/80 backdrop-blur-2xl" />
|
||||||
|
<Dialog.Content className="fixed inset-0 z-50 flex min-h-full items-center justify-center">
|
||||||
|
<div className="relative h-min w-full max-w-xl rounded-xl bg-white/10 backdrop-blur-xl">
|
||||||
|
<div className="h-min w-full shrink-0 rounded-t-xl border-b border-white/10 bg-white/5 px-5 py-5">
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<Dialog.Title className="text-lg font-semibold leading-none text-white">
|
||||||
|
Alby integration (Beta)
|
||||||
|
</Dialog.Title>
|
||||||
|
<Dialog.Close className="inline-flex h-6 w-6 items-center justify-center rounded-md backdrop-blur-xl hover:bg-white/10">
|
||||||
|
<CancelIcon className="h-4 w-4 text-white/50" />
|
||||||
|
</Dialog.Close>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-3 px-5 py-5">
|
||||||
|
<div className="relative flex h-40 items-center justify-center gap-4">
|
||||||
|
<div className="inline-flex h-16 w-16 items-end justify-center rounded-lg bg-black pb-2">
|
||||||
|
<img src="/lume.png" className="w-1/3" alt="Lume Logo" />
|
||||||
|
</div>
|
||||||
|
<div className="w-20 border border-dashed border-white/5" />
|
||||||
|
<div className="inline-flex h-16 w-16 items-center justify-center rounded-lg bg-white">
|
||||||
|
<AlbyIcon className="h-8 w-8" />
|
||||||
|
</div>
|
||||||
|
{isConnected ? (
|
||||||
|
<div className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 transform">
|
||||||
|
<CheckCircleIcon className="h-5 w-5 text-green-500" />
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<p className="text-sm text-white/50">
|
||||||
|
When you click "Connect", a new window will open and you need
|
||||||
|
to click the "Connect Wallet" button to grant Lume permission
|
||||||
|
to integrate with your Alby account.
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-white/50">
|
||||||
|
All information will be encrypted and stored on the local machine.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => initAlby()}
|
||||||
|
className="inline-flex h-11 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{isLoading ? (
|
||||||
|
<>
|
||||||
|
<span className="w-5" />
|
||||||
|
<span>Connecting...</span>
|
||||||
|
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
||||||
|
</>
|
||||||
|
) : isConnected ? (
|
||||||
|
<>
|
||||||
|
<span className="w-5" />
|
||||||
|
<span>Connected</span>
|
||||||
|
<CheckCircleIcon className="h-5 w-5" />
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<span className="w-5" />
|
||||||
|
<span>Connect</span>
|
||||||
|
<ArrowRightCircleIcon className="h-5 w-5" />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Dialog.Content>
|
||||||
|
</Dialog.Portal>
|
||||||
|
</Dialog.Root>
|
||||||
|
);
|
||||||
|
}
|
||||||
168
src/app/nwc/components/other.tsx
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
import * as Dialog from '@radix-ui/react-dialog';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { Resolver, useForm } from 'react-hook-form';
|
||||||
|
|
||||||
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
|
import { ArrowRightCircleIcon, CancelIcon, LoaderIcon, WorldIcon } from '@shared/icons';
|
||||||
|
|
||||||
|
import { useStronghold } from '@stores/stronghold';
|
||||||
|
|
||||||
|
type FormValues = {
|
||||||
|
uri: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const resolver: Resolver<FormValues> = async (values) => {
|
||||||
|
return {
|
||||||
|
values: values.uri ? values : {},
|
||||||
|
errors: !values.uri
|
||||||
|
? {
|
||||||
|
uri: {
|
||||||
|
type: 'required',
|
||||||
|
message: 'This is required.',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export function NWCOther() {
|
||||||
|
const { db } = useStorage();
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
setError,
|
||||||
|
handleSubmit,
|
||||||
|
formState: { errors, isDirty, isValid },
|
||||||
|
} = useForm<FormValues>({ resolver });
|
||||||
|
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
const [isLoading, setIsloading] = useState(false);
|
||||||
|
|
||||||
|
const setWalletConnectURL = useStronghold((state) => state.setWalletConnectURL);
|
||||||
|
|
||||||
|
const onSubmit = async (data: { [x: string]: string }) => {
|
||||||
|
try {
|
||||||
|
if (!data.uri.startsWith('nostr+walletconnect:')) {
|
||||||
|
setError('uri', {
|
||||||
|
type: 'custom',
|
||||||
|
message:
|
||||||
|
'Connect URI is required and must start with format nostr+walletconnect:, please check again',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsloading(true);
|
||||||
|
|
||||||
|
const uriObj = new URL(data.uri);
|
||||||
|
const params = new URLSearchParams(uriObj.search);
|
||||||
|
|
||||||
|
if (params.has('relay') && params.has('secret')) {
|
||||||
|
await db.secureSave('walletConnectURL', data.uri, 'nwc');
|
||||||
|
setWalletConnectURL(data.uri);
|
||||||
|
setIsloading(false);
|
||||||
|
setIsOpen(false);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setIsloading(false);
|
||||||
|
setError('uri', {
|
||||||
|
type: 'custom',
|
||||||
|
message:
|
||||||
|
'Connect URI is required and must start with format nostr+walletconnect:, please check again',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog.Root open={isOpen} onOpenChange={setIsOpen}>
|
||||||
|
<div className="flex items-center justify-between pt-4">
|
||||||
|
<div className="inline-flex items-center gap-2.5">
|
||||||
|
<div className="inline-flex h-11 w-11 items-center justify-center rounded-md bg-white/10">
|
||||||
|
<WorldIcon className="h-5 w-5" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h5 className="font-semibold leading-tight text-white">URI String</h5>
|
||||||
|
<p className="text-sm leading-tight text-white/50">
|
||||||
|
Using format nostr+walletconnect:
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Dialog.Trigger asChild>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="inline-flex h-9 w-min items-center justify-center rounded-md border-t border-white/10 bg-white/20 px-3 text-sm font-medium text-white hover:bg-green-500"
|
||||||
|
>
|
||||||
|
Connect
|
||||||
|
</button>
|
||||||
|
</Dialog.Trigger>
|
||||||
|
</div>
|
||||||
|
<Dialog.Portal className="relative z-10">
|
||||||
|
<Dialog.Overlay className="fixed inset-0 z-50 bg-black/80 backdrop-blur-2xl" />
|
||||||
|
<Dialog.Content className="fixed inset-0 z-50 flex min-h-full items-center justify-center">
|
||||||
|
<div className="relative h-min w-full max-w-xl rounded-xl bg-white/10 backdrop-blur-xl">
|
||||||
|
<div className="h-min w-full shrink-0 rounded-t-xl border-b border-white/10 bg-white/5 px-5 py-5">
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<Dialog.Title className="text-lg font-semibold leading-none text-white">
|
||||||
|
Nostr Wallet Connect
|
||||||
|
</Dialog.Title>
|
||||||
|
<Dialog.Close className="inline-flex h-6 w-6 items-center justify-center rounded-md backdrop-blur-xl hover:bg-white/10">
|
||||||
|
<CancelIcon className="h-4 w-4 text-white/50" />
|
||||||
|
</Dialog.Close>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form
|
||||||
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
|
className="mb-0 flex flex-col gap-3 px-5 py-5"
|
||||||
|
>
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<label
|
||||||
|
htmlFor="uri"
|
||||||
|
className="text-sm font-semibold uppercase tracking-wider text-white/50"
|
||||||
|
>
|
||||||
|
Connect URI
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
{...register('uri', { required: true })}
|
||||||
|
placeholder="nostr+walletconnect:"
|
||||||
|
spellCheck={false}
|
||||||
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
autoCapitalize="off"
|
||||||
|
className="relative h-11 w-full rounded-lg bg-white/10 px-3 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
||||||
|
/>
|
||||||
|
<span className="text-sm text-red-400">
|
||||||
|
{errors.uri && <p>{errors.uri.message}</p>}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-1 text-center">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={!isDirty || !isValid}
|
||||||
|
className="inline-flex h-11 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{isLoading ? (
|
||||||
|
<>
|
||||||
|
<span className="w-5" />
|
||||||
|
<span>Connecting...</span>
|
||||||
|
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<span className="w-5" />
|
||||||
|
<span>Connect</span>
|
||||||
|
<ArrowRightCircleIcon className="h-5 w-5" />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
<span className="text-sm text-white/50">
|
||||||
|
All information will be encrypted and stored on the local machine.
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</Dialog.Content>
|
||||||
|
</Dialog.Portal>
|
||||||
|
</Dialog.Root>
|
||||||
|
);
|
||||||
|
}
|
||||||
124
src/app/nwc/index.tsx
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
import { NWCAlby } from '@app/nwc/components/alby';
|
||||||
|
import { NWCOther } from '@app/nwc/components/other';
|
||||||
|
|
||||||
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
|
import { CheckCircleIcon } from '@shared/icons';
|
||||||
|
|
||||||
|
import { useStronghold } from '@stores/stronghold';
|
||||||
|
|
||||||
|
export function NWCScreen() {
|
||||||
|
const { db } = useStorage();
|
||||||
|
|
||||||
|
const [walletConnectURL, setWalletConnectURL] = useStronghold((state) => [
|
||||||
|
state.walletConnectURL,
|
||||||
|
state.setWalletConnectURL,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const remove = async () => {
|
||||||
|
setWalletConnectURL('');
|
||||||
|
await db.secureSave('walletConnectURL', '', 'nwc');
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex h-full w-full items-center justify-center bg-white/5">
|
||||||
|
<div className="flex w-full flex-col gap-5">
|
||||||
|
<div className="text-center">
|
||||||
|
<h3 className="text-2xl font-bold leading-tight">
|
||||||
|
Nostr Wallet Connect (Beta)
|
||||||
|
</h3>
|
||||||
|
<p className="leading-tight text-white/70">
|
||||||
|
Sending tips easily via Bitcoin Lightning.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="mx-auto max-w-lg">
|
||||||
|
{!walletConnectURL ? (
|
||||||
|
<div className="flex w-full flex-col gap-4 divide-y divide-white/5 rounded-xl border-t border-white/10 bg-white/20 p-3">
|
||||||
|
<NWCAlby />
|
||||||
|
<NWCOther />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="flex w-full flex-col rounded-xl border-t border-white/10 bg-white/20 p-3">
|
||||||
|
<div className="mb-1 inline-flex items-center gap-1.5 text-sm text-green-500">
|
||||||
|
<CheckCircleIcon className="h-4 w-4" />
|
||||||
|
<p>You're using nostr wallet connect</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<textarea
|
||||||
|
readOnly
|
||||||
|
value={walletConnectURL.substring(0, 120) + '****'}
|
||||||
|
className="relative h-40 w-full resize-none rounded-lg bg-white/20 px-3 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => remove()}
|
||||||
|
className="inline-flex h-11 w-full items-center justify-center gap-2 rounded-lg bg-white/10 px-6 font-medium leading-none text-red-500 hover:bg-white/20 focus:outline-none disabled:opacity-50"
|
||||||
|
>
|
||||||
|
Remove connection
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="mt-5 flex flex-col gap-4">
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<h5 className="text-sm font-bold text-white">Introduction</h5>
|
||||||
|
<p className="text-sm text-white/70">
|
||||||
|
Nostr Wallet Connect (NWC) is a way for applications like Nostr clients to
|
||||||
|
access a remote Lightning wallet through a standardized protocol.
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-white/70">
|
||||||
|
To learn more about the details have a look at{' '}
|
||||||
|
<a
|
||||||
|
href="https://github.com/getAlby/nips/blob/7-wallet-connect-patch/47.md"
|
||||||
|
target="_blank"
|
||||||
|
className="text-fuchsia-300"
|
||||||
|
rel="noreferrer"
|
||||||
|
>
|
||||||
|
the specs (NIP47)
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<h5 className="text-sm font-bold text-white">About tipping</h5>
|
||||||
|
<p className="text-sm text-white/70">
|
||||||
|
Also known as Zap in other Nostr client.
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-white/70">
|
||||||
|
Lume doesn't take any commission or platform fees when you tip
|
||||||
|
someone.
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-white/70">Lume doesn't hold your Bitcoin</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<h5 className="text-sm font-bold text-white">
|
||||||
|
Recommend wallet that support NWC
|
||||||
|
</h5>
|
||||||
|
<p className="text-sm text-white/70">
|
||||||
|
Mutiny Wallet:{' '}
|
||||||
|
<a
|
||||||
|
href="https://www.mutinywallet.com/"
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
className="text-fuchsia-300"
|
||||||
|
>
|
||||||
|
website
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-white/70">
|
||||||
|
Self hosted NWC on Umbrel :{' '}
|
||||||
|
<a
|
||||||
|
href="https://apps.umbrel.com/app/alby-nostr-wallet-connect"
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
className="text-fuchsia-300"
|
||||||
|
>
|
||||||
|
website
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
90
src/app/relays/components/relayEventList.tsx
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
import { VList } from 'virtua';
|
||||||
|
|
||||||
|
import { useNDK } from '@libs/ndk/provider';
|
||||||
|
|
||||||
|
import { LoaderIcon } from '@shared/icons';
|
||||||
|
import {
|
||||||
|
ArticleNote,
|
||||||
|
FileNote,
|
||||||
|
NoteWrapper,
|
||||||
|
Repost,
|
||||||
|
TextNote,
|
||||||
|
UnknownNote,
|
||||||
|
} from '@shared/notes';
|
||||||
|
|
||||||
|
export function RelayEventList({ relayUrl }: { relayUrl: string }) {
|
||||||
|
const { fetcher } = useNDK();
|
||||||
|
const { status, data } = useQuery(
|
||||||
|
['relay-event'],
|
||||||
|
async () => {
|
||||||
|
const url = 'wss://' + relayUrl;
|
||||||
|
const events = await fetcher.fetchLatestEvents(
|
||||||
|
[url],
|
||||||
|
{
|
||||||
|
kinds: [NDKKind.Text, NDKKind.Repost, 1063, NDKKind.Article],
|
||||||
|
},
|
||||||
|
100
|
||||||
|
);
|
||||||
|
return events as unknown as NDKEvent[];
|
||||||
|
},
|
||||||
|
{ refetchOnWindowFocus: false }
|
||||||
|
);
|
||||||
|
|
||||||
|
const renderItem = useCallback(
|
||||||
|
(event: NDKEvent) => {
|
||||||
|
switch (event.kind) {
|
||||||
|
case NDKKind.Text:
|
||||||
|
return (
|
||||||
|
<NoteWrapper key={event.id} event={event}>
|
||||||
|
<TextNote />
|
||||||
|
</NoteWrapper>
|
||||||
|
);
|
||||||
|
case NDKKind.Repost:
|
||||||
|
return <Repost key={event.id} event={event} />;
|
||||||
|
case 1063:
|
||||||
|
return (
|
||||||
|
<NoteWrapper key={event.id} event={event}>
|
||||||
|
<FileNote />
|
||||||
|
</NoteWrapper>
|
||||||
|
);
|
||||||
|
case NDKKind.Article:
|
||||||
|
return (
|
||||||
|
<NoteWrapper key={event.id} event={event}>
|
||||||
|
<ArticleNote />
|
||||||
|
</NoteWrapper>
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return (
|
||||||
|
<NoteWrapper key={event.id} event={event}>
|
||||||
|
<UnknownNote />
|
||||||
|
</NoteWrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[data]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="h-full">
|
||||||
|
<div className="mx-auto w-full max-w-[500px]">
|
||||||
|
{status === 'loading' ? (
|
||||||
|
<div className="flex h-full w-full items-center justify-center">
|
||||||
|
<div className="inline-flex flex-col items-center justify-center gap-2">
|
||||||
|
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
||||||
|
<p className="text-sm font-medium text-white/80">Loading newsfeed...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<VList className="scrollbar-hide h-full">
|
||||||
|
<div className="h-10" />
|
||||||
|
{data.map((item) => renderItem(item))}
|
||||||
|
<div className="h-16" />
|
||||||
|
</VList>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
66
src/app/relays/components/relayForm.tsx
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
|
import { PlusIcon } from '@shared/icons';
|
||||||
|
|
||||||
|
const domainRegex = /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/;
|
||||||
|
|
||||||
|
export function RelayForm() {
|
||||||
|
const { db } = useStorage();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const [url, setUrl] = useState('');
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
|
||||||
|
const createRelay = async () => {
|
||||||
|
if (url.length < 1) return setError('Please enter relay url');
|
||||||
|
try {
|
||||||
|
const relay = new URL(url.replace(/\s/g, ''));
|
||||||
|
if (
|
||||||
|
domainRegex.test(relay.host) &&
|
||||||
|
(relay.protocol === 'wss:' || relay.protocol === 'ws:')
|
||||||
|
) {
|
||||||
|
const res = await db.createRelay(url);
|
||||||
|
if (!res) return setError("You're already using this relay");
|
||||||
|
|
||||||
|
queryClient.invalidateQueries(['user-relay']);
|
||||||
|
setError('');
|
||||||
|
setUrl('');
|
||||||
|
} else {
|
||||||
|
return setError(
|
||||||
|
'URL is invalid, a relay must use websocket protocol (start with wss:// or ws://). Please check again'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return setError('Relay URL is not valid. Please check again');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<div className="flex h-10 items-center justify-between rounded-lg bg-white/10 pr-1.5">
|
||||||
|
<input
|
||||||
|
className="h-full w-full bg-transparent pl-3 pr-1.5 placeholder:text-white/70 focus:outline-none"
|
||||||
|
type="url"
|
||||||
|
placeholder="wss://"
|
||||||
|
spellCheck={false}
|
||||||
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
autoCapitalize="off"
|
||||||
|
value={url}
|
||||||
|
onChange={(e) => setUrl(e.target.value)}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => createRelay()}
|
||||||
|
className="inline-flex h-6 w-6 items-center justify-center rounded bg-fuchsia-500 text-white hover:bg-fuchsia-600"
|
||||||
|
>
|
||||||
|
<PlusIcon className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<span className="text-sm text-red-400">{error}</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
109
src/app/relays/components/relayList.tsx
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { message } from '@tauri-apps/api/dialog';
|
||||||
|
import { normalizeRelayUrl } from 'nostr-fetch';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { VList } from 'virtua';
|
||||||
|
|
||||||
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
|
import { LoaderIcon, PlusIcon, ShareIcon } from '@shared/icons';
|
||||||
|
import { User } from '@shared/user';
|
||||||
|
|
||||||
|
import { useNostr } from '@utils/hooks/useNostr';
|
||||||
|
|
||||||
|
export function RelayList() {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const { getAllRelaysByUsers } = useNostr();
|
||||||
|
const { db } = useStorage();
|
||||||
|
const { status, data } = useQuery(
|
||||||
|
['relays'],
|
||||||
|
async () => {
|
||||||
|
return await getAllRelaysByUsers();
|
||||||
|
},
|
||||||
|
{
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
refetchOnMount: false,
|
||||||
|
refetchOnReconnect: false,
|
||||||
|
staleTime: Infinity,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const inspectRelay = (relayUrl: string) => {
|
||||||
|
const url = new URL(relayUrl);
|
||||||
|
navigate(`/relays/${url.hostname}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const connectRelay = async (relayUrl: string) => {
|
||||||
|
const url = normalizeRelayUrl(relayUrl);
|
||||||
|
const res = await db.createRelay(url);
|
||||||
|
|
||||||
|
if (!res) await message("You're aldready connected to this relay");
|
||||||
|
queryClient.invalidateQueries(['user-relay']);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="col-span-2 border-r border-white/5">
|
||||||
|
{status === 'loading' ? (
|
||||||
|
<div className="flex h-full w-full items-center justify-center pb-10">
|
||||||
|
<div className="inline-flex flex-col items-center justify-center gap-2">
|
||||||
|
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
||||||
|
<p>Loading relay...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<VList className="scrollbar-hide mt-20 h-full">
|
||||||
|
<div className="inline-flex h-16 w-full items-center border-b border-white/5 px-3">
|
||||||
|
<h3 className="bg-gradient-to-r from-fuchsia-200 via-red-200 to-orange-300 bg-clip-text font-semibold text-transparent">
|
||||||
|
All relays used by your follows
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
{[...data].map(([key, value]) => (
|
||||||
|
<div
|
||||||
|
key={key}
|
||||||
|
className="flex h-14 w-full items-center justify-between border-b border-white/5 px-3"
|
||||||
|
>
|
||||||
|
<div className="inline-flex items-center gap-2 divide-x divide-white/10">
|
||||||
|
<div className="inline-flex items-center gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => inspectRelay(key)}
|
||||||
|
className="inline-flex h-6 items-center justify-center gap-1 rounded bg-white/10 px-1.5 text-sm font-medium hover:bg-white/20"
|
||||||
|
>
|
||||||
|
<ShareIcon className="h-3 w-3" />
|
||||||
|
Inspect
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => connectRelay(key)}
|
||||||
|
className="inline-flex h-6 w-6 items-center justify-center rounded hover:bg-white/10"
|
||||||
|
>
|
||||||
|
<PlusIcon className="h-3 w-3" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="inline-flex items-center gap-2 pl-3">
|
||||||
|
<span className="text-sm font-semibold text-white/70">Relay: </span>
|
||||||
|
<span className="max-w-[200px] truncate text-sm font-medium text-white">
|
||||||
|
{key}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="isolate flex -space-x-2">
|
||||||
|
{value.slice(0, 4).map((item) => (
|
||||||
|
<User key={item} pubkey={item} variant="stacked" />
|
||||||
|
))}
|
||||||
|
{value.length > 4 ? (
|
||||||
|
<div className="inline-flex h-8 w-8 items-center justify-center rounded-full bg-black/80 ring-1 ring-white/10 backdrop-blur-xl">
|
||||||
|
<span className="text-xs font-semibold">+{value.length}</span>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<div className="h-16" />
|
||||||
|
</VList>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
69
src/app/relays/components/userRelay.tsx
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import { RelayForm } from '@app/relays/components/relayForm';
|
||||||
|
|
||||||
|
import { useNDK } from '@libs/ndk/provider';
|
||||||
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
|
import { CancelIcon } from '@shared/icons';
|
||||||
|
|
||||||
|
export function UserRelay() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const { relayUrls } = useNDK();
|
||||||
|
const { db } = useStorage();
|
||||||
|
const { status, data } = useQuery(
|
||||||
|
['user-relay'],
|
||||||
|
async () => {
|
||||||
|
return await db.getExplicitRelayUrls();
|
||||||
|
},
|
||||||
|
{ refetchOnWindowFocus: false }
|
||||||
|
);
|
||||||
|
|
||||||
|
const removeRelay = async (relayUrl: string) => {
|
||||||
|
await db.removeRelay(relayUrl);
|
||||||
|
queryClient.invalidateQueries(['user-relay']);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mt-3 px-3">
|
||||||
|
{status === 'loading' ? (
|
||||||
|
<p>Loading...</p>
|
||||||
|
) : (
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
{data.map((item) => (
|
||||||
|
<div
|
||||||
|
key={item}
|
||||||
|
className="group flex h-10 items-center justify-between rounded-lg bg-white/10 pl-3 pr-1.5"
|
||||||
|
>
|
||||||
|
<div className="inline-flex items-center gap-2.5">
|
||||||
|
{relayUrls.includes(item) ? (
|
||||||
|
<span className="relative flex h-2 w-2">
|
||||||
|
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75"></span>
|
||||||
|
<span className="relative inline-flex h-2 w-2 rounded-full bg-green-500"></span>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="relative flex h-2 w-2">
|
||||||
|
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-red-400 opacity-75"></span>
|
||||||
|
<span className="relative inline-flex h-2 w-2 rounded-full bg-red-500"></span>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<p className="max-w-[20rem] truncate text-sm font-medium leading-none">
|
||||||
|
{item}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => removeRelay(item)}
|
||||||
|
className="hidden h-6 w-6 items-center justify-center rounded hover:bg-white/10 group-hover:inline-flex"
|
||||||
|
>
|
||||||
|
<CancelIcon className="h-4 w-4 text-white" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<RelayForm />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
16
src/app/relays/index.tsx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { RelayList } from '@app/relays/components/relayList';
|
||||||
|
import { UserRelay } from '@app/relays/components/userRelay';
|
||||||
|
|
||||||
|
export function RelaysScreen() {
|
||||||
|
return (
|
||||||
|
<div className="grid h-full w-full grid-cols-3">
|
||||||
|
<RelayList />
|
||||||
|
<div className="col-span-1">
|
||||||
|
<div className="inline-flex h-16 w-full items-center border-b border-white/5 px-3">
|
||||||
|
<h3 className="font-semibold text-white">Connected relays</h3>
|
||||||
|
</div>
|
||||||
|
<UserRelay />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
165
src/app/relays/relay.tsx
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
import { Suspense } from 'react';
|
||||||
|
import { Await, useLoaderData, useNavigate, useParams } from 'react-router-dom';
|
||||||
|
|
||||||
|
import { ArrowLeftIcon, LoaderIcon } from '@shared/icons';
|
||||||
|
import { User } from '@shared/user';
|
||||||
|
|
||||||
|
import { RelayEventList } from './components/relayEventList';
|
||||||
|
|
||||||
|
export function RelayScreen() {
|
||||||
|
const { url } = useParams();
|
||||||
|
|
||||||
|
const data: { relay?: { [key: string]: string } } = useLoaderData();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const getSoftwareName = (url: string) => {
|
||||||
|
const filename = url.substring(url.lastIndexOf('/') + 1);
|
||||||
|
return filename.replace('.git', '');
|
||||||
|
};
|
||||||
|
|
||||||
|
const titleCase = (s: string) => {
|
||||||
|
return s
|
||||||
|
.replace(/^[-_]*(.)/, (_, c) => c.toUpperCase())
|
||||||
|
.replace(/[-_]+(.)/g, (_, c) => ' ' + c.toUpperCase());
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="grid h-full w-full grid-cols-3">
|
||||||
|
<div className="col-span-2 border-r border-white/5">
|
||||||
|
<div className="inline-flex h-16 w-full items-center gap-2.5 border-b border-white/5 px-3">
|
||||||
|
<button type="button" onClick={() => navigate(-1)}>
|
||||||
|
<ArrowLeftIcon className="h-5 w-5 text-white/70 hover:text-white" />
|
||||||
|
</button>
|
||||||
|
<h3 className="font-semibold text-white">Global events</h3>
|
||||||
|
</div>
|
||||||
|
<RelayEventList relayUrl={url} />
|
||||||
|
</div>
|
||||||
|
<div className="col-span-1">
|
||||||
|
<div className="inline-flex h-16 w-full items-center border-b border-white/5 px-3">
|
||||||
|
<h3 className="font-semibold text-white">Information</h3>
|
||||||
|
</div>
|
||||||
|
<div className="mt-4 px-3">
|
||||||
|
<Suspense
|
||||||
|
fallback={
|
||||||
|
<div className="flex items-center gap-2 text-sm font-medium text-white">
|
||||||
|
<LoaderIcon className="h-4 w-4 animate-spin" />
|
||||||
|
Loading...
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Await
|
||||||
|
resolve={data.relay}
|
||||||
|
errorElement={
|
||||||
|
<div className="text-sm font-medium">
|
||||||
|
<p>Could not load relay information 😬</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{(resolvedRelay) => (
|
||||||
|
<div className="flex flex-col gap-5">
|
||||||
|
<div>
|
||||||
|
<h3 className="font-semibold leading-tight text-white">
|
||||||
|
{resolvedRelay.name}
|
||||||
|
</h3>
|
||||||
|
<p className="text-sm font-medium text-white/70">
|
||||||
|
{resolvedRelay.description}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{resolvedRelay.pubkey ? (
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<h5 className="text-sm font-semibold text-white/70">Owner:</h5>
|
||||||
|
<div className="w-full rounded-lg bg-white/10 px-2 py-2">
|
||||||
|
<User pubkey={resolvedRelay.pubkey} variant="simple" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{resolvedRelay.contact ? (
|
||||||
|
<div>
|
||||||
|
<h5 className="text-sm font-semibold text-white/70">Contact:</h5>
|
||||||
|
<a
|
||||||
|
href={`mailto:${resolvedRelay.contact}`}
|
||||||
|
target="_blank"
|
||||||
|
className="underline after:content-['_↗'] hover:text-fuchsia-500"
|
||||||
|
rel="noreferrer"
|
||||||
|
>
|
||||||
|
mailto:{resolvedRelay.contact}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<div>
|
||||||
|
<h5 className="text-sm font-semibold text-white/70">Software:</h5>
|
||||||
|
<a
|
||||||
|
href={resolvedRelay.software}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
className="underline after:content-['_↗'] hover:text-fuchsia-500"
|
||||||
|
>
|
||||||
|
{getSoftwareName(resolvedRelay.software) +
|
||||||
|
' - ' +
|
||||||
|
resolvedRelay.version}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h5 className="text-sm font-semibold text-white/70">
|
||||||
|
Supported NIPs:
|
||||||
|
</h5>
|
||||||
|
<div className="mt-2 grid grid-cols-7 gap-2">
|
||||||
|
{resolvedRelay.supported_nips.map((item: string) => (
|
||||||
|
<a
|
||||||
|
key={item}
|
||||||
|
href={`https://nips.be/${item}`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
className="inline-flex aspect-square h-full w-full items-center justify-center rounded-lg bg-white/10 text-sm font-medium hover:bg-fuchsia-500"
|
||||||
|
>
|
||||||
|
{item}
|
||||||
|
</a>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{resolvedRelay.limitation ? (
|
||||||
|
<div>
|
||||||
|
<h5 className="text-sm font-semibold text-white/70">Limitation</h5>
|
||||||
|
<div className="flex flex-col gap-2 divide-y divide-white/5">
|
||||||
|
{Object.keys(resolvedRelay.limitation).map((key, index) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="flex items-baseline justify-between pt-2"
|
||||||
|
>
|
||||||
|
<p className="text-sm font-medium text-white">
|
||||||
|
{titleCase(key)}:
|
||||||
|
</p>
|
||||||
|
<p className="text-sm font-medium text-white/70">
|
||||||
|
{resolvedRelay.limitation[key].toString()}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{resolvedRelay.payments_url ? (
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<a
|
||||||
|
href={resolvedRelay.payments_url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
className="inline-flex h-10 w-full items-center justify-center rounded-lg bg-fuchsia-500 text-sm font-medium hover:bg-fuchsia-600"
|
||||||
|
>
|
||||||
|
Open payment website
|
||||||
|
</a>
|
||||||
|
<span className="text-center text-xs text-white/70">
|
||||||
|
You need to make a payment to connect this relay
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Await>
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
import { PlusIcon } from '@shared/icons';
|
import { HandArrowDownIcon, PlusIcon } from '@shared/icons';
|
||||||
|
|
||||||
import { WidgetKinds, useWidgets } from '@stores/widgets';
|
import { WidgetKinds, useWidgets } from '@stores/widgets';
|
||||||
|
|
||||||
@@ -9,17 +9,22 @@ export function ToggleWidgetList() {
|
|||||||
const setWidget = useWidgets((state) => state.setWidget);
|
const setWidget = useWidgets((state) => state.setWidget);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative flex h-full shrink-0 grow-0 basis-[400px] items-center justify-center">
|
<div className="flex h-full shrink-0 grow-0 basis-[400px] items-center justify-center">
|
||||||
<button
|
<div className="relative">
|
||||||
type="button"
|
<div className="absolute -top-44 left-1/2 -translate-x-1/2 transform">
|
||||||
onClick={() =>
|
<HandArrowDownIcon className="text-white/5" />
|
||||||
setWidget(db, { kind: WidgetKinds.tmp.list, title: '', content: '' })
|
</div>
|
||||||
}
|
<button
|
||||||
className="inline-flex items-center gap-2 text-white"
|
type="button"
|
||||||
>
|
onClick={() =>
|
||||||
<PlusIcon className="h-4 w-4 text-white" />
|
setWidget(db, { kind: WidgetKinds.tmp.list, title: '', content: '' })
|
||||||
<p className="text-sm font-bold leading-none">Add widget</p>
|
}
|
||||||
</button>
|
className="inline-flex h-9 items-center gap-2 rounded-lg border-t border-white/10 bg-white/20 px-3 text-white hover:bg-white/30"
|
||||||
|
>
|
||||||
|
<PlusIcon className="h-4 w-4 text-white" />
|
||||||
|
<p className="text-sm font-semibold leading-none">Add widget</p>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,18 @@ import { useCallback } from 'react';
|
|||||||
|
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ArticleIcon,
|
||||||
|
FileIcon,
|
||||||
|
FollowsIcon,
|
||||||
|
GroupFeedsIcon,
|
||||||
|
HashtagIcon,
|
||||||
|
ThreadsIcon,
|
||||||
|
TrendingIcon,
|
||||||
|
} from '@shared/icons';
|
||||||
import { TitleBar } from '@shared/titleBar';
|
import { TitleBar } from '@shared/titleBar';
|
||||||
|
|
||||||
import { DefaultWidgets, useWidgets } from '@stores/widgets';
|
import { DefaultWidgets, WidgetKinds, useWidgets } from '@stores/widgets';
|
||||||
|
|
||||||
import { Widget, WidgetGroup, WidgetGroupItem } from '@utils/types';
|
import { Widget, WidgetGroup, WidgetGroupItem } from '@utils/types';
|
||||||
|
|
||||||
@@ -20,16 +29,63 @@ export function WidgetList({ params }: { params: Widget }) {
|
|||||||
removeWidget(db, params.id);
|
removeWidget(db, params.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderIcon = useCallback(
|
||||||
|
(kind: number) => {
|
||||||
|
switch (kind) {
|
||||||
|
case WidgetKinds.tmp.xfeed:
|
||||||
|
return <GroupFeedsIcon className="h-5 w-5 text-white" />;
|
||||||
|
case WidgetKinds.local.follows:
|
||||||
|
return <FollowsIcon className="h-5 w-5 text-white" />;
|
||||||
|
case WidgetKinds.local.files:
|
||||||
|
case WidgetKinds.global.files:
|
||||||
|
return <FileIcon className="h-5 w-5 text-white" />;
|
||||||
|
case WidgetKinds.local.articles:
|
||||||
|
case WidgetKinds.global.articles:
|
||||||
|
return <ArticleIcon className="h-5 w-5 text-white" />;
|
||||||
|
case WidgetKinds.tmp.xhashtag:
|
||||||
|
return <HashtagIcon className="h-5 w-4 text-white" />;
|
||||||
|
case WidgetKinds.nostrBand.trendingAccounts:
|
||||||
|
case WidgetKinds.nostrBand.trendingNotes:
|
||||||
|
return <TrendingIcon className="h-5 w-4 text-white" />;
|
||||||
|
case WidgetKinds.other.learnNostr:
|
||||||
|
return <ThreadsIcon className="h-5 w-4 text-white" />;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[DefaultWidgets]
|
||||||
|
);
|
||||||
|
|
||||||
const renderItem = useCallback(
|
const renderItem = useCallback(
|
||||||
(row: WidgetGroup) => {
|
(row: WidgetGroup) => {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
<h3 className="font-medium text-white/50">{row.title}</h3>
|
<h3 className="font-medium text-white/50">{row.title}</h3>
|
||||||
<div className="grid grid-cols-3 gap-6">
|
<div className="flex flex-col divide-y divide-white/5 overflow-hidden rounded-xl bg-white/10">
|
||||||
{row.data.map((item, index) => (
|
{row.data.map((item, index) => (
|
||||||
<button onClick={() => openWidget(item)} key={index}>
|
<button
|
||||||
<div className="inline-flex aspect-square h-full w-full transform-gpu flex-col items-center justify-center gap-2.5 rounded-2xl bg-white/5 hover:bg-white/10">
|
onClick={() => openWidget(item)}
|
||||||
<h5 className="text-sm font-medium">{item.title}</h5>
|
key={index}
|
||||||
|
className="flex items-center gap-2.5 px-4 hover:bg-white/10"
|
||||||
|
>
|
||||||
|
{item.icon ? (
|
||||||
|
<div className="h-10 w-10 shrink-0 rounded-md">
|
||||||
|
<img
|
||||||
|
src={item.icon}
|
||||||
|
alt={item.title}
|
||||||
|
className="h-10 w-10 object-cover"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-md bg-white/10">
|
||||||
|
{renderIcon(item.kind)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="inline-flex h-16 w-full flex-col items-start justify-center gap-1">
|
||||||
|
<h5 className="line-clamp-1 font-medium leading-none">{item.title}</h5>
|
||||||
|
<p className="line-clamp-1 text-xs leading-none text-white/50">
|
||||||
|
{item.description}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
@@ -41,10 +97,26 @@ export function WidgetList({ params }: { params: Widget }) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative h-full shrink-0 grow-0 basis-[400px] overflow-hidden">
|
<div className="relative h-full shrink-0 grow-0 basis-[400px] bg-white/10">
|
||||||
<TitleBar id={params.id} title="Add widget" />
|
<TitleBar id={params.id} title="Add widget" />
|
||||||
<div className="flex flex-col gap-8 px-3">
|
<div className="scrollbar-hide h-full overflow-y-auto pb-20">
|
||||||
{DefaultWidgets.map((row: WidgetGroup) => renderItem(row))}
|
<div className="flex flex-col gap-6 px-3">
|
||||||
|
{DefaultWidgets.map((row: WidgetGroup) => renderItem(row))}
|
||||||
|
<div className="border-t border-white/5 pt-6">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled
|
||||||
|
className="inline-flex h-14 w-full items-center justify-center gap-2.5 rounded-xl bg-white/5 text-sm font-medium text-white/50"
|
||||||
|
>
|
||||||
|
Build your own widget{' '}
|
||||||
|
<div className="-rotate-3 transform rounded-md border border-white/20 bg-white/10 px-1.5 py-1">
|
||||||
|
<span className="bg-gradient-to-t from-fuchsia-200 via-red-200 to-orange-300 bg-clip-text text-xs text-transparent">
|
||||||
|
Coming soon
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ import {
|
|||||||
GlobalArticlesWidget,
|
GlobalArticlesWidget,
|
||||||
GlobalFilesWidget,
|
GlobalFilesWidget,
|
||||||
GlobalHashtagWidget,
|
GlobalHashtagWidget,
|
||||||
|
LearnNostrWidget,
|
||||||
LocalArticlesWidget,
|
LocalArticlesWidget,
|
||||||
LocalFeedsWidget,
|
LocalFeedsWidget,
|
||||||
LocalFilesWidget,
|
LocalFilesWidget,
|
||||||
|
LocalFollowsWidget,
|
||||||
LocalNetworkWidget,
|
LocalNetworkWidget,
|
||||||
LocalThreadWidget,
|
LocalThreadWidget,
|
||||||
LocalUserWidget,
|
LocalUserWidget,
|
||||||
@@ -40,6 +42,8 @@ export function SpaceScreen() {
|
|||||||
switch (widget.kind) {
|
switch (widget.kind) {
|
||||||
case WidgetKinds.local.network:
|
case WidgetKinds.local.network:
|
||||||
return <LocalNetworkWidget key={widget.id} />;
|
return <LocalNetworkWidget key={widget.id} />;
|
||||||
|
case WidgetKinds.local.follows:
|
||||||
|
return <LocalFollowsWidget key={widget.id} params={widget} />;
|
||||||
case WidgetKinds.local.feeds:
|
case WidgetKinds.local.feeds:
|
||||||
return <LocalFeedsWidget key={widget.id} params={widget} />;
|
return <LocalFeedsWidget key={widget.id} params={widget} />;
|
||||||
case WidgetKinds.local.files:
|
case WidgetKinds.local.files:
|
||||||
@@ -61,13 +65,15 @@ export function SpaceScreen() {
|
|||||||
case WidgetKinds.nostrBand.trendingNotes:
|
case WidgetKinds.nostrBand.trendingNotes:
|
||||||
return <TrendingNotesWidget key={widget.id} params={widget} />;
|
return <TrendingNotesWidget key={widget.id} params={widget} />;
|
||||||
case WidgetKinds.tmp.xfeed:
|
case WidgetKinds.tmp.xfeed:
|
||||||
return <XhashtagWidget key={widget.id} params={widget} />;
|
|
||||||
case WidgetKinds.tmp.xhashtag:
|
|
||||||
return <XfeedsWidget key={widget.id} params={widget} />;
|
return <XfeedsWidget key={widget.id} params={widget} />;
|
||||||
|
case WidgetKinds.tmp.xhashtag:
|
||||||
|
return <XhashtagWidget key={widget.id} params={widget} />;
|
||||||
case WidgetKinds.tmp.list:
|
case WidgetKinds.tmp.list:
|
||||||
return <WidgetList key={widget.id} params={widget} />;
|
return <WidgetList key={widget.id} params={widget} />;
|
||||||
|
case WidgetKinds.other.learnNostr:
|
||||||
|
return <LearnNostrWidget key={widget.id} params={widget} />;
|
||||||
default:
|
default:
|
||||||
break;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[widgets]
|
[widgets]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { message } from '@tauri-apps/api/dialog';
|
import { message } from '@tauri-apps/api/dialog';
|
||||||
import { invoke } from '@tauri-apps/api/tauri';
|
import { invoke } from '@tauri-apps/api/tauri';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
import { useNDK } from '@libs/ndk/provider';
|
import { useNDK } from '@libs/ndk/provider';
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
@@ -12,81 +12,52 @@ import { useNostr } from '@utils/hooks/useNostr';
|
|||||||
export function SplashScreen() {
|
export function SplashScreen() {
|
||||||
const { db } = useStorage();
|
const { db } = useStorage();
|
||||||
const { ndk } = useNDK();
|
const { ndk } = useNDK();
|
||||||
const { fetchUserData, prefetchEvents } = useNostr();
|
const { fetchUserData } = useNostr();
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(true);
|
|
||||||
const [errorMessage, setErrorMessage] = useState<null | string>(null);
|
|
||||||
|
|
||||||
const skip = async () => {
|
|
||||||
await invoke('close_splashscreen');
|
|
||||||
};
|
|
||||||
|
|
||||||
const prefetch = async () => {
|
|
||||||
const onboarding = localStorage.getItem('onboarding');
|
|
||||||
const step = JSON.parse(onboarding).state.step || null;
|
|
||||||
if (step) await invoke('close_splashscreen');
|
|
||||||
|
|
||||||
try {
|
|
||||||
const user = await fetchUserData();
|
|
||||||
const data = await prefetchEvents();
|
|
||||||
|
|
||||||
if (user.status === 'ok' && data.status === 'ok') {
|
|
||||||
await db.updateLastLogin();
|
|
||||||
await invoke('close_splashscreen');
|
|
||||||
} else {
|
|
||||||
setIsLoading(false);
|
|
||||||
setErrorMessage(user.message);
|
|
||||||
console.log('fetch failed, error: ', user.message);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
setIsLoading(false);
|
|
||||||
setErrorMessage(e);
|
|
||||||
await message(`Something wrong: ${e}`, {
|
|
||||||
title: 'Lume',
|
|
||||||
type: 'error',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (ndk) {
|
async function syncUserData() {
|
||||||
if (!db.account) invoke('close_splashscreen');
|
if (!db.account) {
|
||||||
|
await invoke('close_splashscreen');
|
||||||
|
} else {
|
||||||
|
const onboarding = localStorage.getItem('onboarding');
|
||||||
|
const step = JSON.parse(onboarding).state.step || null;
|
||||||
|
|
||||||
console.log('prefetching...');
|
if (step) {
|
||||||
prefetch();
|
await invoke('close_splashscreen');
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
const userData = await fetchUserData();
|
||||||
|
if (userData.status === 'ok') {
|
||||||
|
// update last login = current time
|
||||||
|
await db.updateLastLogin();
|
||||||
|
// close splash screen and open main app screen
|
||||||
|
await invoke('close_splashscreen');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
await message(e, {
|
||||||
|
title: 'An unexpected error has occurred',
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
await invoke('close_splashscreen');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ndk) {
|
||||||
|
syncUserData();
|
||||||
}
|
}
|
||||||
}, [ndk, db.account]);
|
}, [ndk, db.account]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative flex h-screen w-screen items-center justify-center bg-black">
|
<div className="relative flex h-screen w-screen items-center justify-center bg-black">
|
||||||
<div data-tauri-drag-region className="absolute left-0 top-0 z-10 h-11 w-full" />
|
<div data-tauri-drag-region className="absolute left-0 top-0 z-10 h-11 w-full" />
|
||||||
<div className="flex min-h-0 w-full flex-1 items-center justify-center">
|
<div className="flex min-h-0 w-full flex-1 items-center justify-center px-8">
|
||||||
<div className="flex flex-col items-center justify-center gap-4">
|
<div className="flex flex-col items-center justify-center gap-6">
|
||||||
<LoaderIcon className="h-6 w-6 animate-spin text-white" />
|
<LoaderIcon className="h-6 w-6 animate-spin text-white" />
|
||||||
{isLoading ? (
|
<h3 className="text-lg font-semibold leading-none text-white">
|
||||||
<div className="flex flex-col gap-1 text-center">
|
{!ndk ? 'Connecting...' : 'Syncing...'}
|
||||||
<h3 className="text-lg font-semibold leading-none text-white">
|
</h3>
|
||||||
{!ndk ? 'Connecting to relay...' : 'Fetching events from the last login.'}
|
|
||||||
</h3>
|
|
||||||
<p className="text-sm text-white/50">
|
|
||||||
This may take a few seconds, please don't close app.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="mt-2 flex flex-col gap-1 text-center">
|
|
||||||
<h3 className="text-lg font-semibold leading-none text-white">
|
|
||||||
Something wrong!
|
|
||||||
</h3>
|
|
||||||
<p className="text-sm text-white/50">{errorMessage}</p>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={skip}
|
|
||||||
className="mx-auto mt-4 inline-flex h-10 w-max items-center justify-center rounded-md bg-white/10 px-8 text-sm font-medium leading-none text-white backdrop-blur-xl hover:bg-white/20"
|
|
||||||
>
|
|
||||||
Skip
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ export function EditProfileModal() {
|
|||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={!isValid}
|
disabled={!isValid}
|
||||||
className="inline-flex h-11 w-full transform items-center justify-center gap-1 rounded-md bg-fuchsia-500 font-medium text-white hover:bg-fuchsia-600 focus:outline-none active:translate-y-1 disabled:pointer-events-none disabled:opacity-50"
|
className="inline-flex h-11 w-full transform items-center justify-center gap-1 rounded-lg bg-fuchsia-500 font-medium text-white hover:bg-fuchsia-600 focus:outline-none active:translate-y-1 disabled:pointer-events-none disabled:opacity-50"
|
||||||
>
|
>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<LoaderIcon className="h-4 w-4 animate-spin text-black dark:text-white" />
|
<LoaderIcon className="h-4 w-4 animate-spin text-black dark:text-white" />
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export function UserProfile({ pubkey }: { pubkey: string }) {
|
|||||||
<div className="flex flex-col items-center gap-1">
|
<div className="flex flex-col items-center gap-1">
|
||||||
<div className="inline-flex flex-col items-center gap-1.5">
|
<div className="inline-flex flex-col items-center gap-1.5">
|
||||||
<h5 className="text-center text-xl font-semibold leading-none">
|
<h5 className="text-center text-xl font-semibold leading-none">
|
||||||
{user.display_name || user.displayName || user.name || 'No name'}
|
{user.name || user.display_name || user.displayName || 'No name'}
|
||||||
</h5>
|
</h5>
|
||||||
{user.nip05 ? (
|
{user.nip05 ? (
|
||||||
<NIP05
|
<NIP05
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
|
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useVirtualizer } from '@tanstack/react-virtual';
|
import { useCallback } from 'react';
|
||||||
import { useCallback, useRef } from 'react';
|
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
|
import { WVList } from 'virtua';
|
||||||
|
|
||||||
import { UserProfile } from '@app/users/components/profile';
|
import { UserProfile } from '@app/users/components/profile';
|
||||||
|
|
||||||
@@ -32,79 +32,35 @@ export function UserScreen() {
|
|||||||
return [...events] as unknown as NDKEvent[];
|
return [...events] as unknown as NDKEvent[];
|
||||||
});
|
});
|
||||||
|
|
||||||
const parentRef = useRef();
|
|
||||||
const virtualizer = useVirtualizer({
|
|
||||||
count: data ? data.length : 0,
|
|
||||||
getScrollElement: () => parentRef.current,
|
|
||||||
estimateSize: () => 650,
|
|
||||||
overscan: 4,
|
|
||||||
});
|
|
||||||
const items = virtualizer.getVirtualItems();
|
|
||||||
|
|
||||||
// render event match event kind
|
// render event match event kind
|
||||||
const renderItem = useCallback(
|
const renderItem = useCallback(
|
||||||
(index: string | number) => {
|
(event: NDKEvent) => {
|
||||||
const event: NDKEvent = data[index];
|
|
||||||
if (!event) return;
|
|
||||||
|
|
||||||
switch (event.kind) {
|
switch (event.kind) {
|
||||||
case NDKKind.Text:
|
case NDKKind.Text:
|
||||||
return (
|
return (
|
||||||
<div
|
<NoteWrapper key={event.id} event={event}>
|
||||||
key={event.id + index}
|
<TextNote />
|
||||||
data-index={index}
|
</NoteWrapper>
|
||||||
ref={virtualizer.measureElement}
|
|
||||||
>
|
|
||||||
<NoteWrapper event={event}>
|
|
||||||
<TextNote content={event.content} />
|
|
||||||
</NoteWrapper>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
case NDKKind.Repost:
|
case NDKKind.Repost:
|
||||||
return (
|
return <Repost key={event.id} event={event} />;
|
||||||
<div
|
|
||||||
key={event.id + index}
|
|
||||||
data-index={index}
|
|
||||||
ref={virtualizer.measureElement}
|
|
||||||
>
|
|
||||||
<Repost key={event.id} event={event} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
case 1063:
|
case 1063:
|
||||||
return (
|
return (
|
||||||
<div
|
<NoteWrapper key={event.id} event={event}>
|
||||||
key={event.id + index}
|
<FileNote />
|
||||||
data-index={index}
|
</NoteWrapper>
|
||||||
ref={virtualizer.measureElement}
|
|
||||||
>
|
|
||||||
<NoteWrapper event={event}>
|
|
||||||
<FileNote event={event} />
|
|
||||||
</NoteWrapper>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
case NDKKind.Article:
|
case NDKKind.Article:
|
||||||
return (
|
return (
|
||||||
<div
|
<NoteWrapper key={event.id} event={event}>
|
||||||
key={event.id + index}
|
<ArticleNote />
|
||||||
data-index={index}
|
</NoteWrapper>
|
||||||
ref={virtualizer.measureElement}
|
|
||||||
>
|
|
||||||
<NoteWrapper event={event}>
|
|
||||||
<ArticleNote event={event} />
|
|
||||||
</NoteWrapper>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return (
|
return (
|
||||||
<div
|
<NoteWrapper key={event.id} event={event}>
|
||||||
key={event.id + index}
|
<UnknownNote />
|
||||||
data-index={index}
|
</NoteWrapper>
|
||||||
ref={virtualizer.measureElement}
|
|
||||||
>
|
|
||||||
<NoteWrapper event={event}>
|
|
||||||
<UnknownNote event={event} />
|
|
||||||
</NoteWrapper>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -112,10 +68,7 @@ export function UserScreen() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className="scrollbar-hide relative h-full w-full overflow-y-auto bg-white/10 backdrop-blur-xl">
|
||||||
ref={parentRef}
|
|
||||||
className="scrollbar-hide relative h-full w-full overflow-y-auto bg-white/10 backdrop-blur-xl"
|
|
||||||
>
|
|
||||||
<div data-tauri-drag-region className="absolute left-0 top-0 h-11 w-full" />
|
<div data-tauri-drag-region className="absolute left-0 top-0 h-11 w-full" />
|
||||||
<UserProfile pubkey={pubkey} />
|
<UserProfile pubkey={pubkey} />
|
||||||
<div className="mt-6 h-full w-full border-t border-white/5 px-1.5">
|
<div className="mt-6 h-full w-full border-t border-white/5 px-1.5">
|
||||||
@@ -129,7 +82,7 @@ export function UserScreen() {
|
|||||||
<NoteSkeleton />
|
<NoteSkeleton />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : items.length === 0 ? (
|
) : data.length === 0 ? (
|
||||||
<div className="px-3 py-1.5">
|
<div className="px-3 py-1.5">
|
||||||
<div className="rounded-xl bg-white/10 px-3 py-6 backdrop-blur-xl">
|
<div className="rounded-xl bg-white/10 px-3 py-6 backdrop-blur-xl">
|
||||||
<div className="flex flex-col items-center gap-4">
|
<div className="flex flex-col items-center gap-4">
|
||||||
@@ -140,22 +93,10 @@ export function UserScreen() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div
|
<WVList>
|
||||||
style={{
|
{data.map((item) => renderItem(item))}
|
||||||
position: 'relative',
|
<div className="h-16" />
|
||||||
width: '100%',
|
</WVList>
|
||||||
height: `${virtualizer.getTotalSize()}px`,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className="absolute left-0 top-0 w-full"
|
|
||||||
style={{
|
|
||||||
transform: `translateY(${items[0].start}px)`,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{items.map((item) => renderItem(item.index))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
@import 'reactflow/dist/style.css';
|
||||||
|
@import '@vidstack/react/player/styles/default/theme.css';
|
||||||
|
@import '@vidstack/react/player/styles/default/layouts/audio.css';
|
||||||
|
@import '@vidstack/react/player/styles/default/layouts/video.css';
|
||||||
|
|
||||||
@tailwind base;
|
@tailwind base;
|
||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
@@ -6,11 +11,6 @@ html {
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
input::-ms-reveal,
|
|
||||||
input::-ms-clear {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
a {
|
||||||
@apply cursor-default no-underline !important;
|
@apply cursor-default no-underline !important;
|
||||||
}
|
}
|
||||||
@@ -19,8 +19,46 @@ button {
|
|||||||
@apply cursor-default focus:outline-none;
|
@apply cursor-default focus:outline-none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iframe {
|
||||||
|
height: auto !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
span[data-slate-placeholder] {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
input::-ms-reveal,
|
||||||
|
input::-ms-clear {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-input-placeholder {
|
||||||
|
line-height: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.border {
|
||||||
|
background-clip: padding-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scrollbar-hide::-webkit-scrollbar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scrollbar-hide {
|
||||||
|
-ms-overflow-style: none;
|
||||||
|
scrollbar-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
.markdown {
|
.markdown {
|
||||||
@apply prose prose-white max-w-none select-text hyphens-auto text-white prose-p:mb-0 prose-p:mt-0 prose-p:break-words prose-p:[word-break:break-word] prose-p:last:mb-0 prose-a:break-words prose-a:break-all prose-a:font-normal hover:prose-a:text-fuchsia-500 prose-blockquote:mb-1 prose-blockquote:mt-1 prose-blockquote:border-l-[2px] prose-blockquote:border-fuchsia-500 prose-blockquote:pl-2 prose-pre:whitespace-pre-wrap prose-pre:break-words prose-pre:break-all prose-ol:m-0 prose-ol:mb-1 prose-ul:mb-1 prose-ul:mt-1 prose-img:mb-2 prose-img:mt-3 prose-hr:mx-0 prose-hr:my-2;
|
@apply prose prose-white max-w-none select-text hyphens-auto text-white prose-headings:mb-1 prose-headings:mt-3 prose-p:mb-0 prose-p:mt-0 prose-p:break-words prose-p:[word-break:break-word] prose-p:last:mb-0 prose-a:break-words prose-a:break-all prose-a:font-normal hover:prose-a:text-fuchsia-500 prose-blockquote:mb-1 prose-blockquote:mt-1 prose-blockquote:border-l-[2px] prose-blockquote:border-fuchsia-500 prose-blockquote:pl-2 prose-pre:whitespace-pre-wrap prose-pre:break-words prose-pre:break-all prose-pre:bg-white/10 prose-ol:m-0 prose-ol:mb-1 prose-ul:mb-1 prose-ul:mt-1 prose-img:mb-2 prose-img:mt-3 prose-hr:mx-0 prose-hr:my-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-article {
|
||||||
|
@apply prose prose-white max-w-none select-text hyphens-auto text-white/80 prose-headings:mb-1 prose-headings:mt-3 prose-headings:text-white prose-p:mb-2 prose-p:mt-0 prose-p:break-words prose-p:[word-break:break-word] prose-a:break-words prose-a:break-all prose-a:font-normal hover:prose-a:text-fuchsia-500 prose-blockquote:mb-1 prose-blockquote:mt-1 prose-blockquote:border-l-[2px] prose-blockquote:border-fuchsia-500 prose-blockquote:pl-2 prose-pre:whitespace-pre-wrap prose-pre:break-words prose-pre:break-all prose-pre:bg-white/10 prose-ol:m-0 prose-ol:mb-1 prose-ul:mb-1 prose-ul:mt-1 prose-img:mb-2 prose-img:mt-3 prose-hr:mx-0 prose-hr:my-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-simple {
|
||||||
|
@apply prose prose-white max-w-none select-text hyphens-auto text-white/70 prose-headings:mb-1 prose-headings:mt-3 prose-p:mb-0 prose-p:mt-0 prose-p:break-words prose-p:[word-break:break-word] prose-p:last:mb-0 prose-a:break-words prose-a:break-all prose-a:font-normal hover:prose-a:text-fuchsia-500 prose-blockquote:mb-1 prose-blockquote:mt-1 prose-blockquote:border-l-[2px] prose-blockquote:border-fuchsia-500 prose-blockquote:pl-2 prose-pre:whitespace-pre-wrap prose-pre:break-words prose-pre:break-all prose-pre:bg-white/10 prose-ol:m-0 prose-ol:mb-1 prose-ul:mb-1 prose-ul:mt-1 prose-img:mb-2 prose-img:mt-3 prose-hr:mx-0 prose-hr:my-2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ProseMirror p.is-empty::before {
|
.ProseMirror p.is-empty::before {
|
||||||
@@ -35,25 +73,32 @@ button {
|
|||||||
@apply outline-fuchsia-500;
|
@apply outline-fuchsia-500;
|
||||||
}
|
}
|
||||||
|
|
||||||
iframe {
|
.player {
|
||||||
height: auto !important;
|
--brand-color: #f5f5f5;
|
||||||
|
--focus-color: #4e9cf6;
|
||||||
|
|
||||||
|
--audio-brand: var(--brand-color);
|
||||||
|
--audio-focus-ring-color: var(--focus-color);
|
||||||
|
--audio-border-radius: 2px;
|
||||||
|
|
||||||
|
--video-brand: var(--brand-color);
|
||||||
|
--video-focus-ring-color: var(--focus-color);
|
||||||
|
--video-border-radius: 8px;
|
||||||
|
|
||||||
|
/* 👉 https://vidstack.io/docs/player/components/layouts/default#css-variables for more. */
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For Webkit-based browsers (Chrome, Safari and Opera) */
|
.player[data-view-type='video'] {
|
||||||
.scrollbar-hide::-webkit-scrollbar {
|
aspect-ratio: 16 /9;
|
||||||
display: none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For IE, Edge and Firefox */
|
.src-buttons {
|
||||||
.scrollbar-hide {
|
display: flex;
|
||||||
-ms-overflow-style: none; /* IE and Edge */
|
align-items: center;
|
||||||
scrollbar-width: none; /* Firefox */
|
justify-content: space-evenly;
|
||||||
}
|
margin-top: 40px;
|
||||||
|
margin-inline: auto;
|
||||||
.border {
|
max-width: 300px;
|
||||||
background-clip: padding-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
span[data-slate-placeholder] {
|
|
||||||
@apply top-0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,89 +1,67 @@
|
|||||||
// inspire by: https://github.com/nostr-dev-kit/ndk-react/
|
|
||||||
import NDK from '@nostr-dev-kit/ndk';
|
import NDK from '@nostr-dev-kit/ndk';
|
||||||
|
import NDKCacheAdapterDexie from '@nostr-dev-kit/ndk-cache-dexie';
|
||||||
|
import { ndkAdapter } from '@nostr-fetch/adapter-ndk';
|
||||||
import { message } from '@tauri-apps/api/dialog';
|
import { message } from '@tauri-apps/api/dialog';
|
||||||
|
import { fetch } from '@tauri-apps/api/http';
|
||||||
|
import { NostrFetcher } from 'nostr-fetch';
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import TauriAdapter from '@libs/ndk/cache';
|
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
import { FULL_RELAYS } from '@stores/constants';
|
|
||||||
|
|
||||||
export const NDKInstance = () => {
|
export const NDKInstance = () => {
|
||||||
const { db } = useStorage();
|
|
||||||
|
|
||||||
const [ndk, setNDK] = useState<NDK | undefined>(undefined);
|
const [ndk, setNDK] = useState<NDK | undefined>(undefined);
|
||||||
const [relayUrls, setRelayUrls] = useState<string[]>([]);
|
const [relayUrls, setRelayUrls] = useState<string[]>([]);
|
||||||
|
|
||||||
const cacheAdapter = useMemo(() => new TauriAdapter(), [ndk]);
|
const { db } = useStorage();
|
||||||
|
const fetcher = useMemo(
|
||||||
|
() => (ndk ? NostrFetcher.withCustomPool(ndkAdapter(ndk)) : null),
|
||||||
|
[ndk]
|
||||||
|
);
|
||||||
|
|
||||||
// TODO: fully support NIP-11
|
// TODO: fully support NIP-11
|
||||||
async function verifyRelays(relays: string[]) {
|
async function getExplicitRelays() {
|
||||||
try {
|
try {
|
||||||
const urls: string[] = relays.map((relay) => {
|
// get relays
|
||||||
if (relay.startsWith('ws')) {
|
const relays = await db.getExplicitRelayUrls();
|
||||||
return relay.replace('ws', 'http');
|
const onlineRelays = new Set(relays);
|
||||||
|
|
||||||
|
for (const relay of relays) {
|
||||||
|
try {
|
||||||
|
const url = new URL(relay);
|
||||||
|
const res = await fetch(`https://${url.hostname}`, {
|
||||||
|
method: 'GET',
|
||||||
|
timeout: { secs: 5, nanos: 0 },
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/nostr+json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
console.info(`${relay} is not working, skipping...`);
|
||||||
|
onlineRelays.delete(relay);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
console.warn(`${relay} is not working, skipping...`);
|
||||||
|
onlineRelays.delete(relay);
|
||||||
}
|
}
|
||||||
if (relay.startsWith('wss')) {
|
|
||||||
return relay.replace('wss', 'https');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const controller = new AbortController();
|
|
||||||
const timeoutId = setTimeout(() => controller.abort('timeout'), 10000);
|
|
||||||
|
|
||||||
const requests = urls.map((url) =>
|
|
||||||
fetch(url, {
|
|
||||||
headers: { Accept: 'application/nostr+json' },
|
|
||||||
signal: controller.signal,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const responses = await Promise.all(requests);
|
|
||||||
const errors = responses.filter((response) => !response.ok);
|
|
||||||
|
|
||||||
if (errors.length > 0) {
|
|
||||||
throw errors.map((response) => Error(response.statusText));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const verifiedRelays: string[] = responses.map((res) => {
|
// return all online relays
|
||||||
if (res.url.startsWith('http')) {
|
return [...onlineRelays];
|
||||||
return res.url.replace('htto', 'ws');
|
|
||||||
}
|
|
||||||
if (res.url.startsWith('https')) {
|
|
||||||
return res.url.replace('https', 'wss');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// clear timeout
|
|
||||||
clearTimeout(timeoutId);
|
|
||||||
|
|
||||||
// return all validate relays
|
|
||||||
return verifiedRelays;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('verify relay failed with error: ', e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initNDK() {
|
async function initNDK() {
|
||||||
let explicitRelayUrls: string[];
|
const explicitRelayUrls = await getExplicitRelays();
|
||||||
const explicitRelayUrlsFromDB = await db.getExplicitRelayUrls();
|
const dexieAdapter = new NDKCacheAdapterDexie({ dbName: 'lume_ndkcache' });
|
||||||
|
const instance = new NDK({
|
||||||
|
explicitRelayUrls,
|
||||||
|
// @ts-expect-error, wtf?
|
||||||
|
cacheAdapter: dexieAdapter,
|
||||||
|
});
|
||||||
|
|
||||||
console.log('relays in db: ', explicitRelayUrlsFromDB);
|
|
||||||
console.log('ndk cache adapter: ', cacheAdapter);
|
|
||||||
|
|
||||||
if (explicitRelayUrlsFromDB) {
|
|
||||||
explicitRelayUrls = await verifyRelays(explicitRelayUrlsFromDB);
|
|
||||||
} else {
|
|
||||||
explicitRelayUrls = await verifyRelays(FULL_RELAYS);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (explicitRelayUrls.length < 1) {
|
|
||||||
await message('Something is wrong. No relays have been found.', {
|
|
||||||
title: 'Lume',
|
|
||||||
type: 'error',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const instance = new NDK({ explicitRelayUrls, cacheAdapter });
|
|
||||||
try {
|
try {
|
||||||
await instance.connect(10000);
|
await instance.connect(10000);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -99,14 +77,11 @@ export const NDKInstance = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ndk) initNDK();
|
if (!ndk) initNDK();
|
||||||
|
|
||||||
return () => {
|
|
||||||
cacheAdapter.saveCache();
|
|
||||||
};
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ndk,
|
ndk,
|
||||||
relayUrls,
|
relayUrls,
|
||||||
|
fetcher,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,27 +1,31 @@
|
|||||||
// source: https://github.com/nostr-dev-kit/ndk-react/
|
// source: https://github.com/nostr-dev-kit/ndk-react/
|
||||||
import NDK from '@nostr-dev-kit/ndk';
|
import NDK from '@nostr-dev-kit/ndk';
|
||||||
|
import { NostrFetcher } from 'nostr-fetch';
|
||||||
import { PropsWithChildren, createContext, useContext } from 'react';
|
import { PropsWithChildren, createContext, useContext } from 'react';
|
||||||
|
|
||||||
import { NDKInstance } from '@libs/ndk/instance';
|
import { NDKInstance } from '@libs/ndk/instance';
|
||||||
|
|
||||||
interface NDKContext {
|
interface NDKContext {
|
||||||
ndk: NDK;
|
ndk: undefined | NDK;
|
||||||
relayUrls: string[];
|
relayUrls: string[];
|
||||||
|
fetcher: NostrFetcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NDKContext = createContext<NDKContext>({
|
const NDKContext = createContext<NDKContext>({
|
||||||
ndk: new NDK({}),
|
ndk: undefined,
|
||||||
relayUrls: [],
|
relayUrls: [],
|
||||||
|
fetcher: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const NDKProvider = ({ children }: PropsWithChildren<object>) => {
|
const NDKProvider = ({ children }: PropsWithChildren<object>) => {
|
||||||
const { ndk, relayUrls } = NDKInstance();
|
const { ndk, relayUrls, fetcher } = NDKInstance();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NDKContext.Provider
|
<NDKContext.Provider
|
||||||
value={{
|
value={{
|
||||||
ndk,
|
ndk,
|
||||||
relayUrls,
|
relayUrls,
|
||||||
|
fetcher,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -4,44 +4,50 @@ import { Platform } from '@tauri-apps/api/os';
|
|||||||
import Database from 'tauri-plugin-sql-api';
|
import Database from 'tauri-plugin-sql-api';
|
||||||
import { Stronghold } from 'tauri-plugin-stronghold-api';
|
import { Stronghold } from 'tauri-plugin-stronghold-api';
|
||||||
|
|
||||||
|
import { FULL_RELAYS } from '@stores/constants';
|
||||||
|
|
||||||
import { Account, DBEvent, Relays, Widget } from '@utils/types';
|
import { Account, DBEvent, Relays, Widget } from '@utils/types';
|
||||||
|
|
||||||
export class LumeStorage {
|
export class LumeStorage {
|
||||||
public db: Database;
|
public db: Database;
|
||||||
public platform: Platform;
|
|
||||||
public secureDB: Stronghold;
|
public secureDB: Stronghold;
|
||||||
public account: Account | null = null;
|
public account: Account | null;
|
||||||
|
public platform: Platform | null;
|
||||||
|
|
||||||
constructor(sqlite: Database, platform: Platform, stronghold?: Stronghold) {
|
constructor(sqlite: Database, platform?: Platform, stronghold?: Stronghold) {
|
||||||
this.db = sqlite;
|
this.db = sqlite;
|
||||||
this.platform = platform ?? undefined;
|
|
||||||
this.secureDB = stronghold ?? undefined;
|
this.secureDB = stronghold ?? undefined;
|
||||||
this.account = null;
|
this.account = null;
|
||||||
|
this.platform = platform ?? undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getSecureClient() {
|
private async getSecureClient(key?: string) {
|
||||||
try {
|
try {
|
||||||
return await this.secureDB.loadClient('lume');
|
return await this.secureDB.loadClient(key ?? 'lume');
|
||||||
} catch {
|
} catch {
|
||||||
return await this.secureDB.createClient('lume');
|
return await this.secureDB.createClient(key ?? 'lume');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async secureSave(key: string, value: string) {
|
public async secureSave(key: string, value: string, clientKey?: string) {
|
||||||
if (!this.secureDB) throw new Error("Stronghold isn't initialize");
|
if (!this.secureDB) throw new Error("Stronghold isn't initialize");
|
||||||
|
|
||||||
const client = await this.getSecureClient();
|
const client = await this.getSecureClient(clientKey);
|
||||||
const store = client.getStore();
|
const store = client.getStore();
|
||||||
|
|
||||||
await store.insert(key, Array.from(new TextEncoder().encode(value)));
|
await store.insert(key, Array.from(new TextEncoder().encode(value)));
|
||||||
return await this.secureDB.save();
|
await this.secureDB.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async secureLoad(key: string) {
|
public async secureLoad(key: string, clientKey?: string) {
|
||||||
if (!this.secureDB) throw new Error("Stronghold isn't initialize");
|
if (!this.secureDB) throw new Error("Stronghold isn't initialize");
|
||||||
|
|
||||||
const client = await this.getSecureClient();
|
const client = await this.getSecureClient(clientKey);
|
||||||
const store = client.getStore();
|
const store = client.getStore();
|
||||||
|
|
||||||
const value = await store.get(key);
|
const value = await store.get(key);
|
||||||
|
if (!value) return null;
|
||||||
|
|
||||||
const decoded = new TextDecoder().decode(new Uint8Array(value));
|
const decoded = new TextDecoder().decode(new Uint8Array(value));
|
||||||
return decoded;
|
return decoded;
|
||||||
}
|
}
|
||||||
@@ -50,6 +56,13 @@ export class LumeStorage {
|
|||||||
return await removeFile('lume.stronghold', { dir: BaseDirectory.AppConfig });
|
return await removeFile('lume.stronghold', { dir: BaseDirectory.AppConfig });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async checkAccount() {
|
||||||
|
const result: Array<{ total: string }> = await this.db.select(
|
||||||
|
'SELECT COUNT(*) AS "total" FROM accounts;'
|
||||||
|
);
|
||||||
|
return parseInt(result[0].total);
|
||||||
|
}
|
||||||
|
|
||||||
public async getActiveAccount() {
|
public async getActiveAccount() {
|
||||||
const results: Array<Account> = await this.db.select(
|
const results: Array<Account> = await this.db.select(
|
||||||
'SELECT * FROM accounts WHERE is_active = "1" ORDER BY id DESC LIMIT 1;'
|
'SELECT * FROM accounts WHERE is_active = "1" ORDER BY id DESC LIMIT 1;'
|
||||||
@@ -76,16 +89,24 @@ export class LumeStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async createAccount(npub: string, pubkey: string) {
|
public async createAccount(npub: string, pubkey: string) {
|
||||||
const res = await this.db.execute(
|
const existAccounts: Array<Account> = await this.db.select(
|
||||||
'INSERT OR IGNORE INTO accounts (npub, pubkey, privkey, is_active) VALUES ($1, $2, $3, $4);',
|
'SELECT * FROM accounts WHERE pubkey = $1 ORDER BY id DESC LIMIT 1;',
|
||||||
[npub, pubkey, 'privkey is stored in secure storage', 1]
|
[pubkey]
|
||||||
);
|
);
|
||||||
if (res) {
|
|
||||||
const account = await this.getActiveAccount();
|
if (existAccounts.length > 0) {
|
||||||
return account;
|
await this.db.execute("UPDATE accounts SET is_active = '1' WHERE pubkey = $1;", [
|
||||||
|
pubkey,
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
console.error('create account failed');
|
await this.db.execute(
|
||||||
|
'INSERT OR IGNORE INTO accounts (npub, pubkey, privkey, is_active) VALUES ($1, $2, $3, $4);',
|
||||||
|
[npub, pubkey, 'privkey is stored in secure storage', 1]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const account = await this.getActiveAccount();
|
||||||
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateAccount(column: string, value: string | string[]) {
|
public async updateAccount(column: string, value: string | string[]) {
|
||||||
@@ -102,6 +123,7 @@ export class LumeStorage {
|
|||||||
|
|
||||||
public async updateLastLogin() {
|
public async updateLastLogin() {
|
||||||
const now = Math.floor(Date.now() / 1000);
|
const now = Math.floor(Date.now() / 1000);
|
||||||
|
this.account.last_login_at = now;
|
||||||
return await this.db.execute(
|
return await this.db.execute(
|
||||||
'UPDATE accounts SET last_login_at = $1 WHERE id = $2;',
|
'UPDATE accounts SET last_login_at = $1 WHERE id = $2;',
|
||||||
[now, this.account.id]
|
[now, this.account.id]
|
||||||
@@ -137,18 +159,29 @@ export class LumeStorage {
|
|||||||
return await this.db.execute('DELETE FROM widgets WHERE id = $1;', [id]);
|
return await this.db.execute('DELETE FROM widgets WHERE id = $1;', [id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createEvent(
|
public async createEvent(event: NDKEvent) {
|
||||||
id: string,
|
let root: string;
|
||||||
event: string,
|
let reply: string;
|
||||||
author: string,
|
|
||||||
kind: number,
|
if (event.tags?.[0]?.[0] === 'e' && !event.tags?.[0]?.[3]) {
|
||||||
root_id: string,
|
root = event.tags[0][1];
|
||||||
reply_id: string,
|
} else {
|
||||||
created_at: number
|
root = event.tags.find((el) => el[3] === 'root')?.[1];
|
||||||
) {
|
reply = event.tags.find((el) => el[3] === 'reply')?.[1];
|
||||||
|
}
|
||||||
|
|
||||||
return await this.db.execute(
|
return await this.db.execute(
|
||||||
'INSERT OR IGNORE INTO events (id, account_id, event, author, kind, root_id, reply_id, created_at) VALUES ($1, $2, $3, $4, $5, $6, $7, $8);',
|
'INSERT OR IGNORE INTO events (id, account_id, event, author, kind, root_id, reply_id, created_at) VALUES ($1, $2, $3, $4, $5, $6, $7, $8);',
|
||||||
[id, this.account.id, event, author, kind, root_id, reply_id, created_at]
|
[
|
||||||
|
event.id,
|
||||||
|
this.account.id,
|
||||||
|
JSON.stringify(event),
|
||||||
|
event.pubkey,
|
||||||
|
event.kind,
|
||||||
|
root,
|
||||||
|
reply,
|
||||||
|
event.created_at,
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +197,8 @@ export class LumeStorage {
|
|||||||
|
|
||||||
public async countTotalEvents() {
|
public async countTotalEvents() {
|
||||||
const result: Array<{ total: string }> = await this.db.select(
|
const result: Array<{ total: string }> = await this.db.select(
|
||||||
'SELECT COUNT(*) AS "total" FROM events;'
|
'SELECT COUNT(*) AS "total" FROM events WHERE account_id = $1;',
|
||||||
|
[this.account.id]
|
||||||
);
|
);
|
||||||
return parseInt(result[0].total);
|
return parseInt(result[0].total);
|
||||||
}
|
}
|
||||||
@@ -179,8 +213,8 @@ export class LumeStorage {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const query: DBEvent[] = await this.db.select(
|
const query: DBEvent[] = await this.db.select(
|
||||||
'SELECT * FROM events GROUP BY root_id ORDER BY created_at DESC LIMIT $1 OFFSET $2;',
|
'SELECT * FROM events WHERE account_id = $1 GROUP BY root_id ORDER BY created_at DESC LIMIT $2 OFFSET $3;',
|
||||||
[limit, offset]
|
[this.account.id, limit, offset]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (query && query.length > 0) {
|
if (query && query.length > 0) {
|
||||||
@@ -237,8 +271,8 @@ export class LumeStorage {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const query: DBEvent[] = await this.db.select(
|
const query: DBEvent[] = await this.db.select(
|
||||||
`SELECT * FROM events WHERE kinds IN (${authorsArr}) ORDER BY created_at DESC LIMIT $1 OFFSET $2;`,
|
`SELECT * FROM events WHERE kinds IN (${authorsArr}) AND account_id = $1 ORDER BY created_at DESC LIMIT $2 OFFSET $3;`,
|
||||||
[limit, offset]
|
[this.account.id, limit, offset]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (query && query.length > 0) {
|
if (query && query.length > 0) {
|
||||||
@@ -257,24 +291,32 @@ export class LumeStorage {
|
|||||||
|
|
||||||
public async isEventsEmpty() {
|
public async isEventsEmpty() {
|
||||||
const results: DBEvent[] = await this.db.select(
|
const results: DBEvent[] = await this.db.select(
|
||||||
'SELECT * FROM events ORDER BY id DESC LIMIT 1;'
|
'SELECT * FROM events WHERE account_id = $1 ORDER BY id DESC LIMIT 1;',
|
||||||
|
[this.account.id]
|
||||||
);
|
);
|
||||||
|
|
||||||
return results.length < 1;
|
return results.length < 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getExplicitRelayUrls() {
|
public async getExplicitRelayUrls() {
|
||||||
if (!this.account) return null;
|
if (!this.account) return FULL_RELAYS;
|
||||||
|
|
||||||
const result: Relays[] = await this.db.select(
|
const result: Relays[] = await this.db.select(
|
||||||
`SELECT * FROM relays WHERE account_id = "${this.account.id}" ORDER BY id DESC LIMIT 50;`
|
`SELECT * FROM relays WHERE account_id = "${this.account.id}" ORDER BY id DESC LIMIT 50;`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.length < 1) return null;
|
if (!result || result.length < 1) return FULL_RELAYS;
|
||||||
return result.map((el) => el.relay);
|
return result.map((el) => el.relay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createRelay(relay: string, purpose?: string) {
|
public async createRelay(relay: string, purpose?: string) {
|
||||||
|
const existRelays: Relays[] = await this.db.select(
|
||||||
|
'SELECT * FROM relays WHERE relay = $1 AND account_id = $2 ORDER BY id DESC LIMIT 1;',
|
||||||
|
[relay, this.account.id]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (existRelays.length > 0) return false;
|
||||||
|
|
||||||
return await this.db.execute(
|
return await this.db.execute(
|
||||||
'INSERT OR IGNORE INTO relays (account_id, relay, purpose) VALUES ($1, $2, $3);',
|
'INSERT OR IGNORE INTO relays (account_id, relay, purpose) VALUES ($1, $2, $3);',
|
||||||
[this.account.id, relay, purpose || '']
|
[this.account.id, relay, purpose || '']
|
||||||
@@ -291,6 +333,16 @@ export class LumeStorage {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async accountLogout() {
|
||||||
|
// update current account status
|
||||||
|
await this.db.execute("UPDATE accounts SET is_active = '0' WHERE id = $1;", [
|
||||||
|
this.account.id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
this.account = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public async close() {
|
public async close() {
|
||||||
return this.db.close();
|
return this.db.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { message } from '@tauri-apps/api/dialog';
|
import { message } from '@tauri-apps/api/dialog';
|
||||||
import { platform } from '@tauri-apps/api/os';
|
import { platform } from '@tauri-apps/api/os';
|
||||||
import { appConfigDir } from '@tauri-apps/api/path';
|
|
||||||
import { PropsWithChildren, createContext, useContext, useEffect, useState } from 'react';
|
import { PropsWithChildren, createContext, useContext, useEffect, useState } from 'react';
|
||||||
import Database from 'tauri-plugin-sql-api';
|
import Database from 'tauri-plugin-sql-api';
|
||||||
|
|
||||||
@@ -17,15 +16,12 @@ const StorageContext = createContext<StorageContext>({
|
|||||||
const StorageProvider = ({ children }: PropsWithChildren<object>) => {
|
const StorageProvider = ({ children }: PropsWithChildren<object>) => {
|
||||||
const [db, setDB] = useState<LumeStorage>(undefined);
|
const [db, setDB] = useState<LumeStorage>(undefined);
|
||||||
|
|
||||||
async function initLumeStorage() {
|
const initLumeStorage = async () => {
|
||||||
try {
|
try {
|
||||||
const dir = await appConfigDir();
|
|
||||||
const sqlite = await Database.load('sqlite:lume.db');
|
const sqlite = await Database.load('sqlite:lume.db');
|
||||||
const platformName = await platform();
|
const platformName = await platform();
|
||||||
const lumeStorage = new LumeStorage(sqlite, platformName);
|
const lumeStorage = new LumeStorage(sqlite, platformName);
|
||||||
|
|
||||||
console.log('App config dir: ', dir);
|
|
||||||
|
|
||||||
if (!lumeStorage.account) await lumeStorage.getActiveAccount();
|
if (!lumeStorage.account) await lumeStorage.getActiveAccount();
|
||||||
setDB(lumeStorage);
|
setDB(lumeStorage);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -34,7 +30,7 @@ const StorageProvider = ({ children }: PropsWithChildren<object>) => {
|
|||||||
type: 'error',
|
type: 'error',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!db) initLumeStorage();
|
if (!db) initLumeStorage();
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import { NDKFilter, NDKKind } from '@nostr-dev-kit/ndk';
|
import { NDKFilter, NDKKind } from '@nostr-dev-kit/ndk';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
import { AccountMoreActions } from '@shared/accounts/more';
|
import { SettingsIcon } from '@shared/icons';
|
||||||
import { Image } from '@shared/image';
|
import { Image } from '@shared/image';
|
||||||
|
import { Logout } from '@shared/logout';
|
||||||
|
|
||||||
|
import { useActivities } from '@stores/activities';
|
||||||
|
|
||||||
import { useNostr } from '@utils/hooks/useNostr';
|
import { useNostr } from '@utils/hooks/useNostr';
|
||||||
import { useProfile } from '@utils/hooks/useProfile';
|
import { useProfile } from '@utils/hooks/useProfile';
|
||||||
@@ -16,65 +20,71 @@ export function ActiveAccount() {
|
|||||||
const { status, user } = useProfile(db.account.pubkey);
|
const { status, user } = useProfile(db.account.pubkey);
|
||||||
const { sub } = useNostr();
|
const { sub } = useNostr();
|
||||||
|
|
||||||
|
const addActivity = useActivities((state) => state.addActivity);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const filter: NDKFilter = {
|
const filter: NDKFilter = {
|
||||||
'#p': [db.account.pubkey],
|
'#p': [db.account.pubkey],
|
||||||
kinds: [
|
kinds: [NDKKind.Text, NDKKind.Repost, NDKKind.Reaction, NDKKind.Zap],
|
||||||
NDKKind.Text,
|
|
||||||
NDKKind.Contacts,
|
|
||||||
NDKKind.Repost,
|
|
||||||
NDKKind.Reaction,
|
|
||||||
NDKKind.Zap,
|
|
||||||
],
|
|
||||||
since: Math.floor(Date.now() / 1000),
|
since: Math.floor(Date.now() / 1000),
|
||||||
};
|
};
|
||||||
|
|
||||||
sub(filter, async (event) => {
|
sub(
|
||||||
switch (event.kind) {
|
filter,
|
||||||
case NDKKind.Text:
|
async (event) => {
|
||||||
return await sendNativeNotification('Mention');
|
addActivity(event);
|
||||||
case NDKKind.Contacts:
|
switch (event.kind) {
|
||||||
return await sendNativeNotification("You've new follower");
|
case NDKKind.Text:
|
||||||
case NDKKind.Repost:
|
return await sendNativeNotification('Mention');
|
||||||
return await sendNativeNotification('Repost');
|
case NDKKind.Repost:
|
||||||
case NDKKind.Reaction:
|
return await sendNativeNotification('Repost');
|
||||||
return await sendNativeNotification('Reaction');
|
case NDKKind.Reaction:
|
||||||
case NDKKind.Zap:
|
return await sendNativeNotification('Reaction');
|
||||||
return await sendNativeNotification('Zap');
|
case NDKKind.Zap:
|
||||||
default:
|
return await sendNativeNotification('Zap');
|
||||||
console.log('[notify] new event: ', event);
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (status === 'loading') {
|
if (status === 'loading') {
|
||||||
return (
|
return (
|
||||||
<div className="inline-flex h-10 items-center gap-2.5 rounded-md px-2">
|
<div className="inline-flex h-16 items-center gap-2.5 border-l-2 border-transparent pb-2 pl-4 pr-2">
|
||||||
<div className="relative h-7 w-7 shrink-0 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
<div className="relative h-10 w-10 shrink-0 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
||||||
<div className="h-2.5 w-2/3 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
<div className="h-2.5 w-2/3 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-16 items-center justify-between border-l-2 border-transparent pb-2 pl-4 pr-2">
|
<div className="flex h-16 items-center justify-between border-l-2 border-transparent pb-2 pl-4 pr-3">
|
||||||
<div className="flex items-center gap-2.5">
|
<Link to={`/users/${db.account.pubkey}`} className="flex items-center gap-1.5">
|
||||||
<Image
|
<Image
|
||||||
src={user?.picture || user?.image}
|
src={user?.picture || user?.image}
|
||||||
alt={db.account.npub}
|
alt={db.account.npub}
|
||||||
className="h-10 w-10 shrink-0 rounded-lg object-cover"
|
className="h-9 w-9 shrink-0 rounded-lg object-cover"
|
||||||
/>
|
/>
|
||||||
<div className="flex w-full flex-1 flex-col items-start gap-1.5">
|
<div className="flex w-full flex-1 flex-col items-start gap-0.5">
|
||||||
<p className="max-w-[10rem] truncate font-bold leading-none text-white">
|
<p className="max-w-[10rem] truncate font-semibold leading-none text-white">
|
||||||
{user?.name || user?.display_name}
|
{user?.name || user?.display_name || user?.displayName}
|
||||||
</p>
|
</p>
|
||||||
<span className="max-w-[8rem] truncate text-sm leading-none text-white/50">
|
<span className="max-w-[7rem] truncate text-sm leading-none text-white/50">
|
||||||
{displayNpub(db.account.pubkey, 16)}
|
{user?.nip05 || displayNpub(db.account.pubkey, 12)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
</Link>
|
||||||
|
<div className="inline-flex divide-x divide-white/5 rounded-lg border-t border-white/10 bg-white/20">
|
||||||
|
<Link
|
||||||
|
to="/settings/"
|
||||||
|
className="inline-flex h-9 w-9 items-center justify-center hover:bg-white/10"
|
||||||
|
>
|
||||||
|
<SettingsIcon className="h-4 w-4 text-white" />
|
||||||
|
</Link>
|
||||||
|
<Logout />
|
||||||
</div>
|
</div>
|
||||||
<AccountMoreActions pubkey={db.account.pubkey} />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { useState } from 'react';
|
|||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import { HorizontalDotsIcon } from '@shared/icons';
|
import { HorizontalDotsIcon } from '@shared/icons';
|
||||||
|
import { Logout } from '@shared/logout';
|
||||||
|
|
||||||
export function AccountMoreActions({ pubkey }: { pubkey: string }) {
|
export function AccountMoreActions({ pubkey }: { pubkey: string }) {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
@@ -18,7 +19,7 @@ export function AccountMoreActions({ pubkey }: { pubkey: string }) {
|
|||||||
</button>
|
</button>
|
||||||
</DropdownMenu.Trigger>
|
</DropdownMenu.Trigger>
|
||||||
<DropdownMenu.Portal>
|
<DropdownMenu.Portal>
|
||||||
<DropdownMenu.Content className="flex w-[200px] flex-col overflow-hidden rounded-xl bg-white/10 p-2 backdrop-blur-3xl focus:outline-none">
|
<DropdownMenu.Content className="flex w-[200px] flex-col overflow-hidden rounded-xl border border-white/10 bg-white/20 p-2 backdrop-blur-3xl focus:outline-none">
|
||||||
<DropdownMenu.Item asChild>
|
<DropdownMenu.Item asChild>
|
||||||
<Link
|
<Link
|
||||||
to={`/users/${pubkey}`}
|
to={`/users/${pubkey}`}
|
||||||
@@ -44,9 +45,7 @@ export function AccountMoreActions({ pubkey }: { pubkey: string }) {
|
|||||||
</Link>
|
</Link>
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
<DropdownMenu.Item asChild>
|
<DropdownMenu.Item asChild>
|
||||||
<button className="inline-flex h-10 items-center rounded-lg px-2 text-sm font-medium text-white hover:bg-white/10">
|
<Logout />
|
||||||
Logout
|
|
||||||
</button>
|
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
</DropdownMenu.Content>
|
</DropdownMenu.Content>
|
||||||
</DropdownMenu.Portal>
|
</DropdownMenu.Portal>
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ import { Dispatch, SetStateAction, useState } from 'react';
|
|||||||
|
|
||||||
import { LoaderIcon, PlusIcon } from '@shared/icons';
|
import { LoaderIcon, PlusIcon } from '@shared/icons';
|
||||||
|
|
||||||
import { useImageUploader } from '@utils/hooks/useUploader';
|
import { useNostr } from '@utils/hooks/useNostr';
|
||||||
|
|
||||||
export function AvatarUploader({
|
export function AvatarUploader({
|
||||||
setPicture,
|
setPicture,
|
||||||
}: {
|
}: {
|
||||||
setPicture: Dispatch<SetStateAction<string>>;
|
setPicture: Dispatch<SetStateAction<string>>;
|
||||||
}) {
|
}) {
|
||||||
const upload = useImageUploader();
|
const { upload } = useNostr();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const uploadAvatar = async () => {
|
const uploadAvatar = async () => {
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ import { Dispatch, SetStateAction, useState } from 'react';
|
|||||||
|
|
||||||
import { LoaderIcon, PlusIcon } from '@shared/icons';
|
import { LoaderIcon, PlusIcon } from '@shared/icons';
|
||||||
|
|
||||||
import { useImageUploader } from '@utils/hooks/useUploader';
|
import { useNostr } from '@utils/hooks/useNostr';
|
||||||
|
|
||||||
export function BannerUploader({
|
export function BannerUploader({
|
||||||
setBanner,
|
setBanner,
|
||||||
}: {
|
}: {
|
||||||
setBanner: Dispatch<SetStateAction<string>>;
|
setBanner: Dispatch<SetStateAction<string>>;
|
||||||
}) {
|
}) {
|
||||||
const upload = useImageUploader();
|
const { upload } = useNostr();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const uploadBanner = async () => {
|
const uploadBanner = async () => {
|
||||||
@@ -25,13 +25,14 @@ export function BannerUploader({
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => uploadBanner()}
|
onClick={() => uploadBanner()}
|
||||||
className="inline-flex h-full w-full items-center justify-center bg-black/40 hover:bg-black/50"
|
className="inline-flex h-full w-full flex-col items-center justify-center gap-1 bg-black/40 hover:bg-black/50"
|
||||||
>
|
>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<LoaderIcon className="h-8 w-8 animate-spin text-white" />
|
<LoaderIcon className="h-6 w-6 animate-spin text-white" />
|
||||||
) : (
|
) : (
|
||||||
<PlusIcon className="h-8 w-8 text-white" />
|
<PlusIcon className="h-6 w-6 text-white" />
|
||||||
)}
|
)}
|
||||||
|
<p className="text-sm font-medium text-white/70">Add a banner image</p>
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ export function Composer() {
|
|||||||
autoCapitalize="off"
|
autoCapitalize="off"
|
||||||
className={twMerge(
|
className={twMerge(
|
||||||
'scrollbar-hide markdown max-h-[500px] overflow-y-auto break-all pr-2 outline-none',
|
'scrollbar-hide markdown max-h-[500px] overflow-y-auto break-all pr-2 outline-none',
|
||||||
expand ? 'min-h-[500px]' : 'min-h-[120px]'
|
expand ? 'min-h-[500px]' : reply.id ? 'min-h-min' : 'min-h-[120px]'
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
{reply.id && (
|
{reply.id && (
|
||||||
|
|||||||
@@ -3,4 +3,6 @@ export * from './modal';
|
|||||||
export * from './composer';
|
export * from './composer';
|
||||||
export * from './mention/item';
|
export * from './mention/item';
|
||||||
export * from './mention/popup';
|
export * from './mention/popup';
|
||||||
|
export * from './mention/suggestion';
|
||||||
|
export * from './mention/inlineList';
|
||||||
export * from './mediaUploader';
|
export * from './mediaUploader';
|
||||||
|
|||||||
83
src/shared/composer/mention/inlineList.tsx
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import { type SuggestionProps } from '@tiptap/suggestion';
|
||||||
|
import {
|
||||||
|
ForwardedRef,
|
||||||
|
forwardRef,
|
||||||
|
useEffect,
|
||||||
|
useImperativeHandle,
|
||||||
|
useState,
|
||||||
|
} from 'react';
|
||||||
|
import { twMerge } from 'tailwind-merge';
|
||||||
|
|
||||||
|
import { MentionItem } from '@shared/composer';
|
||||||
|
|
||||||
|
export const MentionInlineList = forwardRef(
|
||||||
|
(props: SuggestionProps, ref: ForwardedRef<unknown>) => {
|
||||||
|
const [selectedIndex, setSelectedIndex] = useState(0);
|
||||||
|
|
||||||
|
const selectItem = (index) => {
|
||||||
|
const item = props.items[index];
|
||||||
|
|
||||||
|
if (item) {
|
||||||
|
props.command({ id: item });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const upHandler = () => {
|
||||||
|
setSelectedIndex((selectedIndex + props.items.length - 1) % props.items.length);
|
||||||
|
};
|
||||||
|
|
||||||
|
const downHandler = () => {
|
||||||
|
setSelectedIndex((selectedIndex + 1) % props.items.length);
|
||||||
|
};
|
||||||
|
|
||||||
|
const enterHandler = () => {
|
||||||
|
selectItem(selectedIndex);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => setSelectedIndex(0), [props.items]);
|
||||||
|
|
||||||
|
useImperativeHandle(ref, () => ({
|
||||||
|
onKeyDown: ({ event }) => {
|
||||||
|
if (event.key === 'ArrowUp') {
|
||||||
|
upHandler();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.key === 'ArrowDown') {
|
||||||
|
downHandler();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
enterHandler();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex w-[250px] flex-col rounded-xl bg-white/10 px-3 py-3 backdrop-blur-xl">
|
||||||
|
{props.items.length ? (
|
||||||
|
props.items.map((item: string, index: number) => (
|
||||||
|
<button
|
||||||
|
className={twMerge(
|
||||||
|
'h-11 w-full rounded-lg px-2 text-start text-sm font-medium hover:bg-white/10',
|
||||||
|
`${index === selectedIndex ? 'is-selected' : ''}`
|
||||||
|
)}
|
||||||
|
key={index}
|
||||||
|
onClick={() => selectItem(index)}
|
||||||
|
>
|
||||||
|
<MentionItem embed={item} />
|
||||||
|
</button>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<div>No result</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
MentionInlineList.displayName = 'MentionList';
|
||||||