Compare commits

..

15 Commits

Author SHA1 Message Date
a262217ab2 chore: release 2024-11-11 10:02:44 +07:00
c5d06a2492 feat: add negentropy sync to settings 2024-11-11 10:02:19 +07:00
c93edde7d2 chore: use upstream rust nostr 2024-11-11 07:56:31 +07:00
5103126001 fix: build on windows 2024-11-10 14:28:14 +07:00
b0c49c5141 chore: release 2024-11-10 13:23:57 +07:00
2ed2cb3afd chore: update dependencies 2024-11-10 10:43:38 +07:00
2bcda1f2ef feat: support NIP22 for comment 2024-11-10 08:51:07 +07:00
ca20bbd298 chore: release 2024-11-08 09:19:51 +07:00
c6da06cd4d chore: clean up 2024-11-08 09:02:57 +07:00
50bf6c04c1 chore: use upstream nostr-sdk instead of fork 2024-11-08 07:51:48 +07:00
490417771c chore: release 2024-11-07 15:02:05 +07:00
0cb491eaf9 feat: auto open browser if receive auth_url 2024-11-07 14:26:13 +07:00
ece6bcc125 feat: add DVM feeds 2024-11-07 09:26:28 +07:00
4b79e559d2 chore: clean up 2024-11-06 09:43:31 +07:00
322e510db2 fix: settings 2024-11-06 09:16:22 +07:00
39 changed files with 2400 additions and 1865 deletions

View File

@@ -1,85 +1,85 @@
{
"name": "lume",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"tauri": "tauri"
},
"dependencies": {
"@getalby/bitcoin-connect-react": "^3.6.2",
"@phosphor-icons/react": "^2.1.7",
"@radix-ui/react-avatar": "^1.1.1",
"@radix-ui/react-checkbox": "^1.1.2",
"@radix-ui/react-popover": "^1.1.2",
"@radix-ui/react-progress": "^1.1.0",
"@radix-ui/react-scroll-area": "^1.2.0",
"@radix-ui/react-switch": "^1.1.1",
"@radix-ui/react-tabs": "^1.1.1",
"@radix-ui/react-tooltip": "^1.1.3",
"@tanstack/query-broadcast-client-experimental": "^5.59.16",
"@tanstack/query-persist-client-core": "^5.59.16",
"@tanstack/react-query": "^5.59.16",
"@tanstack/react-router": "^1.77.5",
"@tauri-apps/api": "^2.0.3",
"@tauri-apps/plugin-clipboard-manager": "^2.0.0",
"@tauri-apps/plugin-dialog": "^2.0.1",
"@tauri-apps/plugin-fs": "^2.0.1",
"@tauri-apps/plugin-http": "^2.0.1",
"@tauri-apps/plugin-os": "^2.0.0",
"@tauri-apps/plugin-process": "^2.0.0",
"@tauri-apps/plugin-shell": "^2.0.1",
"@tauri-apps/plugin-store": "github:tauri-apps/tauri-plugin-store#a564510",
"@tauri-apps/plugin-updater": "^2.0.0",
"@tauri-apps/plugin-upload": "^2.0.0",
"@tauri-apps/plugin-window-state": "^2.0.0",
"bitcoin-units": "^1.0.0",
"dayjs": "^1.11.13",
"embla-carousel-react": "^8.3.0",
"i18next": "^23.16.4",
"i18next-resources-to-backend": "^1.2.1",
"light-bolt11-decoder": "^3.2.0",
"minidenticons": "^4.2.1",
"nanoid": "^5.0.7",
"nostr-tools": "^2.9.4",
"react": "19.0.0-rc-cae764ce-20241025",
"react-currency-input-field": "^3.8.0",
"react-dom": "19.0.0-rc-cae764ce-20241025",
"react-hook-form": "^7.53.1",
"react-i18next": "^15.1.0",
"react-string-replace": "^1.1.1",
"rich-textarea": "^0.26.3",
"use-debounce": "^10.0.4",
"virtua": "^0.34.2"
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@tailwindcss/forms": "^0.5.9",
"@tailwindcss/typography": "^0.5.15",
"@tanstack/router-devtools": "^1.77.5",
"@tanstack/router-plugin": "^1.76.4",
"@tauri-apps/cli": "^2.0.4",
"@types/react": "npm:types-react@19.0.0-rc.1",
"@types/react-dom": "npm:types-react-dom@19.0.0-rc.1",
"@vitejs/plugin-react": "^4.3.3",
"autoprefixer": "^10.4.20",
"babel-plugin-react-compiler": "0.0.0-experimental-b4db8c3-20241001",
"clsx": "^2.1.1",
"postcss": "^8.4.47",
"tailwind-gradient-mask-image": "^1.2.0",
"tailwind-merge": "^2.5.4",
"tailwind-scrollbar": "^3.1.0",
"tailwindcss": "^3.4.14",
"tailwindcss-content-visibility": "^1.0.0",
"typescript": "^5.6.3",
"vite": "^5.4.10",
"vite-tsconfig-paths": "^5.0.1"
},
"overrides": {
"@types/react": "npm:types-react@rc",
"@types/react-dom": "npm:types-react-dom@rc"
}
"name": "lume",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"tauri": "tauri"
},
"dependencies": {
"@getalby/bitcoin-connect-react": "^3.6.2",
"@phosphor-icons/react": "^2.1.7",
"@radix-ui/react-avatar": "^1.1.1",
"@radix-ui/react-checkbox": "^1.1.2",
"@radix-ui/react-popover": "^1.1.2",
"@radix-ui/react-progress": "^1.1.0",
"@radix-ui/react-scroll-area": "^1.2.0",
"@radix-ui/react-switch": "^1.1.1",
"@radix-ui/react-tabs": "^1.1.1",
"@radix-ui/react-tooltip": "^1.1.3",
"@tanstack/query-broadcast-client-experimental": "^5.59.20",
"@tanstack/query-persist-client-core": "^5.59.20",
"@tanstack/react-query": "^5.59.20",
"@tanstack/react-router": "^1.81.0",
"@tauri-apps/api": "^2.1.0",
"@tauri-apps/plugin-clipboard-manager": "^2.0.0",
"@tauri-apps/plugin-dialog": "^2.0.1",
"@tauri-apps/plugin-fs": "^2.0.2",
"@tauri-apps/plugin-http": "^2.0.1",
"@tauri-apps/plugin-os": "^2.0.0",
"@tauri-apps/plugin-process": "^2.0.0",
"@tauri-apps/plugin-shell": "^2.0.1",
"@tauri-apps/plugin-store": "github:tauri-apps/tauri-plugin-store#a564510",
"@tauri-apps/plugin-updater": "^2.0.0",
"@tauri-apps/plugin-upload": "^2.1.0",
"@tauri-apps/plugin-window-state": "^2.0.0",
"bitcoin-units": "^1.0.0",
"dayjs": "^1.11.13",
"embla-carousel-react": "^8.3.1",
"i18next": "^23.16.5",
"i18next-resources-to-backend": "^1.2.1",
"light-bolt11-decoder": "^3.2.0",
"minidenticons": "^4.2.1",
"nanoid": "^5.0.8",
"nostr-tools": "^2.10.1",
"react": "19.0.0-rc-cae764ce-20241025",
"react-currency-input-field": "^3.8.0",
"react-dom": "19.0.0-rc-cae764ce-20241025",
"react-hook-form": "^7.53.2",
"react-i18next": "^15.1.1",
"react-string-replace": "^1.1.1",
"rich-textarea": "^0.26.4",
"use-debounce": "^10.0.4",
"virtua": "^0.34.2"
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@tailwindcss/forms": "^0.5.9",
"@tailwindcss/typography": "^0.5.15",
"@tanstack/router-devtools": "^1.81.0",
"@tanstack/router-plugin": "^1.79.0",
"@tauri-apps/cli": "^2.1.0",
"@types/react": "npm:types-react@19.0.0-rc.1",
"@types/react-dom": "npm:types-react-dom@19.0.0-rc.1",
"@vitejs/plugin-react": "^4.3.3",
"autoprefixer": "^10.4.20",
"babel-plugin-react-compiler": "0.0.0-experimental-b4db8c3-20241001",
"clsx": "^2.1.1",
"postcss": "^8.4.47",
"tailwind-gradient-mask-image": "^1.2.0",
"tailwind-merge": "^2.5.4",
"tailwind-scrollbar": "^3.1.0",
"tailwindcss": "^3.4.14",
"tailwindcss-content-visibility": "^1.0.0",
"typescript": "^5.6.3",
"vite": "^5.4.10",
"vite-tsconfig-paths": "5.0.0"
},
"overrides": {
"@types/react": "npm:types-react@rc",
"@types/react-dom": "npm:types-react-dom@rc"
}
}

600
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

1568
src-tauri/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -33,9 +33,6 @@ tauri-plugin-theme = "2.1.2"
tauri-plugin-decorum = { git = "https://github.com/clearlysid/tauri-plugin-decorum" }
tauri-specta = { version = "2.0.0-rc.15", features = ["derive", "typescript"] }
nostr-sdk = { git = "https://github.com/rust-nostr/nostr", features = ["lmdb"] }
nostr-connect = { git = "https://github.com/rust-nostr/nostr" }
specta = "^2.0.0-rc.20"
specta-typescript = "0.0.7"
tokio = { version = "1", features = ["full"] }
@@ -49,6 +46,11 @@ regex = "1.10.4"
keyring = { version = "3", features = ["apple-native", "windows-native"] }
keyring-search = { git = "https://github.com/reyamir/keyring-search" }
tracing-subscriber = { version = "0.3.18", features = ["fmt"] }
async-trait = "0.1.83"
webbrowser = "1.0.2"
nostr-sdk = { git = "https://github.com/rust-nostr/nostr", features = ["lmdb", "webln", "all-nips"] }
nostr-connect = { git = "https://github.com/rust-nostr/nostr" }
[target.'cfg(target_os = "macos")'.dependencies]
border = { git = "https://github.com/ahkohd/tauri-toolkit", branch = "v2" }

View File

@@ -37,7 +37,7 @@
],
"definitions": {
"Capability": {
"description": "A grouping and boundary mechanism developers can use to isolate access to the IPC layer.\n\nIt controls application windows fine grained access to the Tauri core, application, or plugin commands. If a window is not matching any capability then it has no access to the IPC layer at all.\n\nThis can be done to create groups of windows, based on their required system access, which can reduce impact of frontend vulnerabilities in less privileged windows. Windows can be added to a capability by exact name (e.g. `main-window`) or glob patterns like `*` or `admin-*`. A Window can have none, one, or multiple associated capabilities.\n\n## Example\n\n```json { \"identifier\": \"main-user-files-write\", \"description\": \"This capability allows the `main` window on macOS and Windows access to `filesystem` write related commands and `dialog` commands to enable programatic access to files selected by the user.\", \"windows\": [ \"main\" ], \"permissions\": [ \"core:default\", \"dialog:open\", { \"identifier\": \"fs:allow-write-text-file\", \"allow\": [{ \"path\": \"$HOME/test.txt\" }] }, \"platforms\": [\"macOS\",\"windows\"] } ```",
"description": "A grouping and boundary mechanism developers can use to isolate access to the IPC layer.\n\nIt controls application windows fine grained access to the Tauri core, application, or plugin commands. If a window is not matching any capability then it has no access to the IPC layer at all.\n\nThis can be done to create groups of windows, based on their required system access, which can reduce impact of frontend vulnerabilities in less privileged windows. Windows can be added to a capability by exact name (e.g. `main-window`) or glob patterns like `*` or `admin-*`. A Window can have none, one, or multiple associated capabilities.\n\n## Example\n\n```json { \"identifier\": \"main-user-files-write\", \"description\": \"This capability allows the `main` window on macOS and Windows access to `filesystem` write related commands and `dialog` commands to enable programatic access to files selected by the user.\", \"windows\": [ \"main\" ], \"permissions\": [ \"core:default\", \"dialog:open\", { \"identifier\": \"fs:allow-write-text-file\", \"allow\": [{ \"path\": \"$HOME/test.txt\" }] }, ], \"platforms\": [\"macOS\",\"windows\"] } ```",
"type": "object",
"required": [
"identifier",
@@ -84,7 +84,7 @@
}
},
"permissions": {
"description": "List of permissions attached to this capability.\n\nMust include the plugin name as prefix in the form of `${plugin-name}:${permission-name}`. For commands directly implemented in the application itself only `${permission-name}` is required.\n\n## Example\n\n```json [ \"core:default\", \"shell:allow-open\", \"dialog:open\", { \"identifier\": \"fs:allow-write-text-file\", \"allow\": [{ \"path\": \"$HOME/test.txt\" }] } ```",
"description": "List of permissions attached to this capability.\n\nMust include the plugin name as prefix in the form of `${plugin-name}:${permission-name}`. For commands directly implemented in the application itself only `${permission-name}` is required.\n\n## Example\n\n```json [ \"core:default\", \"shell:allow-open\", \"dialog:open\", { \"identifier\": \"fs:allow-write-text-file\", \"allow\": [{ \"path\": \"$HOME/test.txt\" }] } ] ```",
"type": "array",
"items": {
"$ref": "#/definitions/PermissionEntry"

View File

@@ -37,7 +37,7 @@
],
"definitions": {
"Capability": {
"description": "A grouping and boundary mechanism developers can use to isolate access to the IPC layer.\n\nIt controls application windows fine grained access to the Tauri core, application, or plugin commands. If a window is not matching any capability then it has no access to the IPC layer at all.\n\nThis can be done to create groups of windows, based on their required system access, which can reduce impact of frontend vulnerabilities in less privileged windows. Windows can be added to a capability by exact name (e.g. `main-window`) or glob patterns like `*` or `admin-*`. A Window can have none, one, or multiple associated capabilities.\n\n## Example\n\n```json { \"identifier\": \"main-user-files-write\", \"description\": \"This capability allows the `main` window on macOS and Windows access to `filesystem` write related commands and `dialog` commands to enable programatic access to files selected by the user.\", \"windows\": [ \"main\" ], \"permissions\": [ \"core:default\", \"dialog:open\", { \"identifier\": \"fs:allow-write-text-file\", \"allow\": [{ \"path\": \"$HOME/test.txt\" }] }, \"platforms\": [\"macOS\",\"windows\"] } ```",
"description": "A grouping and boundary mechanism developers can use to isolate access to the IPC layer.\n\nIt controls application windows fine grained access to the Tauri core, application, or plugin commands. If a window is not matching any capability then it has no access to the IPC layer at all.\n\nThis can be done to create groups of windows, based on their required system access, which can reduce impact of frontend vulnerabilities in less privileged windows. Windows can be added to a capability by exact name (e.g. `main-window`) or glob patterns like `*` or `admin-*`. A Window can have none, one, or multiple associated capabilities.\n\n## Example\n\n```json { \"identifier\": \"main-user-files-write\", \"description\": \"This capability allows the `main` window on macOS and Windows access to `filesystem` write related commands and `dialog` commands to enable programatic access to files selected by the user.\", \"windows\": [ \"main\" ], \"permissions\": [ \"core:default\", \"dialog:open\", { \"identifier\": \"fs:allow-write-text-file\", \"allow\": [{ \"path\": \"$HOME/test.txt\" }] }, ], \"platforms\": [\"macOS\",\"windows\"] } ```",
"type": "object",
"required": [
"identifier",
@@ -84,7 +84,7 @@
}
},
"permissions": {
"description": "List of permissions attached to this capability.\n\nMust include the plugin name as prefix in the form of `${plugin-name}:${permission-name}`. For commands directly implemented in the application itself only `${permission-name}` is required.\n\n## Example\n\n```json [ \"core:default\", \"shell:allow-open\", \"dialog:open\", { \"identifier\": \"fs:allow-write-text-file\", \"allow\": [{ \"path\": \"$HOME/test.txt\" }] } ```",
"description": "List of permissions attached to this capability.\n\nMust include the plugin name as prefix in the form of `${plugin-name}:${permission-name}`. For commands directly implemented in the application itself only `${permission-name}` is required.\n\n## Example\n\n```json [ \"core:default\", \"shell:allow-open\", \"dialog:open\", { \"identifier\": \"fs:allow-write-text-file\", \"allow\": [{ \"path\": \"$HOME/test.txt\" }] } ] ```",
"type": "array",
"items": {
"$ref": "#/definitions/PermissionEntry"

View File

@@ -14,6 +14,17 @@ struct Account {
nostr_connect: Option<String>,
}
#[derive(Debug, Clone)]
struct AuthHandler;
#[async_trait::async_trait]
impl AuthUrlHandler for AuthHandler {
async fn on_auth_url(&self, auth_url: Url) -> Result<()> {
webbrowser::open(auth_url.as_str())?;
Ok(())
}
}
#[tauri::command]
#[specta::specta]
pub fn get_accounts() -> Vec<String> {
@@ -94,19 +105,29 @@ pub async fn connect_account(uri: String, state: State<'_, Nostr>) -> Result<Str
let remote_npub = remote_user.to_bech32().map_err(|err| err.to_string())?;
// Init nostr connect
let nostr_connect = NostrConnect::new(bunker_uri, app_keys, Duration::from_secs(120), None)
let mut nostr_connect = NostrConnect::new(bunker_uri, app_keys, Duration::from_secs(120), None)
.map_err(|err| err.to_string())?;
let bunker_uri = nostr_connect
// Handle auth url
nostr_connect.auth_url_handler(AuthHandler);
let keyring = Entry::new("Lume Safe Storage", &remote_npub).map_err(|err| err.to_string())?;
let reuse_bunker = nostr_connect
.bunker_uri()
.await
.map_err(|err| err.to_string())?;
let keyring = Entry::new("Lume Safe Storage", &remote_npub).map_err(|err| err.to_string())?;
let mut reuse_uri = reuse_bunker.to_string();
if let Some(secret) = reuse_bunker.secret() {
let replace = format!("&secret={}", secret);
reuse_uri = reuse_uri.replace(replace.as_str(), "");
}
let account = Account {
secret_key: app_secret,
nostr_connect: Some(bunker_uri.to_string()),
nostr_connect: Some(reuse_uri),
};
// Save secret key to keyring
@@ -217,7 +238,9 @@ pub async fn set_signer(
let app_keys = Keys::from_str(&account.secret_key).map_err(|e| e.to_string())?;
match NostrConnect::new(uri, app_keys, Duration::from_secs(120), None) {
Ok(signer) => {
Ok(mut signer) => {
// Handle auth url
signer.auth_url_handler(AuthHandler);
// Update signer
client.set_signer(signer).await;
// Emit to front-end

View File

@@ -71,11 +71,11 @@ pub async fn get_meta_from_event(content: String) -> Result<Meta, ()> {
#[specta::specta]
pub async fn get_replies(id: String, state: State<'_, Nostr>) -> Result<Vec<RichEvent>, String> {
let client = &state.client;
let event_id = EventId::parse(&id).map_err(|err| err.to_string())?;
let event_id = EventId::parse(&id).map_err(|err| err.to_string())?;
let filter = Filter::new()
.kinds(vec![Kind::TextNote, Kind::Custom(1111)])
.event(event_id);
.kind(Kind::Comment)
.custom_tag(SingleLetterTag::uppercase(Alphabet::E), [event_id]);
let mut events = Events::new(&[filter.clone()]);
@@ -239,6 +239,173 @@ pub async fn get_all_events_from(
Ok(alt_events)
}
#[tauri::command]
#[specta::specta]
pub async fn get_all_events_by_kind(
kind: u16,
until: Option<String>,
state: State<'_, Nostr>,
) -> Result<Vec<String>, String> {
let client = &state.client;
let as_of = match until {
Some(until) => Timestamp::from_str(&until).map_err(|err| err.to_string())?,
None => Timestamp::now(),
};
let filter = Filter::new()
.kind(Kind::Custom(kind))
.limit(FETCH_LIMIT)
.until(as_of);
let mut events = Events::new(&[filter.clone()]);
let mut rx = client
.stream_events(vec![filter], Some(Duration::from_secs(3)))
.await
.map_err(|e| e.to_string())?;
while let Some(event) = rx.next().await {
events.insert(event);
}
let alt_events: Vec<String> = events.iter().map(|ev| ev.as_json()).collect();
Ok(alt_events)
}
#[tauri::command]
#[specta::specta]
pub async fn get_all_providers(state: State<'_, Nostr>) -> Result<Vec<String>, String> {
let client = &state.client;
let filter = Filter::new()
.kind(Kind::Custom(31990))
.custom_tag(SingleLetterTag::lowercase(Alphabet::K), vec!["5300"]);
let mut events = Events::new(&[filter.clone()]);
let mut rx = client
.stream_events(vec![filter], Some(Duration::from_secs(3)))
.await
.map_err(|e| e.to_string())?;
while let Some(event) = rx.next().await {
events.insert(event);
}
let alt_events: Vec<String> = events.iter().map(|ev| ev.as_json()).collect();
Ok(alt_events)
}
#[tauri::command]
#[specta::specta]
pub async fn request_events_from_provider(
provider: String,
state: State<'_, Nostr>,
) -> Result<String, String> {
let client = &state.client;
let signer = client.signer().await.map_err(|err| err.to_string())?;
let public_key = signer
.get_public_key()
.await
.map_err(|err| err.to_string())?;
let provider = PublicKey::parse(&provider).map_err(|err| err.to_string())?;
// Get current user's relay list
let relay_list = client
.database()
.relay_list(public_key)
.await
.map_err(|err| err.to_string())?;
let relay_list: Vec<String> = relay_list.iter().map(|item| item.0.to_string()).collect();
// Create job request
let builder = EventBuilder::job_request(
Kind::JobRequest(5300),
vec![
Tag::public_key(provider),
Tag::custom(TagKind::Relays, relay_list),
],
)
.map_err(|err| err.to_string())?;
match client.send_event_builder(builder).await {
Ok(output) => {
let filter = Filter::new()
.kind(Kind::JobResult(6300))
.author(provider)
.pubkey(public_key)
.since(Timestamp::now());
let opts = SubscribeAutoCloseOptions::default()
.filter(FilterOptions::WaitDurationAfterEOSE(Duration::from_secs(2)));
let _ = client.subscribe(vec![filter], Some(opts)).await;
Ok(output.val.to_hex())
}
Err(e) => Err(e.to_string()),
}
}
#[tauri::command]
#[specta::specta]
pub async fn get_all_events_by_request(
id: String,
provider: String,
state: State<'_, Nostr>,
) -> Result<Vec<RichEvent>, String> {
let client = &state.client;
let public_key = PublicKey::parse(&id).map_err(|err| err.to_string())?;
let provider = PublicKey::parse(&provider).map_err(|err| err.to_string())?;
let filter = Filter::new()
.kind(Kind::JobResult(6300))
.author(provider)
.pubkey(public_key)
.limit(1);
let events = client
.database()
.query(vec![filter])
.await
.map_err(|err| err.to_string())?;
if let Some(event) = events.first() {
let parsed: Vec<Vec<String>> =
serde_json::from_str(&event.content).map_err(|err| err.to_string())?;
let vec: Vec<Tag> = parsed
.into_iter()
.filter_map(|item| Tag::parse(&item).ok())
.collect::<Vec<_>>();
let tags = Tags::new(vec);
let ids: Vec<EventId> = tags.event_ids().copied().collect();
let filter = Filter::new().ids(ids);
let mut events = Events::new(&[filter.clone()]);
let mut rx = client
.stream_events(vec![filter], Some(Duration::from_secs(3)))
.await
.map_err(|e| e.to_string())?;
while let Some(event) = rx.next().await {
events.insert(event);
}
let alt_events = process_event(client, events, false).await;
Ok(alt_events)
} else {
Err("Job result not found.".into())
}
}
#[tauri::command]
#[specta::specta]
pub async fn get_local_events(
@@ -356,39 +523,31 @@ pub async fn reply(content: String, to: String, state: State<'_, Nostr>) -> Resu
Err(e) => return Err(e.to_string()),
};
// Detect root event from reply
let root_ids: Vec<&EventId> = reply_to
// Find root event from reply
let root_tag = reply_to
.tags
.filter_standardized(TagKind::e())
.filter_map(|t| match t {
TagStandard::Event {
event_id, marker, ..
} => {
if let Some(mkr) = marker {
match mkr {
Marker::Root => Some(event_id),
Marker::Reply => Some(event_id),
_ => None,
}
} else {
Some(event_id)
}
}
_ => None,
})
.collect();
.find(TagKind::SingleLetter(SingleLetterTag::uppercase(
Alphabet::E,
)));
// Get root event if exist
let root = match root_ids.first() {
Some(&id) => client
.database()
.event_by_id(id)
.await
.map_err(|err| err.to_string())?,
let root = match root_tag {
Some(tag) => match tag.content() {
Some(content) => {
let id = EventId::parse(content).map_err(|err| err.to_string())?;
client
.database()
.event_by_id(&id)
.await
.map_err(|err| err.to_string())?
}
None => None,
},
None => None,
};
let builder = EventBuilder::text_note_reply(content, &reply_to, root.as_ref(), None)
let builder = EventBuilder::comment(content, &reply_to, root.as_ref(), None)
.add_tags(tags)
.pow(DEFAULT_DIFFICULTY);

View File

@@ -1,12 +1,8 @@
use nostr_sdk::prelude::*;
use serde::Serialize;
use specta::Type;
use std::{
fs::OpenOptions,
io::{self, BufRead, Write},
str::FromStr,
};
use tauri::{path::BaseDirectory, Manager, State};
use std::str::FromStr;
use tauri::State;
use crate::{Nostr, FETCH_LIMIT};
@@ -20,82 +16,17 @@ pub struct Relays {
#[tauri::command]
#[specta::specta]
pub async fn get_relays(id: String, state: State<'_, Nostr>) -> Result<Relays, String> {
pub async fn get_all_relays(state: State<'_, Nostr>) -> Result<Vec<String>, String> {
let client = &state.client;
let public_key = PublicKey::from_str(&id).map_err(|e| e.to_string())?;
let relays = client.pool().all_relays().await;
let v: Vec<String> = relays.iter().map(|item| item.0.to_string()).collect();
let connected_relays = client
.relays()
.await
.into_keys()
.map(|url| url.to_string())
.collect::<Vec<_>>();
let filter = Filter::new()
.author(public_key)
.kind(Kind::RelayList)
.limit(1);
match client.database().query(vec![filter]).await {
Ok(events) => {
if let Some(event) = events.first() {
let nip65_list = nip65::extract_relay_list(event).collect::<Vec<_>>();
let read = nip65_list
.iter()
.filter_map(|(url, meta)| {
if let Some(RelayMetadata::Read) = meta {
Some(url.to_string())
} else {
None
}
})
.collect();
let write = nip65_list
.iter()
.filter_map(|(url, meta)| {
if let Some(RelayMetadata::Write) = meta {
Some(url.to_string())
} else {
None
}
})
.collect();
let both = nip65_list
.iter()
.filter_map(|(url, meta)| {
if meta.is_none() {
Some(url.to_string())
} else {
None
}
})
.collect();
Ok(Relays {
connected: connected_relays,
read: Some(read),
write: Some(write),
both: Some(both),
})
} else {
Ok(Relays {
connected: connected_relays,
read: None,
write: None,
both: None,
})
}
}
Err(e) => Err(e.to_string()),
}
Ok(v)
}
#[tauri::command]
#[specta::specta]
pub async fn get_all_relays(
pub async fn get_all_relay_lists(
until: Option<String>,
state: State<'_, Nostr>,
) -> Result<Vec<String>, String> {
@@ -149,36 +80,3 @@ pub async fn remove_relay(relay: String, state: State<'_, Nostr>) -> Result<(),
Ok(())
}
#[tauri::command]
#[specta::specta]
pub fn get_bootstrap_relays(app: tauri::AppHandle) -> Result<Vec<String>, String> {
let relays_path = app
.path()
.resolve("resources/relays.txt", BaseDirectory::Resource)
.map_err(|e| e.to_string())?;
let file = std::fs::File::open(relays_path).map_err(|e| e.to_string())?;
let reader = io::BufReader::new(file);
reader
.lines()
.collect::<Result<Vec<String>, io::Error>>()
.map_err(|e| e.to_string())
}
#[tauri::command]
#[specta::specta]
pub fn set_bootstrap_relays(relays: String, app: tauri::AppHandle) -> Result<(), String> {
let relays_path = app
.path()
.resolve("resources/relays.txt", BaseDirectory::Resource)
.map_err(|e| e.to_string())?;
let mut file = OpenOptions::new()
.write(true)
.open(relays_path)
.map_err(|e| e.to_string())?;
file.write_all(relays.as_bytes()).map_err(|e| e.to_string())
}

View File

@@ -1,116 +1,71 @@
use nostr_sdk::prelude::*;
use std::fs::{self, File};
use tauri::{ipc::Channel, Manager, State};
use std::collections::HashSet;
use tauri::State;
use crate::Nostr;
#[tauri::command]
#[specta::specta]
pub fn is_account_sync(id: String, app_handle: tauri::AppHandle) -> Result<bool, String> {
let config_dir = app_handle
.path()
.app_config_dir()
.map_err(|e| e.to_string())?;
let exist = fs::metadata(config_dir.join(id)).is_ok();
Ok(exist)
}
#[tauri::command]
#[specta::specta]
pub async fn sync_account(
id: String,
pub async fn sync_all(
state: State<'_, Nostr>,
reader: Channel<f64>,
app_handle: tauri::AppHandle,
reader: tauri::ipc::Channel<f64>,
) -> Result<(), String> {
let client = &state.client;
let public_key = PublicKey::from_bech32(&id).map_err(|e| e.to_string())?;
let filter = Filter::new().author(public_key).kinds(vec![
Kind::Metadata,
Kind::ContactList,
Kind::Interests,
Kind::InterestSet,
Kind::FollowSet,
Kind::RelayList,
Kind::MuteList,
Kind::EventDeletion,
Kind::Bookmarks,
Kind::BookmarkSet,
// Create a filter for get all public keys
let filter = Filter::new().kinds(vec![
Kind::TextNote,
Kind::Repost,
Kind::Custom(30315),
Kind::FollowSet,
Kind::ContactList,
Kind::MuteList,
]);
let events = client
.database()
.query(vec![filter])
.await
.map_err(|err| err.to_string())?;
let public_keys: Vec<PublicKey> = events
.iter()
.flat_map(|ev| ev.tags.public_keys().copied())
.collect::<HashSet<_>>()
.into_iter()
.collect();
let (tx, mut rx) = SyncProgress::channel();
let opts = SyncOptions::default().progress(tx);
tauri::async_runtime::spawn(async move {
while (rx.changed().await).is_ok() {
let SyncProgress { total, current } = *rx.borrow_and_update();
while rx.changed().await.is_ok() {
let progress = *rx.borrow_and_update();
if total > 0 {
reader
.send((current as f64 / total as f64) * 100.0)
.unwrap()
if progress.total > 0 {
reader.send(progress.percentage() * 100.0).unwrap();
}
}
});
if let Ok(output) = client.sync(filter, &opts).await {
println!("Success: {:?}", output.success);
println!("Failed: {:?}", output.failed);
for chunk in public_keys.chunks(200) {
let authors = chunk.to_owned();
let filter = Filter::new().authors(authors).kinds(vec![
Kind::Metadata,
Kind::ContactList,
Kind::FollowSet,
Kind::Interests,
Kind::InterestSet,
Kind::EventDeletion,
Kind::TextNote,
Kind::Repost,
Kind::Comment,
]);
let event_pubkeys = client
.database()
.query(vec![Filter::new().kinds(vec![
Kind::ContactList,
Kind::FollowSet,
Kind::MuteList,
Kind::Repost,
Kind::TextNote,
])])
let _ = client
.sync(filter, &opts)
.await
.map_err(|e| e.to_string())?;
if !event_pubkeys.is_empty() {
let pubkeys: Vec<PublicKey> = event_pubkeys
.iter()
.flat_map(|ev| ev.tags.public_keys().copied())
.collect();
let filter = Filter::new()
.authors(pubkeys)
.kinds(vec![
Kind::Metadata,
Kind::TextNote,
Kind::Repost,
Kind::EventDeletion,
Kind::Interests,
Kind::InterestSet,
Kind::FollowSet,
Kind::RelayList,
Kind::MuteList,
Kind::EventDeletion,
Kind::Bookmarks,
Kind::BookmarkSet,
Kind::Custom(30315),
])
.limit(10000);
if let Ok(output) = client.sync(filter, &opts).await {
println!("Success: {:?}", output.success);
println!("Failed: {:?}", output.failed);
}
};
.map_err(|err| err.to_string())?;
}
let config_dir = app_handle
.path()
.app_config_dir()
.map_err(|e| e.to_string())?;
let _ = File::create(config_dir.join(id));
Ok(())
}

View File

@@ -71,11 +71,11 @@ pub async fn create_column(
if let Ok(public_key) = PublicKey::parse(&id) {
let is_newsfeed = payload.url().to_string().contains("newsfeed");
tauri::async_runtime::spawn(async move {
let state = webview.state::<Nostr>();
let client = &state.client;
if is_newsfeed {
tauri::async_runtime::spawn(async move {
let state = webview.state::<Nostr>();
let client = &state.client;
if is_newsfeed {
if let Ok(contact_list) =
client.database().contacts_public_keys(public_key).await
{
@@ -102,8 +102,8 @@ pub async fn create_column(
println!("Subscription error: {}", e);
}
}
}
});
});
}
} else if let Ok(event_id) = EventId::parse(&id) {
tauri::async_runtime::spawn(async move {
let state = webview.state::<Nostr>();
@@ -112,8 +112,11 @@ pub async fn create_column(
let subscription_id = SubscriptionId::new(webview.label());
let filter = Filter::new()
.event(event_id)
.kinds(vec![Kind::TextNote, Kind::Custom(1111)])
.custom_tag(
SingleLetterTag::uppercase(Alphabet::E),
[event_id],
)
.kind(Kind::Comment)
.since(Timestamp::now());
if let Err(e) = client

View File

@@ -56,13 +56,6 @@ pub fn create_tags(content: &str) -> Vec<Tag> {
// Get words
let words: Vec<_> = content.split_whitespace().collect();
// Get mentions
let mentions = words
.iter()
.filter(|&&word| ["nostr:", "@"].iter().any(|&el| word.starts_with(el)))
.map(|&s| s.to_string())
.collect::<Vec<_>>();
// Get hashtags
let hashtags = words
.iter()
@@ -70,6 +63,13 @@ pub fn create_tags(content: &str) -> Vec<Tag> {
.map(|&s| s.to_string().replace("#", "").to_lowercase())
.collect::<Vec<_>>();
// Get mentions
let mentions = words
.iter()
.filter(|&&word| ["nostr:", "@"].iter().any(|&el| word.starts_with(el)))
.map(|&s| s.to_string())
.collect::<Vec<_>>();
for mention in mentions {
let entity = mention.replace("nostr:", "").replace('@', "");
@@ -92,8 +92,11 @@ pub fn create_tags(content: &str) -> Vec<Tag> {
}
if entity.starts_with("note") {
if let Ok(event_id) = EventId::from_bech32(&entity) {
let hex = event_id.to_hex();
let tag = Tag::parse(&["e", &hex, "", "mention"]).unwrap();
let tag = Tag::from_standardized(TagStandard::Quote {
event_id,
relay_url: None,
public_key: None,
});
tags.push(tag);
} else {
continue;
@@ -101,14 +104,12 @@ pub fn create_tags(content: &str) -> Vec<Tag> {
}
if entity.starts_with("nevent") {
if let Ok(event) = Nip19Event::from_bech32(&entity) {
let hex = event.event_id.to_hex();
let relay = event.clone().relays.into_iter().next().unwrap_or("".into());
let tag = Tag::parse(&["e", &hex, &relay, "mention"]).unwrap();
if let Some(author) = event.author {
let tag = Tag::public_key(author);
tags.push(tag);
}
let relay_url = event.relays.first().and_then(|i| Url::parse(i).ok());
let tag = Tag::from_standardized(TagStandard::Quote {
event_id: event.event_id,
relay_url,
public_key: event.author,
});
tags.push(tag);
} else {

View File

@@ -5,26 +5,20 @@
#[cfg(target_os = "macos")]
use border::WebviewWindowExt as BorderWebviewWindowExt;
use commands::{account::*, event::*, metadata::*, relay::*, window::*};
use commands::{account::*, event::*, metadata::*, relay::*, sync::*, window::*};
use common::{get_all_accounts, parse_event};
use nostr_sdk::prelude::{Profile as DatabaseProfile, *};
use serde::{Deserialize, Serialize};
use specta::Type;
use specta_typescript::Typescript;
use std::{
collections::HashSet,
fs,
io::{self, BufRead},
str::FromStr,
time::Duration,
};
use std::{collections::HashSet, fs, str::FromStr, time::Duration};
use tauri::{
menu::{Menu, MenuItem},
path::BaseDirectory,
Emitter, EventTarget, Listener, Manager, WebviewWindowBuilder,
};
use tauri_plugin_decorum::WebviewWindowExt;
use tauri_plugin_notification::{NotificationExt, PermissionState};
use tauri_plugin_store::StoreExt;
use tauri_specta::{collect_commands, Builder};
use tokio::{sync::RwLock, time::sleep};
@@ -42,7 +36,7 @@ pub struct Payload {
id: String,
}
#[derive(Clone, Serialize, Deserialize, Type)]
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
pub struct Settings {
resize_service: bool,
content_warning: bool,
@@ -69,18 +63,25 @@ pub const DEFAULT_DIFFICULTY: u8 = 0;
pub const FETCH_LIMIT: usize = 50;
pub const QUEUE_DELAY: u64 = 150;
pub const NOTIFICATION_SUB_ID: &str = "lume_notification";
// Will be removed when almost relays support negentropy
pub const BOOTSTRAP_RELAYS: [&str; 5] = [
"wss://relay.damus.io",
"wss://relay.primal.net",
"wss://nostr.fmt.wiz.biz",
"wss://directory.yabu.me",
"wss://purplepag.es",
];
fn main() {
tracing_subscriber::fmt::init();
let builder = Builder::<tauri::Wry>::new().commands(collect_commands![
get_relays,
sync_all,
get_all_relays,
get_all_relay_lists,
is_relay_connected,
connect_relay,
remove_relay,
get_bootstrap_relays,
set_bootstrap_relays,
get_accounts,
watch_account,
import_account,
@@ -121,6 +122,10 @@ fn main() {
get_all_events_by_authors,
get_all_events_by_hashtags,
get_all_events_from,
get_all_events_by_kind,
get_all_providers,
request_events_from_provider,
get_all_events_by_request,
get_local_events,
get_global_events,
search,
@@ -232,9 +237,8 @@ fn main() {
// Config
let opts = Options::new()
.gossip(true)
.max_avg_latency(Duration::from_millis(300))
.automatic_authentication(true)
.timeout(Duration::from_secs(5));
.max_avg_latency(Duration::from_secs(2))
.timeout(Duration::from_secs(10));
// Setup nostr client
let client = ClientBuilder::default()
@@ -242,7 +246,7 @@ fn main() {
.opts(opts)
.build();
// Get bootstrap relays
/* Get bootstrap relays
if let Ok(path) = handle
.path()
.resolve("resources/relays.txt", BaseDirectory::Resource)
@@ -269,6 +273,11 @@ fn main() {
}
}
}
*/
for relay in BOOTSTRAP_RELAYS {
let _ = client.add_relay(relay).await;
}
let _ = client.add_discovery_relay("wss://user.kindpag.es/").await;
@@ -278,11 +287,29 @@ fn main() {
client
});
// Load app settings
let store = app.store(".data")?;
// Parse app settings if exist
let settings = if let Some(data) = store.get("tanstack-query-[\"settings\"]") {
if let Some(str) = data.as_str() {
let v: Value = serde_json::from_str(str).unwrap();
let data = v["state"]["data"].clone();
let parse: Settings = serde_json::from_value(data).unwrap();
RwLock::new(parse)
} else {
RwLock::new(Settings::default())
}
} else {
RwLock::new(Settings::default())
};
// Create global state
app.manage(Nostr {
client,
settings,
queue: RwLock::new(HashSet::new()),
settings: RwLock::new(Settings::default()),
});
// Listen for request metadata
@@ -339,6 +366,8 @@ fn main() {
// Set interval
let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(600));
// Skip the first tick
interval.tick().await;
loop {
interval.tick().await;
@@ -361,7 +390,8 @@ fn main() {
// Sync notification
//
if let Ok(output) = client.sync(filter, &opts).await {
if let Ok(output) = client.sync_with(BOOTSTRAP_RELAYS, filter, &opts).await
{
println!("Received: {}", output.received.len())
}
@@ -401,7 +431,9 @@ fn main() {
// Sync metadata
//
if let Ok(output) = client.sync(filter, &opts).await {
if let Ok(output) =
client.sync_with(BOOTSTRAP_RELAYS, filter, &opts).await
{
println!("Received: {}", output.received.len())
}
@@ -414,7 +446,9 @@ fn main() {
// Sync text note
//
if let Ok(output) = client.sync(filter, &opts).await {
if let Ok(output) =
client.sync_with(BOOTSTRAP_RELAYS, filter, &opts).await
{
println!("Received: {}", output.received.len())
}
}
@@ -444,7 +478,7 @@ fn main() {
Kind::Repost,
Kind::Reaction,
Kind::ZapReceipt,
Kind::Custom(1111),
Kind::Comment,
])
.since(Timestamp::now());
@@ -501,7 +535,7 @@ fn main() {
if let Err(e) = handle_clone.emit("metadata", event.as_json()) {
println!("Emit error: {}", e)
}
} else if event.kind == Kind::TextNote {
} else if event.kind == Kind::Comment {
let payload = RichEvent {
raw: event.as_json(),
parsed: if event.kind == Kind::TextNote {
@@ -513,7 +547,7 @@ fn main() {
if let Err(e) = handle_clone.emit_to(
EventTarget::labeled(subscription_id.to_string()),
"event",
"comment",
payload,
) {
println!("Emit error: {}", e)
@@ -572,7 +606,7 @@ fn send_event_notification(event: &Event, author: Metadata, handle: &tauri::AppH
if let Err(e) = handle
.notification()
.builder()
.body("Mentioned you in a thread.")
.body("You're mentioned in a thread.")
.title(author.display_name.unwrap_or_else(|| "Lume".to_string()))
.show()
{
@@ -583,7 +617,7 @@ fn send_event_notification(event: &Event, author: Metadata, handle: &tauri::AppH
if let Err(e) = handle
.notification()
.builder()
.body("Reposted your note.")
.body("Your note has been reposted.")
.title(author.display_name.unwrap_or_else(|| "Lume".to_string()))
.show()
{
@@ -594,7 +628,7 @@ fn send_event_notification(event: &Event, author: Metadata, handle: &tauri::AppH
if let Err(e) = handle
.notification()
.builder()
.body("Zapped you.")
.body("You've received zap.")
.title(author.display_name.unwrap_or_else(|| "Lume".to_string()))
.show()
{

View File

@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "Lume",
"version": "24.11.4",
"version": "24.11.8",
"identifier": "nu.lume.Lume",
"build": {
"beforeDevCommand": "pnpm dev",

View File

@@ -5,17 +5,25 @@
export const commands = {
async getRelays(id: string) : Promise<Result<Relays, string>> {
async syncAll(reader: TAURI_CHANNEL<number>) : Promise<Result<null, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_relays", { id }) };
return { status: "ok", data: await TAURI_INVOKE("sync_all", { reader }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getAllRelays(until: string | null) : Promise<Result<string[], string>> {
async getAllRelays() : Promise<Result<string[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_all_relays", { until }) };
return { status: "ok", data: await TAURI_INVOKE("get_all_relays") };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getAllRelayLists(until: string | null) : Promise<Result<string[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_all_relay_lists", { until }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
@@ -45,22 +53,6 @@ async removeRelay(relay: string) : Promise<Result<null, string>> {
else return { status: "error", error: e as any };
}
},
async getBootstrapRelays() : Promise<Result<string[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_bootstrap_relays") };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async setBootstrapRelays(relays: string) : Promise<Result<null, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("set_bootstrap_relays", { relays }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getAccounts() : Promise<string[]> {
return await TAURI_INVOKE("get_accounts");
},
@@ -376,6 +368,38 @@ async getAllEventsFrom(url: string, until: string | null) : Promise<Result<RichE
else return { status: "error", error: e as any };
}
},
async getAllEventsByKind(kind: number, until: string | null) : Promise<Result<string[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_all_events_by_kind", { kind, until }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getAllProviders() : Promise<Result<string[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_all_providers") };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async requestEventsFromProvider(provider: string) : Promise<Result<string, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("request_events_from_provider", { provider }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getAllEventsByRequest(id: string, provider: string) : Promise<Result<RichEvent[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_all_events_by_request", { id, provider }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getLocalEvents(until: string | null) : Promise<Result<RichEvent[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_local_events", { until }) };
@@ -536,9 +560,9 @@ export type Column = { label: string; url: string; x: number; y: number; width:
export type Mention = { pubkey: string; avatar: string; display_name: string; name: string }
export type Meta = { content: string; images: string[]; events: string[]; mentions: string[]; hashtags: string[] }
export type NewWindow = { label: string; title: string; url: string; width: number; height: number; maximizable: boolean; minimizable: boolean; hidden_title: boolean; closable: boolean }
export type Relays = { connected: string[]; read: string[] | null; write: string[] | null; both: string[] | null }
export type RichEvent = { raw: string; parsed: Meta | null }
export type Settings = { resize_service: boolean; content_warning: boolean; display_avatar: boolean; display_zap_button: boolean; display_repost_button: boolean; display_media: boolean }
export type TAURI_CHANNEL<TSend> = null
/** tauri-specta globals **/

View File

@@ -20,7 +20,7 @@ export function Column({ column }: { column: LumeColumn }) {
y: rect.y,
width: rect.width,
height: rect.height,
url: `${column.url}?label=${column.label}&name=${column.name}`,
url: `${column.url}?label=${column.label}&name=${column.name}&account=${column.account}`,
});
if (res.status === "error") {

View File

@@ -105,13 +105,11 @@ export function NoteRepost({
if (signer.status === "ok") {
if (!signer.data) {
if (!signer.data) {
const res = await commands.setSigner(account);
const res = await commands.setSigner(account);
if (res.status === "error") {
await message(res.error, { kind: "error" });
return;
}
if (res.status === "error") {
await message(res.error, { kind: "error" });
return;
}
}

View File

@@ -3,14 +3,12 @@ import { ZapIcon } from "@/components";
import { settingsQueryOptions } from "@/routes/__root";
import { LumeWindow } from "@/system";
import { useSuspenseQuery } from "@tanstack/react-query";
import { useSearch } from "@tanstack/react-router";
import { useNoteContext } from "../provider";
export function NoteZap({
label = false,
smol = false,
}: { label?: boolean; smol?: boolean }) {
const search = useSearch({ strict: false });
const settings = useSuspenseQuery(settingsQueryOptions);
const event = useNoteContext();
@@ -19,7 +17,7 @@ export function NoteZap({
return (
<button
type="button"
onClick={() => LumeWindow.openZap(event.id, search.account)}
onClick={() => LumeWindow.openZap(event.id)}
className={cn(
"h-7 rounded-full inline-flex items-center justify-center text-neutral-800 hover:bg-black/5 dark:hover:bg-white/5 dark:text-neutral-200 text-sm font-medium",
label ? "w-24 gap-1.5" : "w-14",

View File

@@ -1,23 +1,28 @@
import { commands } from "@/commands.gen";
import { cn } from "@/commons";
import { cn, displayNpub } from "@/commons";
import { Spinner } from "@/components";
import { useQuery } from "@tanstack/react-query";
import { useRouteContext } from "@tanstack/react-router";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { message } from "@tauri-apps/plugin-dialog";
import { useTransition } from "react";
import { useCallback, useTransition } from "react";
import { useUserContext } from "./provider";
import type { Metadata } from "@/types";
import { MenuItem, Menu } from "@tauri-apps/api/menu";
export function UserButton({ className }: { className?: string }) {
const user = useUserContext();
const queryClient = useQueryClient();
const { queryClient } = useRouteContext({ strict: false });
const {
isLoading,
isError,
data: isFollow,
} = useQuery({
queryKey: ["status", user.pubkey],
queryKey: ["status", user?.pubkey],
queryFn: async () => {
if (!user) {
throw new Error("User not found");
}
const res = await commands.isContact(user.pubkey);
if (res.status === "ok") {
@@ -27,28 +32,89 @@ export function UserButton({ className }: { className?: string }) {
}
},
refetchOnWindowFocus: false,
refetchOnMount: false,
refetchOnReconnect: false,
retry: 2,
});
const [isPending, startTransition] = useTransition();
const toggleFollow = () => {
startTransition(async () => {
const showContextMenu = useCallback(async (e: React.MouseEvent) => {
e.preventDefault();
const accounts = await commands.getAccounts();
const list: Promise<MenuItem>[] = [];
for (const account of accounts) {
const res = await commands.getProfile(account);
let name = "unknown";
if (res.status === "ok") {
const profile: Metadata = JSON.parse(res.data);
name = profile.display_name ?? profile.name ?? "anon";
}
list.push(
MenuItem.new({
text: `Follow as ${name} (${displayNpub(account, 16)})`,
action: async () => submit(account),
}),
);
}
const items = await Promise.all(list);
const menu = await Menu.new({ items });
await menu.popup().catch((e) => console.error(e));
}, []);
const toggleFollow = useMutation({
mutationFn: async () => {
if (!user) return;
// Cancel any outgoing refetches
await queryClient.cancelQueries({ queryKey: ["status", user.pubkey] });
// Optimistically update to the new value
queryClient.setQueryData(
["status", user.pubkey],
(data: boolean) => !data,
);
const res = await commands.toggleContact(user.pubkey, null);
if (res.status === "ok") {
queryClient.setQueryData(
["status", user.pubkey],
(prev: boolean) => !prev,
);
// invalidate cache
await queryClient.invalidateQueries({
queryKey: ["status", user.pubkey],
});
return;
} else {
await message(res.error, { kind: "error" });
throw new Error(res.error);
}
},
onError: () => {
queryClient.setQueryData(["status", user?.pubkey], false);
},
onSettled: async () => {
return await queryClient.invalidateQueries({
queryKey: ["status", user?.pubkey],
});
},
});
const submit = (account: string) => {
startTransition(async () => {
const signer = await commands.hasSigner(account);
if (signer.status === "ok") {
if (!signer.data) {
const res = await commands.setSigner(account);
if (res.status === "error") {
await message(res.error, { kind: "error" });
return;
}
}
toggleFollow.mutate();
} else {
return;
}
});
@@ -57,8 +123,8 @@ export function UserButton({ className }: { className?: string }) {
return (
<button
type="button"
disabled={isPending}
onClick={() => toggleFollow()}
disabled={isPending || isLoading}
onClick={(e) => showContextMenu(e)}
className={cn("w-max gap-1", className)}
>
{isError ? "Error" : null}

View File

@@ -1,12 +1,12 @@
/* prettier-ignore-start */
/* eslint-disable */
// @ts-nocheck
// noinspection JSUnusedGlobalSymbols
// This file is auto-generated by TanStack Router
// This file was automatically generated by TanStack Router.
// You should NOT make any changes in this file as it will be overwritten.
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
import { createFileRoute } from '@tanstack/react-router'
@@ -17,13 +17,12 @@ import { Route as AppImport } from './routes/_app'
import { Route as NewPostIndexImport } from './routes/new-post/index'
import { Route as AppIndexImport } from './routes/_app/index'
import { Route as ZapIdImport } from './routes/zap.$id'
import { Route as SettingsWalletImport } from './routes/settings/wallet'
import { Route as SettingsRelaysImport } from './routes/settings/relays'
import { Route as ColumnsLayoutImport } from './routes/columns/_layout'
import { Route as IdSetProfileImport } from './routes/$id.set-profile'
import { Route as IdSetInterestImport } from './routes/$id.set-interest'
import { Route as IdSetGroupImport } from './routes/$id.set-group'
import { Route as SettingsIdWalletImport } from './routes/settings.$id/wallet'
import { Route as SettingsIdRelayImport } from './routes/settings.$id/relay'
import { Route as SettingsIdGeneralImport } from './routes/settings.$id/general'
import { Route as ColumnsLayoutGlobalImport } from './routes/columns/_layout/global'
import { Route as ColumnsLayoutCreateNewsfeedImport } from './routes/columns/_layout/create-newsfeed'
import { Route as ColumnsLayoutStoriesIdImport } from './routes/columns/_layout/stories.$id'
@@ -37,8 +36,10 @@ import { Route as ColumnsLayoutCreateNewsfeedF2fImport } from './routes/columns/
// Create Virtual Routes
const ColumnsImport = createFileRoute('/columns')()
const SettingsLazyImport = createFileRoute('/settings')()
const NewLazyImport = createFileRoute('/new')()
const SettingsIdLazyImport = createFileRoute('/settings/$id')()
const SettingsSyncLazyImport = createFileRoute('/settings/sync')()
const SettingsGeneralLazyImport = createFileRoute('/settings/general')()
const NewAccountWatchLazyImport = createFileRoute('/new-account/watch')()
const NewAccountImportLazyImport = createFileRoute('/new-account/import')()
const NewAccountConnectLazyImport = createFileRoute('/new-account/connect')()
@@ -75,6 +76,9 @@ const ColumnsLayoutNotificationIdLazyImport = createFileRoute(
const ColumnsLayoutLaunchpadIdLazyImport = createFileRoute(
'/columns/_layout/launchpad/$id',
)()
const ColumnsLayoutDvmIdLazyImport = createFileRoute(
'/columns/_layout/dvm/$id',
)()
// Create/Update Routes
@@ -84,6 +88,12 @@ const ColumnsRoute = ColumnsImport.update({
getParentRoute: () => rootRoute,
} as any)
const SettingsLazyRoute = SettingsLazyImport.update({
id: '/settings',
path: '/settings',
getParentRoute: () => rootRoute,
} as any).lazy(() => import('./routes/settings.lazy').then((d) => d.Route))
const NewLazyRoute = NewLazyImport.update({
id: '/new',
path: '/new',
@@ -109,11 +119,19 @@ const AppIndexRoute = AppIndexImport.update({
getParentRoute: () => AppRoute,
} as any).lazy(() => import('./routes/_app/index.lazy').then((d) => d.Route))
const SettingsIdLazyRoute = SettingsIdLazyImport.update({
id: '/settings/$id',
path: '/settings/$id',
getParentRoute: () => rootRoute,
} as any).lazy(() => import('./routes/settings.$id.lazy').then((d) => d.Route))
const SettingsSyncLazyRoute = SettingsSyncLazyImport.update({
id: '/sync',
path: '/sync',
getParentRoute: () => SettingsLazyRoute,
} as any).lazy(() => import('./routes/settings/sync.lazy').then((d) => d.Route))
const SettingsGeneralLazyRoute = SettingsGeneralLazyImport.update({
id: '/general',
path: '/general',
getParentRoute: () => SettingsLazyRoute,
} as any).lazy(() =>
import('./routes/settings/general.lazy').then((d) => d.Route),
)
const NewAccountWatchLazyRoute = NewAccountWatchLazyImport.update({
id: '/new-account/watch',
@@ -145,6 +163,22 @@ const ZapIdRoute = ZapIdImport.update({
getParentRoute: () => rootRoute,
} as any).lazy(() => import('./routes/zap.$id.lazy').then((d) => d.Route))
const SettingsWalletRoute = SettingsWalletImport.update({
id: '/wallet',
path: '/wallet',
getParentRoute: () => SettingsLazyRoute,
} as any).lazy(() =>
import('./routes/settings/wallet.lazy').then((d) => d.Route),
)
const SettingsRelaysRoute = SettingsRelaysImport.update({
id: '/relays',
path: '/relays',
getParentRoute: () => SettingsLazyRoute,
} as any).lazy(() =>
import('./routes/settings/relays.lazy').then((d) => d.Route),
)
const ColumnsLayoutRoute = ColumnsLayoutImport.update({
id: '/_layout',
getParentRoute: () => ColumnsRoute,
@@ -230,30 +264,6 @@ const ColumnsLayoutDiscoverInterestsLazyRoute =
),
)
const SettingsIdWalletRoute = SettingsIdWalletImport.update({
id: '/wallet',
path: '/wallet',
getParentRoute: () => SettingsIdLazyRoute,
} as any).lazy(() =>
import('./routes/settings.$id/wallet.lazy').then((d) => d.Route),
)
const SettingsIdRelayRoute = SettingsIdRelayImport.update({
id: '/relay',
path: '/relay',
getParentRoute: () => SettingsIdLazyRoute,
} as any).lazy(() =>
import('./routes/settings.$id/relay.lazy').then((d) => d.Route),
)
const SettingsIdGeneralRoute = SettingsIdGeneralImport.update({
id: '/general',
path: '/general',
getParentRoute: () => SettingsIdLazyRoute,
} as any).lazy(() =>
import('./routes/settings.$id/general.lazy').then((d) => d.Route),
)
const ColumnsLayoutGlobalRoute = ColumnsLayoutGlobalImport.update({
id: '/global',
path: '/global',
@@ -315,6 +325,14 @@ const ColumnsLayoutLaunchpadIdLazyRoute =
import('./routes/columns/_layout/launchpad.$id.lazy').then((d) => d.Route),
)
const ColumnsLayoutDvmIdLazyRoute = ColumnsLayoutDvmIdLazyImport.update({
id: '/dvm/$id',
path: '/dvm/$id',
getParentRoute: () => ColumnsLayoutRoute,
} as any).lazy(() =>
import('./routes/columns/_layout/dvm.$id.lazy').then((d) => d.Route),
)
const ColumnsLayoutStoriesIdRoute = ColumnsLayoutStoriesIdImport.update({
id: '/stories/$id',
path: '/stories/$id',
@@ -387,6 +405,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof NewLazyImport
parentRoute: typeof rootRoute
}
'/settings': {
id: '/settings'
path: '/settings'
fullPath: '/settings'
preLoaderRoute: typeof SettingsLazyImport
parentRoute: typeof rootRoute
}
'/$id/set-group': {
id: '/$id/set-group'
path: '/$id/set-group'
@@ -422,6 +447,20 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof ColumnsLayoutImport
parentRoute: typeof ColumnsRoute
}
'/settings/relays': {
id: '/settings/relays'
path: '/relays'
fullPath: '/settings/relays'
preLoaderRoute: typeof SettingsRelaysImport
parentRoute: typeof SettingsLazyImport
}
'/settings/wallet': {
id: '/settings/wallet'
path: '/wallet'
fullPath: '/settings/wallet'
preLoaderRoute: typeof SettingsWalletImport
parentRoute: typeof SettingsLazyImport
}
'/zap/$id': {
id: '/zap/$id'
path: '/zap/$id'
@@ -450,12 +489,19 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof NewAccountWatchLazyImport
parentRoute: typeof rootRoute
}
'/settings/$id': {
id: '/settings/$id'
path: '/settings/$id'
fullPath: '/settings/$id'
preLoaderRoute: typeof SettingsIdLazyImport
parentRoute: typeof rootRoute
'/settings/general': {
id: '/settings/general'
path: '/general'
fullPath: '/settings/general'
preLoaderRoute: typeof SettingsGeneralLazyImport
parentRoute: typeof SettingsLazyImport
}
'/settings/sync': {
id: '/settings/sync'
path: '/sync'
fullPath: '/settings/sync'
preLoaderRoute: typeof SettingsSyncLazyImport
parentRoute: typeof SettingsLazyImport
}
'/_app/': {
id: '/_app/'
@@ -485,27 +531,6 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof ColumnsLayoutGlobalImport
parentRoute: typeof ColumnsLayoutImport
}
'/settings/$id/general': {
id: '/settings/$id/general'
path: '/general'
fullPath: '/settings/$id/general'
preLoaderRoute: typeof SettingsIdGeneralImport
parentRoute: typeof SettingsIdLazyImport
}
'/settings/$id/relay': {
id: '/settings/$id/relay'
path: '/relay'
fullPath: '/settings/$id/relay'
preLoaderRoute: typeof SettingsIdRelayImport
parentRoute: typeof SettingsIdLazyImport
}
'/settings/$id/wallet': {
id: '/settings/$id/wallet'
path: '/wallet'
fullPath: '/settings/$id/wallet'
preLoaderRoute: typeof SettingsIdWalletImport
parentRoute: typeof SettingsIdLazyImport
}
'/columns/_layout/discover-interests': {
id: '/columns/_layout/discover-interests'
path: '/discover-interests'
@@ -597,6 +622,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof ColumnsLayoutStoriesIdImport
parentRoute: typeof ColumnsLayoutImport
}
'/columns/_layout/dvm/$id': {
id: '/columns/_layout/dvm/$id'
path: '/dvm/$id'
fullPath: '/columns/dvm/$id'
preLoaderRoute: typeof ColumnsLayoutDvmIdLazyImport
parentRoute: typeof ColumnsLayoutImport
}
'/columns/_layout/launchpad/$id': {
id: '/columns/_layout/launchpad/$id'
path: '/launchpad/$id'
@@ -647,6 +679,24 @@ const AppRouteChildren: AppRouteChildren = {
const AppRouteWithChildren = AppRoute._addFileChildren(AppRouteChildren)
interface SettingsLazyRouteChildren {
SettingsRelaysRoute: typeof SettingsRelaysRoute
SettingsWalletRoute: typeof SettingsWalletRoute
SettingsGeneralLazyRoute: typeof SettingsGeneralLazyRoute
SettingsSyncLazyRoute: typeof SettingsSyncLazyRoute
}
const SettingsLazyRouteChildren: SettingsLazyRouteChildren = {
SettingsRelaysRoute: SettingsRelaysRoute,
SettingsWalletRoute: SettingsWalletRoute,
SettingsGeneralLazyRoute: SettingsGeneralLazyRoute,
SettingsSyncLazyRoute: SettingsSyncLazyRoute,
}
const SettingsLazyRouteWithChildren = SettingsLazyRoute._addFileChildren(
SettingsLazyRouteChildren,
)
interface ColumnsLayoutCreateNewsfeedRouteChildren {
ColumnsLayoutCreateNewsfeedF2fRoute: typeof ColumnsLayoutCreateNewsfeedF2fRoute
ColumnsLayoutCreateNewsfeedUsersRoute: typeof ColumnsLayoutCreateNewsfeedUsersRoute
@@ -678,6 +728,7 @@ interface ColumnsLayoutRouteChildren {
ColumnsLayoutInterestsIdRoute: typeof ColumnsLayoutInterestsIdRoute
ColumnsLayoutNewsfeedIdRoute: typeof ColumnsLayoutNewsfeedIdRoute
ColumnsLayoutStoriesIdRoute: typeof ColumnsLayoutStoriesIdRoute
ColumnsLayoutDvmIdLazyRoute: typeof ColumnsLayoutDvmIdLazyRoute
ColumnsLayoutLaunchpadIdLazyRoute: typeof ColumnsLayoutLaunchpadIdLazyRoute
ColumnsLayoutNotificationIdLazyRoute: typeof ColumnsLayoutNotificationIdLazyRoute
ColumnsLayoutRelaysUrlLazyRoute: typeof ColumnsLayoutRelaysUrlLazyRoute
@@ -702,6 +753,7 @@ const ColumnsLayoutRouteChildren: ColumnsLayoutRouteChildren = {
ColumnsLayoutInterestsIdRoute: ColumnsLayoutInterestsIdRoute,
ColumnsLayoutNewsfeedIdRoute: ColumnsLayoutNewsfeedIdRoute,
ColumnsLayoutStoriesIdRoute: ColumnsLayoutStoriesIdRoute,
ColumnsLayoutDvmIdLazyRoute: ColumnsLayoutDvmIdLazyRoute,
ColumnsLayoutLaunchpadIdLazyRoute: ColumnsLayoutLaunchpadIdLazyRoute,
ColumnsLayoutNotificationIdLazyRoute: ColumnsLayoutNotificationIdLazyRoute,
ColumnsLayoutRelaysUrlLazyRoute: ColumnsLayoutRelaysUrlLazyRoute,
@@ -724,41 +776,26 @@ const ColumnsRouteChildren: ColumnsRouteChildren = {
const ColumnsRouteWithChildren =
ColumnsRoute._addFileChildren(ColumnsRouteChildren)
interface SettingsIdLazyRouteChildren {
SettingsIdGeneralRoute: typeof SettingsIdGeneralRoute
SettingsIdRelayRoute: typeof SettingsIdRelayRoute
SettingsIdWalletRoute: typeof SettingsIdWalletRoute
}
const SettingsIdLazyRouteChildren: SettingsIdLazyRouteChildren = {
SettingsIdGeneralRoute: SettingsIdGeneralRoute,
SettingsIdRelayRoute: SettingsIdRelayRoute,
SettingsIdWalletRoute: SettingsIdWalletRoute,
}
const SettingsIdLazyRouteWithChildren = SettingsIdLazyRoute._addFileChildren(
SettingsIdLazyRouteChildren,
)
export interface FileRoutesByFullPath {
'': typeof AppRouteWithChildren
'/new': typeof NewLazyRoute
'/settings': typeof SettingsLazyRouteWithChildren
'/$id/set-group': typeof IdSetGroupRoute
'/$id/set-interest': typeof IdSetInterestRoute
'/$id/set-profile': typeof IdSetProfileRoute
'/columns': typeof ColumnsLayoutRouteWithChildren
'/settings/relays': typeof SettingsRelaysRoute
'/settings/wallet': typeof SettingsWalletRoute
'/zap/$id': typeof ZapIdRoute
'/new-account/connect': typeof NewAccountConnectLazyRoute
'/new-account/import': typeof NewAccountImportLazyRoute
'/new-account/watch': typeof NewAccountWatchLazyRoute
'/settings/$id': typeof SettingsIdLazyRouteWithChildren
'/settings/general': typeof SettingsGeneralLazyRoute
'/settings/sync': typeof SettingsSyncLazyRoute
'/': typeof AppIndexRoute
'/new-post': typeof NewPostIndexRoute
'/columns/create-newsfeed': typeof ColumnsLayoutCreateNewsfeedRouteWithChildren
'/columns/global': typeof ColumnsLayoutGlobalRoute
'/settings/$id/general': typeof SettingsIdGeneralRoute
'/settings/$id/relay': typeof SettingsIdRelayRoute
'/settings/$id/wallet': typeof SettingsIdWalletRoute
'/columns/discover-interests': typeof ColumnsLayoutDiscoverInterestsLazyRoute
'/columns/discover-newsfeeds': typeof ColumnsLayoutDiscoverNewsfeedsLazyRoute
'/columns/discover-relays': typeof ColumnsLayoutDiscoverRelaysLazyRoute
@@ -772,6 +809,7 @@ export interface FileRoutesByFullPath {
'/columns/interests/$id': typeof ColumnsLayoutInterestsIdRoute
'/columns/newsfeed/$id': typeof ColumnsLayoutNewsfeedIdRoute
'/columns/stories/$id': typeof ColumnsLayoutStoriesIdRoute
'/columns/dvm/$id': typeof ColumnsLayoutDvmIdLazyRoute
'/columns/launchpad/$id': typeof ColumnsLayoutLaunchpadIdLazyRoute
'/columns/notification/$id': typeof ColumnsLayoutNotificationIdLazyRoute
'/columns/relays/$url': typeof ColumnsLayoutRelaysUrlLazyRoute
@@ -781,22 +819,23 @@ export interface FileRoutesByFullPath {
export interface FileRoutesByTo {
'/new': typeof NewLazyRoute
'/settings': typeof SettingsLazyRouteWithChildren
'/$id/set-group': typeof IdSetGroupRoute
'/$id/set-interest': typeof IdSetInterestRoute
'/$id/set-profile': typeof IdSetProfileRoute
'/columns': typeof ColumnsLayoutRouteWithChildren
'/settings/relays': typeof SettingsRelaysRoute
'/settings/wallet': typeof SettingsWalletRoute
'/zap/$id': typeof ZapIdRoute
'/new-account/connect': typeof NewAccountConnectLazyRoute
'/new-account/import': typeof NewAccountImportLazyRoute
'/new-account/watch': typeof NewAccountWatchLazyRoute
'/settings/$id': typeof SettingsIdLazyRouteWithChildren
'/settings/general': typeof SettingsGeneralLazyRoute
'/settings/sync': typeof SettingsSyncLazyRoute
'/': typeof AppIndexRoute
'/new-post': typeof NewPostIndexRoute
'/columns/create-newsfeed': typeof ColumnsLayoutCreateNewsfeedRouteWithChildren
'/columns/global': typeof ColumnsLayoutGlobalRoute
'/settings/$id/general': typeof SettingsIdGeneralRoute
'/settings/$id/relay': typeof SettingsIdRelayRoute
'/settings/$id/wallet': typeof SettingsIdWalletRoute
'/columns/discover-interests': typeof ColumnsLayoutDiscoverInterestsLazyRoute
'/columns/discover-newsfeeds': typeof ColumnsLayoutDiscoverNewsfeedsLazyRoute
'/columns/discover-relays': typeof ColumnsLayoutDiscoverRelaysLazyRoute
@@ -810,6 +849,7 @@ export interface FileRoutesByTo {
'/columns/interests/$id': typeof ColumnsLayoutInterestsIdRoute
'/columns/newsfeed/$id': typeof ColumnsLayoutNewsfeedIdRoute
'/columns/stories/$id': typeof ColumnsLayoutStoriesIdRoute
'/columns/dvm/$id': typeof ColumnsLayoutDvmIdLazyRoute
'/columns/launchpad/$id': typeof ColumnsLayoutLaunchpadIdLazyRoute
'/columns/notification/$id': typeof ColumnsLayoutNotificationIdLazyRoute
'/columns/relays/$url': typeof ColumnsLayoutRelaysUrlLazyRoute
@@ -821,23 +861,24 @@ export interface FileRoutesById {
__root__: typeof rootRoute
'/_app': typeof AppRouteWithChildren
'/new': typeof NewLazyRoute
'/settings': typeof SettingsLazyRouteWithChildren
'/$id/set-group': typeof IdSetGroupRoute
'/$id/set-interest': typeof IdSetInterestRoute
'/$id/set-profile': typeof IdSetProfileRoute
'/columns': typeof ColumnsRouteWithChildren
'/columns/_layout': typeof ColumnsLayoutRouteWithChildren
'/settings/relays': typeof SettingsRelaysRoute
'/settings/wallet': typeof SettingsWalletRoute
'/zap/$id': typeof ZapIdRoute
'/new-account/connect': typeof NewAccountConnectLazyRoute
'/new-account/import': typeof NewAccountImportLazyRoute
'/new-account/watch': typeof NewAccountWatchLazyRoute
'/settings/$id': typeof SettingsIdLazyRouteWithChildren
'/settings/general': typeof SettingsGeneralLazyRoute
'/settings/sync': typeof SettingsSyncLazyRoute
'/_app/': typeof AppIndexRoute
'/new-post/': typeof NewPostIndexRoute
'/columns/_layout/create-newsfeed': typeof ColumnsLayoutCreateNewsfeedRouteWithChildren
'/columns/_layout/global': typeof ColumnsLayoutGlobalRoute
'/settings/$id/general': typeof SettingsIdGeneralRoute
'/settings/$id/relay': typeof SettingsIdRelayRoute
'/settings/$id/wallet': typeof SettingsIdWalletRoute
'/columns/_layout/discover-interests': typeof ColumnsLayoutDiscoverInterestsLazyRoute
'/columns/_layout/discover-newsfeeds': typeof ColumnsLayoutDiscoverNewsfeedsLazyRoute
'/columns/_layout/discover-relays': typeof ColumnsLayoutDiscoverRelaysLazyRoute
@@ -851,6 +892,7 @@ export interface FileRoutesById {
'/columns/_layout/interests/$id': typeof ColumnsLayoutInterestsIdRoute
'/columns/_layout/newsfeed/$id': typeof ColumnsLayoutNewsfeedIdRoute
'/columns/_layout/stories/$id': typeof ColumnsLayoutStoriesIdRoute
'/columns/_layout/dvm/$id': typeof ColumnsLayoutDvmIdLazyRoute
'/columns/_layout/launchpad/$id': typeof ColumnsLayoutLaunchpadIdLazyRoute
'/columns/_layout/notification/$id': typeof ColumnsLayoutNotificationIdLazyRoute
'/columns/_layout/relays/$url': typeof ColumnsLayoutRelaysUrlLazyRoute
@@ -863,22 +905,23 @@ export interface FileRouteTypes {
fullPaths:
| ''
| '/new'
| '/settings'
| '/$id/set-group'
| '/$id/set-interest'
| '/$id/set-profile'
| '/columns'
| '/settings/relays'
| '/settings/wallet'
| '/zap/$id'
| '/new-account/connect'
| '/new-account/import'
| '/new-account/watch'
| '/settings/$id'
| '/settings/general'
| '/settings/sync'
| '/'
| '/new-post'
| '/columns/create-newsfeed'
| '/columns/global'
| '/settings/$id/general'
| '/settings/$id/relay'
| '/settings/$id/wallet'
| '/columns/discover-interests'
| '/columns/discover-newsfeeds'
| '/columns/discover-relays'
@@ -892,6 +935,7 @@ export interface FileRouteTypes {
| '/columns/interests/$id'
| '/columns/newsfeed/$id'
| '/columns/stories/$id'
| '/columns/dvm/$id'
| '/columns/launchpad/$id'
| '/columns/notification/$id'
| '/columns/relays/$url'
@@ -900,22 +944,23 @@ export interface FileRouteTypes {
fileRoutesByTo: FileRoutesByTo
to:
| '/new'
| '/settings'
| '/$id/set-group'
| '/$id/set-interest'
| '/$id/set-profile'
| '/columns'
| '/settings/relays'
| '/settings/wallet'
| '/zap/$id'
| '/new-account/connect'
| '/new-account/import'
| '/new-account/watch'
| '/settings/$id'
| '/settings/general'
| '/settings/sync'
| '/'
| '/new-post'
| '/columns/create-newsfeed'
| '/columns/global'
| '/settings/$id/general'
| '/settings/$id/relay'
| '/settings/$id/wallet'
| '/columns/discover-interests'
| '/columns/discover-newsfeeds'
| '/columns/discover-relays'
@@ -929,6 +974,7 @@ export interface FileRouteTypes {
| '/columns/interests/$id'
| '/columns/newsfeed/$id'
| '/columns/stories/$id'
| '/columns/dvm/$id'
| '/columns/launchpad/$id'
| '/columns/notification/$id'
| '/columns/relays/$url'
@@ -938,23 +984,24 @@ export interface FileRouteTypes {
| '__root__'
| '/_app'
| '/new'
| '/settings'
| '/$id/set-group'
| '/$id/set-interest'
| '/$id/set-profile'
| '/columns'
| '/columns/_layout'
| '/settings/relays'
| '/settings/wallet'
| '/zap/$id'
| '/new-account/connect'
| '/new-account/import'
| '/new-account/watch'
| '/settings/$id'
| '/settings/general'
| '/settings/sync'
| '/_app/'
| '/new-post/'
| '/columns/_layout/create-newsfeed'
| '/columns/_layout/global'
| '/settings/$id/general'
| '/settings/$id/relay'
| '/settings/$id/wallet'
| '/columns/_layout/discover-interests'
| '/columns/_layout/discover-newsfeeds'
| '/columns/_layout/discover-relays'
@@ -968,6 +1015,7 @@ export interface FileRouteTypes {
| '/columns/_layout/interests/$id'
| '/columns/_layout/newsfeed/$id'
| '/columns/_layout/stories/$id'
| '/columns/_layout/dvm/$id'
| '/columns/_layout/launchpad/$id'
| '/columns/_layout/notification/$id'
| '/columns/_layout/relays/$url'
@@ -979,6 +1027,7 @@ export interface FileRouteTypes {
export interface RootRouteChildren {
AppRoute: typeof AppRouteWithChildren
NewLazyRoute: typeof NewLazyRoute
SettingsLazyRoute: typeof SettingsLazyRouteWithChildren
IdSetGroupRoute: typeof IdSetGroupRoute
IdSetInterestRoute: typeof IdSetInterestRoute
IdSetProfileRoute: typeof IdSetProfileRoute
@@ -987,13 +1036,13 @@ export interface RootRouteChildren {
NewAccountConnectLazyRoute: typeof NewAccountConnectLazyRoute
NewAccountImportLazyRoute: typeof NewAccountImportLazyRoute
NewAccountWatchLazyRoute: typeof NewAccountWatchLazyRoute
SettingsIdLazyRoute: typeof SettingsIdLazyRouteWithChildren
NewPostIndexRoute: typeof NewPostIndexRoute
}
const rootRouteChildren: RootRouteChildren = {
AppRoute: AppRouteWithChildren,
NewLazyRoute: NewLazyRoute,
SettingsLazyRoute: SettingsLazyRouteWithChildren,
IdSetGroupRoute: IdSetGroupRoute,
IdSetInterestRoute: IdSetInterestRoute,
IdSetProfileRoute: IdSetProfileRoute,
@@ -1002,7 +1051,6 @@ const rootRouteChildren: RootRouteChildren = {
NewAccountConnectLazyRoute: NewAccountConnectLazyRoute,
NewAccountImportLazyRoute: NewAccountImportLazyRoute,
NewAccountWatchLazyRoute: NewAccountWatchLazyRoute,
SettingsIdLazyRoute: SettingsIdLazyRouteWithChildren,
NewPostIndexRoute: NewPostIndexRoute,
}
@@ -1010,8 +1058,6 @@ export const routeTree = rootRoute
._addFileChildren(rootRouteChildren)
._addFileTypes<FileRouteTypes>()
/* prettier-ignore-end */
/* ROUTE_MANIFEST_START
{
"routes": {
@@ -1020,6 +1066,7 @@ export const routeTree = rootRoute
"children": [
"/_app",
"/new",
"/settings",
"/$id/set-group",
"/$id/set-interest",
"/$id/set-profile",
@@ -1028,7 +1075,6 @@ export const routeTree = rootRoute
"/new-account/connect",
"/new-account/import",
"/new-account/watch",
"/settings/$id",
"/new-post/"
]
},
@@ -1041,6 +1087,15 @@ export const routeTree = rootRoute
"/new": {
"filePath": "new.lazy.tsx"
},
"/settings": {
"filePath": "settings.lazy.tsx",
"children": [
"/settings/relays",
"/settings/wallet",
"/settings/general",
"/settings/sync"
]
},
"/$id/set-group": {
"filePath": "$id.set-group.tsx"
},
@@ -1073,6 +1128,7 @@ export const routeTree = rootRoute
"/columns/_layout/interests/$id",
"/columns/_layout/newsfeed/$id",
"/columns/_layout/stories/$id",
"/columns/_layout/dvm/$id",
"/columns/_layout/launchpad/$id",
"/columns/_layout/notification/$id",
"/columns/_layout/relays/$url",
@@ -1080,6 +1136,14 @@ export const routeTree = rootRoute
"/columns/_layout/users/$id"
]
},
"/settings/relays": {
"filePath": "settings/relays.tsx",
"parent": "/settings"
},
"/settings/wallet": {
"filePath": "settings/wallet.tsx",
"parent": "/settings"
},
"/zap/$id": {
"filePath": "zap.$id.tsx"
},
@@ -1092,13 +1156,13 @@ export const routeTree = rootRoute
"/new-account/watch": {
"filePath": "new-account/watch.lazy.tsx"
},
"/settings/$id": {
"filePath": "settings.$id.lazy.tsx",
"children": [
"/settings/$id/general",
"/settings/$id/relay",
"/settings/$id/wallet"
]
"/settings/general": {
"filePath": "settings/general.lazy.tsx",
"parent": "/settings"
},
"/settings/sync": {
"filePath": "settings/sync.lazy.tsx",
"parent": "/settings"
},
"/_app/": {
"filePath": "_app/index.tsx",
@@ -1119,18 +1183,6 @@ export const routeTree = rootRoute
"filePath": "columns/_layout/global.tsx",
"parent": "/columns/_layout"
},
"/settings/$id/general": {
"filePath": "settings.$id/general.tsx",
"parent": "/settings/$id"
},
"/settings/$id/relay": {
"filePath": "settings.$id/relay.tsx",
"parent": "/settings/$id"
},
"/settings/$id/wallet": {
"filePath": "settings.$id/wallet.tsx",
"parent": "/settings/$id"
},
"/columns/_layout/discover-interests": {
"filePath": "columns/_layout/discover-interests.lazy.tsx",
"parent": "/columns/_layout"
@@ -1183,6 +1235,10 @@ export const routeTree = rootRoute
"filePath": "columns/_layout/stories.$id.tsx",
"parent": "/columns/_layout"
},
"/columns/_layout/dvm/$id": {
"filePath": "columns/_layout/dvm.$id.lazy.tsx",
"parent": "/columns/_layout"
},
"/columns/_layout/launchpad/$id": {
"filePath": "columns/_layout/launchpad.$id.lazy.tsx",
"parent": "/columns/_layout"

View File

@@ -118,7 +118,7 @@ function Account({ pubkey }: { pubkey: string }) {
const items = await Promise.all([
MenuItem.new({
text: "Unlock",
enabled: !isActive || true,
enabled: !isActive,
action: async () => await commands.setSigner(pubkey),
}),
PredefinedMenuItem.new({ item: "Separator" }),
@@ -154,7 +154,7 @@ function Account({ pubkey }: { pubkey: string }) {
PredefinedMenuItem.new({ item: "Separator" }),
MenuItem.new({
text: "Settings",
action: () => LumeWindow.openSettings(pubkey),
action: () => LumeWindow.openSettings(),
}),
PredefinedMenuItem.new({ item: "Separator" }),
MenuItem.new({
@@ -183,7 +183,7 @@ function Account({ pubkey }: { pubkey: string }) {
await menu.popup().catch((e) => console.error(e));
},
[pubkey],
[isActive, pubkey],
);
useEffect(() => {

View File

@@ -1,16 +1,8 @@
import { cn } from "@/commons";
import type { ColumnRouteSearch } from "@/types";
import { Link, Outlet } from "@tanstack/react-router";
import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/columns/_layout/create-newsfeed")({
validateSearch: (search: Record<string, string>): ColumnRouteSearch => {
return {
account: search.account,
label: search.label,
name: search.name,
};
},
component: Screen,
});

View File

@@ -27,7 +27,7 @@ function Screen() {
initialPageParam: 0,
queryFn: async ({ pageParam }: { pageParam: number }) => {
const until = pageParam > 0 ? pageParam.toString() : null;
const res = await commands.getAllRelays(until);
const res = await commands.getAllRelayLists(until);
if (res.status === "ok") {
const data: NostrEvent[] = res.data.map((item) => JSON.parse(item));

View File

@@ -0,0 +1,108 @@
import { commands } from "@/commands.gen";
import { toLumeEvents } from "@/commons";
import { RepostNote, Spinner, TextNote } from "@/components";
import type { LumeEvent } from "@/system";
import { Kind } from "@/types";
import * as ScrollArea from "@radix-ui/react-scroll-area";
import { useQuery } from "@tanstack/react-query";
import { createLazyFileRoute } from "@tanstack/react-router";
import { type RefObject, useCallback, useRef } from "react";
import { Virtualizer } from "virtua";
export const Route = createLazyFileRoute("/columns/_layout/dvm/$id")({
component: Screen,
});
function Screen() {
const { id } = Route.useParams();
const { account } = Route.useSearch();
const { isLoading, isError, error, data } = useQuery({
queryKey: ["job-result", id],
queryFn: async () => {
if (!account) {
throw new Error("Account is required");
}
const res = await commands.getAllEventsByRequest(account, id);
if (res.status === "error") {
throw new Error(res.error);
}
return toLumeEvents(res.data);
},
refetchOnWindowFocus: false,
});
const ref = useRef<HTMLDivElement>(null);
const renderItem = useCallback(
(event: LumeEvent) => {
if (!event) {
return;
}
switch (event.kind) {
case Kind.Repost: {
const repostId = event.repostId;
return (
<RepostNote
key={repostId + event.id}
event={event}
className="border-b-[.5px] border-neutral-300 dark:border-neutral-700"
/>
);
}
default:
return (
<TextNote
key={event.id}
event={event}
className="border-b-[.5px] border-neutral-300 dark:border-neutral-700"
/>
);
}
},
[data],
);
return (
<ScrollArea.Root
type={"scroll"}
scrollHideDelay={300}
className="overflow-hidden size-full px-3"
>
<ScrollArea.Viewport
ref={ref}
className="relative h-full bg-white dark:bg-neutral-800 rounded-t-xl shadow shadow-neutral-300/50 dark:shadow-none border-[.5px] border-neutral-300 dark:border-neutral-700"
>
<Virtualizer scrollRef={ref as unknown as RefObject<HTMLElement>}>
{isLoading ? (
<div className="flex items-center justify-center w-full h-16 gap-2">
<Spinner className="size-4" />
<span className="text-sm font-medium">Requesting events...</span>
</div>
) : isError ? (
<div className="flex items-center justify-center w-full h-16 gap-2">
<span className="text-sm font-medium">{error?.message}</span>
</div>
) : !data?.length ? (
<div className="mb-3 flex items-center justify-center h-20 text-sm">
🎉 Yo. You're catching up on all latest notes.
</div>
) : (
data.map((item) => renderItem(item))
)}
</Virtualizer>
</ScrollArea.Viewport>
<ScrollArea.Scrollbar
className="flex select-none touch-none p-0.5 duration-[160ms] ease-out data-[orientation=vertical]:w-2"
orientation="vertical"
>
<ScrollArea.Thumb className="flex-1 bg-black/10 dark:bg-white/10 rounded-full relative before:content-[''] before:absolute before:top-1/2 before:left-1/2 before:-translate-x-1/2 before:-translate-y-1/2 before:w-full before:h-full before:min-w-[44px] before:min-h-[44px]" />
</ScrollArea.Scrollbar>
<ScrollArea.Corner className="bg-transparent" />
</ScrollArea.Root>
);
}

View File

@@ -99,14 +99,9 @@ function ReplyList() {
const res = await commands.getReplies(id);
if (res.status === "ok") {
const events = res.data
// Create Lume Events
.map((item) => LumeEvent.from(item.raw, item.parsed))
// Filter quote
.filter(
(ev) =>
!ev.tags.filter((t) => t[0] === "q" || t[3] === "mention").length,
);
const events = res.data.map((item) =>
LumeEvent.from(item.raw, item.parsed),
);
return events;
} else {
@@ -179,7 +174,7 @@ function ReplyList() {
useEffect(() => {
const unlisten = getCurrentWindow().listen<EventPayload>(
"event",
"comment",
async (data) => {
const event = LumeEvent.from(data.payload.raw, data.payload.parsed);
@@ -216,7 +211,7 @@ function ReplyList() {
{isLoading ? (
<div className="flex items-center justify-center gap-2">
<Spinner className="size-4" />
<span className="text-sm font-medium">Getting replies...</span>
<span className="text-sm font-medium">Loading replies...</span>
</div>
) : (
<div className="flex flex-col gap-3">

View File

@@ -1,9 +1,3 @@
import { commands } from "@/commands.gen";
import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/columns/_layout/events/$id")({
beforeLoad: async () => {
const accounts = await commands.getAccounts();
return { accounts };
},
});
export const Route = createFileRoute("/columns/_layout/events/$id")();

View File

@@ -11,7 +11,8 @@ import { resolveResource } from "@tauri-apps/api/path";
import { message } from "@tauri-apps/plugin-dialog";
import { readTextFile } from "@tauri-apps/plugin-fs";
import { nanoid } from "nanoid";
import { useCallback, useState, useTransition } from "react";
import { memo, useCallback, useState, useTransition } from "react";
import { minidenticon } from "minidenticons";
export const Route = createLazyFileRoute("/columns/_layout/launchpad/$id")({
component: Screen,
@@ -28,6 +29,7 @@ function Screen() {
<Newsfeeds />
<Relayfeeds />
<Interests />
<ContentDiscovery />
<Core />
</ScrollArea.Viewport>
<ScrollArea.Scrollbar
@@ -71,7 +73,7 @@ function Newsfeeds() {
: item.tags.find((tag) => tag[0] === "title")?.[1] || "Unnamed";
const label =
item.kind === 3
? `newsfeed-${id.slice(0, 5)}`
? `newsfeed-${item.pubkey.slice(0, 5)}`
: item.tags.find((tag) => tag[0] === "d")?.[1] || nanoid();
return (
@@ -436,22 +438,20 @@ function Interests() {
</User.Provider>
<h5 className="text-xs font-medium">{name}</h5>
</div>
<div className="flex items-center gap-3">
<button
type="button"
onClick={() =>
LumeWindow.openColumn({
label,
name,
account: id,
url: `/columns/interests/${item.id}`,
})
}
className="h-6 w-16 inline-flex items-center justify-center gap-1 text-xs font-semibold rounded-full bg-neutral-200 dark:bg-neutral-700 hover:bg-blue-500 hover:text-white"
>
Add
</button>
</div>
<button
type="button"
onClick={() =>
LumeWindow.openColumn({
label,
name,
account: id,
url: `/columns/interests/${item.id}`,
})
}
className="h-6 w-16 inline-flex items-center justify-center gap-1 text-xs font-semibold rounded-full bg-neutral-200 dark:bg-neutral-700 hover:bg-blue-500 hover:text-white"
>
Add
</button>
</div>
</div>
);
@@ -522,6 +522,132 @@ function Interests() {
);
}
function ContentDiscovery() {
const { isLoading, isError, error, data } = useQuery({
queryKey: ["content-discovery"],
queryFn: async () => {
const res = await commands.getAllProviders();
if (res.status === "ok") {
const events: NostrEvent[] = res.data.map((item) => JSON.parse(item));
return events;
} else {
throw new Error(res.error);
}
},
refetchOnWindowFocus: false,
});
return (
<div className="mb-12 flex flex-col gap-3">
<div className="flex items-center justify-between px-2">
<h3 className="font-semibold">Content Discovery</h3>
</div>
<div className="flex flex-col gap-3">
{isLoading ? (
<div className="inline-flex items-center gap-1.5">
<Spinner className="size-4" />
Loading...
</div>
) : isError ? (
<div className="flex flex-col items-center justify-center h-16 w-full rounded-xl overflow-hidden bg-neutral-200/50 dark:bg-neutral-800/50">
<p className="text-center">{error?.message ?? "Error"}</p>
</div>
) : !data ? (
<div className="flex flex-col items-center justify-center h-16 w-full rounded-xl overflow-hidden bg-neutral-200/50 dark:bg-neutral-800/50">
<p className="text-center">Empty.</p>
</div>
) : (
<div className="flex flex-col rounded-xl overflow-hidden bg-white dark:bg-neutral-800/50 shadow-lg shadow-primary dark:ring-1 dark:ring-neutral-800">
<div className="flex flex-col gap-2 p-2">
{data?.map((item) => (
<Provider key={item.id} event={item} />
))}
</div>
</div>
)}
</div>
</div>
);
}
const Provider = memo(function Provider({ event }: { event: NostrEvent }) {
const { id } = Route.useParams();
const [isPending, startTransition] = useTransition();
const metadata: { [key: string]: string } = JSON.parse(event.content);
const fallback = `data:image/svg+xml;utf8,${encodeURIComponent(
minidenticon(event.id, 60, 50),
)}`;
const request = (name: string | undefined, provider: string) => {
startTransition(async () => {
// Ensure signer
const signer = await commands.hasSigner(id);
if (signer.status === "ok") {
if (!signer.data) {
const res = await commands.setSigner(id);
if (res.status === "error") {
await message(res.error, { kind: "error" });
return;
}
}
// Send request event to provider
const res = await commands.requestEventsFromProvider(provider);
if (res.status === "ok") {
// Open column
await LumeWindow.openColumn({
label: `dvm_${provider.slice(0, 6)}`,
name: name || "Content Discovery",
account: id,
url: `/columns/dvm/${provider}`,
});
return;
} else {
await message(res.error, { kind: "error" });
return;
}
} else {
await message(signer.error, { kind: "error" });
return;
}
});
};
return (
<div className="group px-3 flex gap-2 items-center justify-between h-16 rounded-lg bg-neutral-100 dark:bg-neutral-800">
<div className="shrink-0 size-10 bg-neutral-200 dark:bg-neutral-700 rounded-full overflow-hidden">
<img
src={metadata.picture || fallback}
alt={event.id}
className="size-10 object-cover"
/>
</div>
<div className="flex-1 flex flex-col truncate">
<h5 className="text-sm font-medium">{metadata.name}</h5>
<p className="w-full text-sm truncate text-neutral-600 dark:text-neutral-400">
{metadata.about}
</p>
</div>
<button
type="button"
onClick={() => request(metadata.name, event.pubkey)}
disabled={isPending}
className={cn(
"h-6 w-16 group-hover:visible inline-flex items-center justify-center gap-1 text-xs font-semibold rounded-full bg-neutral-200 dark:bg-neutral-700 hover:bg-blue-500 hover:text-white",
isPending ? "" : "invisible",
)}
>
{isPending ? <Spinner className="size-3" /> : "Add"}
</button>
</div>
);
});
function Core() {
const { id } = Route.useParams();
const { data } = useQuery({

View File

@@ -120,19 +120,19 @@ function Screen() {
>
<Tabs.List className="h-11 shrink-0 flex items-center">
<Tabs.Trigger
className="flex-1 inline-flex h-11 items-center justify-center gap-2 px-3 text-sm font-medium border-b border-neutral-100 dark:border-neutral-900 data-[state=active]:border-neutral-200 dark:data-[state=active]:border-neutral-800 data-[state=inactive]:opacity-50"
className="flex-1 inline-flex h-11 items-center justify-center gap-2 px-3 text-sm font-medium border-b border-neutral-100 dark:border-neutral-700 data-[state=active]:border-neutral-200 dark:data-[state=active]:border-neutral-600 data-[state=inactive]:opacity-50"
value="replies"
>
Replies
</Tabs.Trigger>
<Tabs.Trigger
className="flex-1 inline-flex h-11 items-center justify-center gap-2 px-3 text-sm font-medium border-b border-neutral-100 dark:border-neutral-900 data-[state=active]:border-neutral-200 dark:data-[state=active]:border-neutral-800 data-[state=inactive]:opacity-50"
className="flex-1 inline-flex h-11 items-center justify-center gap-2 px-3 text-sm font-medium border-b border-neutral-100 dark:border-neutral-700 data-[state=active]:border-neutral-200 dark:data-[state=active]:border-neutral-600 data-[state=inactive]:opacity-50"
value="reactions"
>
Reactions
</Tabs.Trigger>
<Tabs.Trigger
className="flex-1 inline-flex h-11 items-center justify-center gap-2 px-3 text-sm font-medium border-b border-neutral-100 dark:border-neutral-900 data-[state=active]:border-neutral-200 dark:data-[state=active]:border-neutral-800 data-[state=inactive]:opacity-50"
className="flex-1 inline-flex h-11 items-center justify-center gap-2 px-3 text-sm font-medium border-b border-neutral-100 dark:border-neutral-700 data-[state=active]:border-neutral-200 dark:data-[state=active]:border-neutral-600 data-[state=inactive]:opacity-50"
value="zaps"
>
Zaps

View File

@@ -70,7 +70,7 @@ export const Route = createLazyFileRoute("/new-post/")({
function Screen() {
const { reply_to } = Route.useSearch();
const { accounts, initialValue, queryClient } = Route.useRouteContext();
const { accounts, initialValue } = Route.useRouteContext();
const { deferMentionList } = Route.useLoaderData();
const users = useAwaited({ promise: deferMentionList })[0];

View File

@@ -1,3 +0,0 @@
import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/settings/$id/general")();

View File

@@ -1,156 +0,0 @@
import { commands } from "@/commands.gen";
import { Plus, X } from "@phosphor-icons/react";
import { createLazyFileRoute } from "@tanstack/react-router";
import { message } from "@tauri-apps/plugin-dialog";
import { useEffect, useState, useTransition } from "react";
export const Route = createLazyFileRoute("/settings/$id/relay")({
component: Screen,
});
function Screen() {
const { relayList } = Route.useRouteContext();
const [relays, setRelays] = useState<string[]>([]);
const [newRelay, setNewRelay] = useState<string>("");
const [isPending, startTransition] = useTransition();
const removeRelay = async (relay: string) => {
const res = await commands.removeRelay(relay);
if (res.status === "ok") {
return res.data;
} else {
throw new Error(res.error);
}
};
const addNewRelay = () => {
startTransition(async () => {
try {
let url = newRelay;
if (!url.startsWith("wss://")) {
url = `wss://${url}`;
}
const relay = new URL(url);
const res = await commands.connectRelay(relay.toString());
if (res.status === "ok") {
setRelays((prev) => [...prev, newRelay]);
setNewRelay("");
} else {
await message(res.error, { title: "Relay", kind: "error" });
return;
}
} catch {
await message("URL is not valid.", { kind: "error" });
return;
}
});
};
useEffect(() => {
setRelays(relayList.connected);
}, [relayList]);
return (
<div className="w-full px-3 pb-3">
<div className="flex flex-col gap-6">
<div className="flex flex-col gap-2">
<h2 className="text-sm font-semibold text-neutral-700 dark:text-neutral-300">
Connected Relays
</h2>
<div className="flex flex-col px-3 divide-y divide-black/10 dark:divide-white/10 bg-black/5 dark:bg-white/5 rounded-xl">
{relays.map((relay) => (
<div
key={relay}
className="flex items-center justify-between h-11"
>
<div className="inline-flex items-center gap-2 text-sm font-medium">
<span className="relative flex size-2">
<span className="absolute inline-flex w-full h-full bg-teal-400 rounded-full opacity-75 animate-ping" />
<span className="relative inline-flex bg-teal-500 rounded-full size-2" />
</span>
{relay}
</div>
<div>
<button
type="button"
onClick={() => removeRelay(relay)}
className="inline-flex items-center justify-center rounded-md size-7 hover:bg-black/10 dark:hover:bg-white/10"
>
<X className="size-4" />
</button>
</div>
</div>
))}
<div className="flex items-center h-14">
<div className="flex items-center w-full gap-2 mb-0">
<input
value={newRelay}
onChange={(e) => setNewRelay(e.target.value)}
name="url"
placeholder="wss://..."
disabled={isPending}
spellCheck={false}
className="flex-1 px-3 bg-transparent rounded-lg h-9 border-neutral-300 placeholder:text-neutral-500 focus:border-blue-500 focus:ring-0 dark:border-neutral-700 dark:placeholder:text-neutral-400"
/>
<button
type="button"
disabled={isPending}
onClick={() => addNewRelay()}
className="inline-flex items-center justify-center w-16 px-2 text-sm font-medium text-white rounded-lg shrink-0 h-9 bg-black/20 dark:bg-white/20 hover:bg-blue-500 disabled:opacity-50"
>
<Plus className="size-5" />
</button>
</div>
</div>
</div>
</div>
<div className="flex flex-col gap-2">
<h2 className="text-sm font-semibold text-neutral-700 dark:text-neutral-300">
User Relays (NIP-65)
</h2>
<div className="flex flex-col px-3 py-2 bg-black/5 dark:bg-white/5 rounded-xl">
<p className="text-sm text-yellow-500">
Lume will automatically connect to the user's relay list, but the
manager function (like adding, removing, changing relay purpose)
is not yet available.
</p>
</div>
<div className="flex flex-col px-3 divide-y divide-black/10 dark:divide-white/10 bg-black/5 dark:bg-white/5 rounded-xl">
{relayList.read?.map((relay) => (
<div
key={relay}
className="flex items-center justify-between h-11"
>
<div className="text-sm font-medium">{relay}</div>
<div className="text-xs font-semibold">READ</div>
</div>
))}
{relayList.write?.map((relay) => (
<div
key={relay}
className="flex items-center justify-between h-11"
>
<div className="text-sm font-medium">{relay}</div>
<div className="text-xs font-semibold">WRITE</div>
</div>
))}
{relayList.both?.map((relay) => (
<div
key={relay}
className="flex items-center justify-between h-11"
>
<div className="text-sm font-medium">{relay}</div>
<div className="text-xs font-semibold">READ + WRITE</div>
</div>
))}
</div>
</div>
</div>
</div>
);
}

View File

@@ -1,15 +1,19 @@
import { cn } from "@/commons";
import { CurrencyBtc, GearSix, HardDrives, User } from "@phosphor-icons/react";
import {
CloudArrowDown,
CurrencyBtc,
GearSix,
HardDrives,
} from "@phosphor-icons/react";
import * as ScrollArea from "@radix-ui/react-scroll-area";
import { Link } from "@tanstack/react-router";
import { Outlet, createLazyFileRoute } from "@tanstack/react-router";
export const Route = createLazyFileRoute("/settings/$id")({
export const Route = createLazyFileRoute("/settings")({
component: Screen,
});
function Screen() {
const { id } = Route.useParams();
const { platform } = Route.useRouteContext();
return (
@@ -24,7 +28,7 @@ function Screen() {
<div className="h-8 px-1.5">
<h1 className="text-lg font-semibold">Settings</h1>
</div>
<Link to="/settings/$id/general" params={{ id }}>
<Link to="/settings/general">
{({ isActive }) => {
return (
<div
@@ -41,7 +45,7 @@ function Screen() {
);
}}
</Link>
<Link to="/settings/$id/profile" params={{ id }}>
<Link to="/settings/sync">
{({ isActive }) => {
return (
<div
@@ -52,13 +56,13 @@ function Screen() {
: "text-neutral-700 hover:bg-black/10 dark:text-neutral-300 dark:hover:bg-white/10",
)}
>
<User className="size-5 shrink-0" />
<p className="text-sm font-medium">Profile</p>
<CloudArrowDown className="size-5 shrink-0" />
<p className="text-sm font-medium">Sync</p>
</div>
);
}}
</Link>
<Link to="/settings/$id/relay" params={{ id }}>
<Link to="/settings/relays">
{({ isActive }) => {
return (
<div
@@ -70,12 +74,12 @@ function Screen() {
)}
>
<HardDrives className="size-5 shrink-0" />
<p className="text-sm font-medium">Relay</p>
<p className="text-sm font-medium">Relays</p>
</div>
);
}}
</Link>
<Link to="/settings/$id/wallet" params={{ id }}>
<Link to="/settings/wallet">
{({ isActive }) => {
return (
<div

View File

@@ -17,7 +17,7 @@ import { settingsQueryOptions } from "../__root";
type Theme = "auto" | "light" | "dark";
export const Route = createLazyFileRoute("/settings/$id/general")({
export const Route = createLazyFileRoute("/settings/general")({
component: Screen,
});
@@ -46,6 +46,7 @@ function Screen() {
return;
} else {
await message(res.error, { kind: "error" });
return;
}
});
};
@@ -68,9 +69,7 @@ function Screen() {
<div className="relative w-full">
<div className="flex flex-col gap-6 px-3 pb-3">
<div className="flex flex-col gap-2">
<h2 className="text-sm font-semibold text-neutral-700 dark:text-neutral-300">
General
</h2>
<h2 className="text-sm font-semibold">General</h2>
<div className="flex flex-col px-3 divide-y divide-black/10 dark:divide-white/10 bg-black/5 dark:bg-white/5 rounded-xl">
<Setting
name="Content Warning"
@@ -91,9 +90,7 @@ function Screen() {
</div>
</div>
<div className="flex flex-col gap-2">
<h2 className="text-sm font-semibold text-neutral-700 dark:text-neutral-300">
Appearance
</h2>
<h2 className="text-sm font-semibold">Appearance</h2>
<div className="flex flex-col px-3 divide-y divide-black/10 dark:divide-white/10 bg-black/5 dark:bg-white/5 rounded-xl">
<div className="flex items-start justify-between w-full gap-4 py-3">
<div className="flex-1">
@@ -139,9 +136,7 @@ function Screen() {
</div>
</div>
<div className="flex flex-col gap-2">
<h2 className="text-sm font-semibold text-neutral-700 dark:text-neutral-300">
Privacy & Performance
</h2>
<h2 className="text-sm font-semibold">Privacy & Performance</h2>
<div className="flex flex-col px-3 divide-y divide-black/10 dark:divide-white/10 bg-black/5 dark:bg-white/5 rounded-xl">
<Setting
name="Resize Service"

View File

@@ -0,0 +1,118 @@
import { commands } from "@/commands.gen";
import { isValidRelayUrl } from "@/commons";
import { Plus, X } from "@phosphor-icons/react";
import { createLazyFileRoute } from "@tanstack/react-router";
import { message } from "@tauri-apps/plugin-dialog";
import { useEffect, useState, useTransition } from "react";
export const Route = createLazyFileRoute("/settings/relays")({
component: Screen,
});
function Screen() {
const { allRelays } = Route.useRouteContext();
const [relays, setRelays] = useState<string[]>([]);
const [newRelay, setNewRelay] = useState<string>("");
const [isPending, startTransition] = useTransition();
const removeRelay = async (relay: string) => {
const res = await commands.removeRelay(relay);
if (res.status === "ok") {
return res.data;
} else {
throw new Error(res.error);
}
};
const addNewRelay = () => {
startTransition(async () => {
if (!isValidRelayUrl(newRelay)) {
await message("Relay URL is not valid", { kind: "error" });
return;
}
const res = await commands.connectRelay(newRelay);
if (res.status === "ok") {
setRelays((prev) => [...prev, newRelay]);
setNewRelay("");
} else {
await message(res.error, { title: "Relay", kind: "error" });
return;
}
});
};
useEffect(() => {
if (allRelays) setRelays(allRelays);
}, [allRelays]);
return (
<div className="w-full px-3 pb-3">
<div className="flex flex-col gap-6">
<div className="flex flex-col gap-2">
<div>
<h2 className="text-sm font-semibold">Connected Relays</h2>
<p className="text-sm text-neutral-500">
Learn more about Relays{" "}
<a
href="https://nostr.how/en/relays"
target="_blank"
rel="noreferrer"
className="text-blue-500 !underline"
>
here
</a>
</p>
</div>
<div className="flex flex-col px-3 divide-y divide-black/10 dark:divide-white/10 bg-black/5 dark:bg-white/5 rounded-xl">
<div className="flex items-center h-14">
<div className="flex items-center w-full gap-2 mb-0">
<input
value={newRelay}
onChange={(e) => setNewRelay(e.target.value)}
name="url"
placeholder="wss://..."
disabled={isPending}
spellCheck={false}
className="flex-1 px-3 bg-transparent rounded-lg h-9 border-neutral-400/50 placeholder:text-neutral-500 focus:border-blue-500 focus:ring-0 dark:border-neutral-800/50 dark:placeholder:text-neutral-400"
/>
<button
type="button"
disabled={isPending}
onClick={() => addNewRelay()}
className="inline-flex items-center justify-center w-16 px-2 text-sm font-medium text-white rounded-lg shrink-0 h-9 bg-black/20 dark:bg-white/20 hover:bg-blue-500 disabled:opacity-50"
>
<Plus className="size-5" />
</button>
</div>
</div>
{relays.map((relay) => (
<div
key={relay}
className="flex items-center justify-between h-11"
>
<div className="inline-flex items-center gap-2 text-sm font-medium truncate">
<span className="relative flex size-2">
<span className="absolute inline-flex w-full h-full bg-teal-400 rounded-full opacity-75 animate-ping" />
<span className="relative inline-flex bg-teal-500 rounded-full size-2" />
</span>
<span className="truncate">{relay}</span>
</div>
<button
type="button"
onClick={() => removeRelay(relay)}
className="inline-flex items-center justify-center rounded-md size-7 text-neutral-500 hover:bg-black/5 dark:hover:bg-white/5"
>
<X className="size-4" />
</button>
</div>
))}
</div>
</div>
</div>
</div>
);
}

View File

@@ -1,12 +1,12 @@
import { commands } from "@/commands.gen";
import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/settings/$id/relay")({
beforeLoad: async ({ params }) => {
const res = await commands.getRelays(params.id);
export const Route = createFileRoute("/settings/relays")({
beforeLoad: async () => {
const res = await commands.getAllRelays();
if (res.status === "ok") {
return { relayList: res.data };
return { allRelays: res.data };
} else {
throw new Error(res.error);
}

View File

@@ -0,0 +1,100 @@
import { createLazyFileRoute } from "@tanstack/react-router";
import { useEffect, useState, useTransition } from "react";
import * as Progress from "@radix-ui/react-progress";
import { Channel } from "@tauri-apps/api/core";
import { commands } from "@/commands.gen";
import { message } from "@tauri-apps/plugin-dialog";
import { Spinner } from "@/components";
export const Route = createLazyFileRoute("/settings/sync")({
component: Screen,
});
function Screen() {
const [channel, _setChannel] = useState<Channel<number>>(
() => new Channel<number>(),
);
const [progress, setProgress] = useState(0);
const [isPending, startTransition] = useTransition();
const runSync = () => {
startTransition(async () => {
const res = await commands.syncAll(channel);
if (res.status === "error") {
await message(res.error, { kind: "error" });
}
return;
});
};
useEffect(() => {
channel.onmessage = (message) => {
setProgress(message);
};
}, [channel]);
return (
<div className="w-full h-full px-3 pb-3">
<div className="h-full flex flex-col w-full gap-2">
<div>
<h2 className="text-sm font-semibold">Sync events with Negentropy</h2>
<p className="text-sm text-neutral-500">
Learn more about negentropy{" "}
<a
href="https://github.com/hoytech/strfry/blob/nextneg/docs/negentropy.md"
target="_blank"
rel="noreferrer"
className="text-blue-500 !underline"
>
here
</a>
</p>
</div>
<div className="text-sm flex flex-col gap-2">
<h5 className="font-semibold">Data will be sync:</h5>
<div className="w-full h-9 inline-flex items-center px-2 bg-black/5 dark:bg-white/5 rounded-lg text-neutral-700 dark:text-neutral-300">
Metadata of all public keys that found in database.
</div>
<div className="w-full h-9 inline-flex items-center px-2 bg-black/5 dark:bg-white/5 rounded-lg text-neutral-700 dark:text-neutral-300">
Contact list of all public keys that found in database.
</div>
<div className="w-full h-9 inline-flex items-center px-2 bg-black/5 dark:bg-white/5 rounded-lg text-neutral-700 dark:text-neutral-300">
Follow and interest sets of all public keys that found in database.
</div>
<div className="w-full h-9 inline-flex items-center px-2 bg-black/5 dark:bg-white/5 rounded-lg text-neutral-700 dark:text-neutral-300">
All notes and reposts of all public keys that found in database.
</div>
<div className="w-full h-9 inline-flex items-center px-2 bg-black/5 dark:bg-white/5 rounded-lg text-neutral-700 dark:text-neutral-300">
All comments all public keys that found in database.
</div>
</div>
<div className="relative mt-auto flex items-center gap-4 justify-between">
<div className="flex-1">
<Progress.Root
className="relative overflow-hidden bg-black/20 dark:bg-white/20 rounded-full w-full h-1"
style={{
transform: "translateZ(0)",
}}
value={progress}
>
<Progress.Indicator
className="bg-blue-500 size-full rounded-full transition-transform duration-[660ms] ease-[cubic-bezier(0.65, 0, 0.35, 1)]"
style={{ transform: `translateX(-${100 - progress}%)` }}
/>
</Progress.Root>
</div>
<button
type="button"
disabled={isPending}
onClick={() => runSync()}
className="shrink-0 w-20 h-8 rounded-lg inline-flex items-center justify-center bg-blue-500 hover:bg-blue-600 text-white text-sm font-semibold"
>
{isPending ? <Spinner className="size-4" /> : "Sync"}
</button>
</div>
</div>
</div>
);
}

View File

@@ -3,7 +3,7 @@ import { Button } from "@getalby/bitcoin-connect-react";
import { createLazyFileRoute } from "@tanstack/react-router";
import { useState } from "react";
export const Route = createLazyFileRoute("/settings/$id/wallet")({
export const Route = createLazyFileRoute("/settings/wallet")({
component: Screen,
});
@@ -33,9 +33,20 @@ function Screen() {
return (
<div className="w-full px-3 pb-3">
<div className="flex flex-col w-full gap-2">
<h2 className="text-sm font-semibold text-neutral-700 dark:text-neutral-300">
Wallet
</h2>
<div>
<h2 className="text-sm font-semibold">Bitcoin Wallet</h2>
<p className="text-sm text-neutral-500">
Learn more about Zap{" "}
<a
href="https://nostr.how/en/zaps"
target="_blank"
rel="noreferrer"
className="text-blue-500 !underline"
>
here
</a>
</p>
</div>
<div className="w-full h-44 flex items-center justify-center bg-black/5 dark:bg-white/5 rounded-xl">
<Button
onConnected={(provider) =>

View File

@@ -1,7 +1,7 @@
import { init } from "@getalby/bitcoin-connect-react";
import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/settings/$id/wallet")({
export const Route = createFileRoute("/settings/wallet")({
beforeLoad: async () => {
init({
appName: "Lume",

View File

@@ -121,7 +121,7 @@ export const LumeWindow = {
throw new Error(query.error);
}
},
openZap: async (id: string, account?: string) => {
openZap: async (id: string) => {
const wallet = await commands.loadWallet();
if (wallet.status === "ok") {
@@ -136,16 +136,14 @@ export const LumeWindow = {
hidden_title: true,
closable: true,
});
} else if (account) {
await LumeWindow.openSettings(account, "wallet");
} else {
await LumeWindow.openSettings("wallet");
}
},
openSettings: async (account: string, path?: string) => {
openSettings: async (path?: string) => {
const query = await commands.openWindow({
label: "settings",
url: path
? `/settings/${account}/${path}`
: `/settings/${account}/general`,
url: path ? `/settings/${path}` : "/settings/general",
title: "Settings",
width: 700,
height: 500,