update trending screen and add tauri shell plugin

This commit is contained in:
Ren Amamiya 2023-08-03 16:12:27 +07:00
parent 3432005ade
commit 2e47415160
12 changed files with 177 additions and 34 deletions

View File

@ -37,6 +37,7 @@
"@tauri-apps/plugin-notification": "github:tauri-apps/tauri-plugin-notification#v2",
"@tauri-apps/plugin-os": "github:tauri-apps/tauri-plugin-os#v2",
"@tauri-apps/plugin-process": "github:tauri-apps/tauri-plugin-process#v2",
"@tauri-apps/plugin-shell": "github:tauri-apps/tauri-plugin-shell#v2",
"@tauri-apps/plugin-sql": "github:tauri-apps/tauri-plugin-sql#v2",
"@tauri-apps/plugin-store": "github:tauri-apps/tauri-plugin-store#v2",
"@tauri-apps/plugin-stronghold": "github:tauri-apps/tauri-plugin-stronghold#v2",

View File

@ -61,6 +61,9 @@ dependencies:
'@tauri-apps/plugin-process':
specifier: github:tauri-apps/tauri-plugin-process#v2
version: github.com/tauri-apps/tauri-plugin-process/ed3f8f78ddecc72c926239f5a10ec6ce1b8c353e
'@tauri-apps/plugin-shell':
specifier: github:tauri-apps/tauri-plugin-shell#v2
version: github.com/tauri-apps/tauri-plugin-shell/ecff26b9c9c4084374dd12ddbe24fc77fe382990
'@tauri-apps/plugin-sql':
specifier: github:tauri-apps/tauri-plugin-sql#v2
version: github.com/tauri-apps/tauri-plugin-sql/0591e9f63e0f86be79c209f4bcb564ccce4bd05c
@ -7743,6 +7746,14 @@ packages:
'@tauri-apps/api': 2.0.0-alpha.5
dev: false
github.com/tauri-apps/tauri-plugin-shell/ecff26b9c9c4084374dd12ddbe24fc77fe382990:
resolution: {tarball: https://codeload.github.com/tauri-apps/tauri-plugin-shell/tar.gz/ecff26b9c9c4084374dd12ddbe24fc77fe382990}
name: '@tauri-apps/plugin-shell'
version: 2.0.0-alpha.0
dependencies:
'@tauri-apps/api': 2.0.0-alpha.5
dev: false
github.com/tauri-apps/tauri-plugin-sql/0591e9f63e0f86be79c209f4bcb564ccce4bd05c:
resolution: {tarball: https://codeload.github.com/tauri-apps/tauri-plugin-sql/tar.gz/0591e9f63e0f86be79c209f4bcb564ccce4bd05c}
name: '@tauri-apps/plugin-sql'

74
src-tauri/Cargo.lock generated
View File

@ -2382,6 +2382,15 @@ version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6"
[[package]]
name = "is-docker"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3"
dependencies = [
"once_cell",
]
[[package]]
name = "is-terminal"
version = "0.4.9"
@ -2393,6 +2402,16 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "is-wsl"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5"
dependencies = [
"is-docker",
"once_cell",
]
[[package]]
name = "itertools"
version = "0.10.5"
@ -2648,6 +2667,7 @@ dependencies = [
"tauri-plugin-notification",
"tauri-plugin-os",
"tauri-plugin-process",
"tauri-plugin-shell",
"tauri-plugin-single-instance",
"tauri-plugin-sql",
"tauri-plugin-store",
@ -3067,6 +3087,17 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "open"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a083c0c7e5e4a8ec4176346cf61f67ac674e8bfb059d9226e1c54a96b377c12"
dependencies = [
"is-wsl",
"libc",
"pathdiff",
]
[[package]]
name = "ordered-stream"
version = "0.2.0"
@ -3088,6 +3119,16 @@ dependencies = [
"winapi",
]
[[package]]
name = "os_pipe"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ae859aa07428ca9a929b936690f8b12dc5f11dd8c6992a18ca93919f28bc177"
dependencies = [
"libc",
"windows-sys 0.48.0",
]
[[package]]
name = "overload"
version = "0.1.1"
@ -3155,6 +3196,12 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "pathdiff"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
[[package]]
name = "pbkdf2"
version = "0.11.0"
@ -4166,6 +4213,16 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "shared_child"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0d94659ad3c2137fef23ae75b03d5241d633f8acded53d672decfa0e6e0caef"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "signal-hook"
version = "0.3.17"
@ -5022,6 +5079,23 @@ dependencies = [
"tauri",
]
[[package]]
name = "tauri-plugin-shell"
version = "2.0.0-alpha.0"
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v2#7f2e2dd5b8af2c8e7e224bed132e2b76da983818"
dependencies = [
"encoding_rs",
"log",
"open",
"os_pipe",
"regex",
"serde",
"serde_json",
"shared_child",
"tauri",
"thiserror",
]
[[package]]
name = "tauri-plugin-single-instance"
version = "2.0.0-alpha.0"

View File

@ -16,7 +16,10 @@ tauri-build = { version = "2.0.0-alpha.6", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "2.0.0-alpha.10", features = [ "macos-private-api", "system-tray"] }
tauri = { version = "2.0.0-alpha.10", features = [
"macos-private-api",
"system-tray",
] }
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-autostart = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-stronghold = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
@ -32,6 +35,7 @@ tauri-plugin-process = { git = "https://github.com/tauri-apps/plugins-workspace"
tauri-plugin-os = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-window = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-shell = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
window-shadows = { git = "https://github.com/tauri-apps/window-shadows", branch = "dev" }
window-vibrancy = { git = "https://github.com/tauri-apps/window-vibrancy", branch = "dev" }
sqlx-cli = { version = "0.7.0", default-features = false, features = [

View File

@ -138,6 +138,7 @@ fn main() {
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_window::init())
.plugin(tauri_plugin_store::Builder::default().build())
.plugin(tauri_plugin_shell::init())
.setup(|app| {
let window = app.get_window("main").unwrap();

View File

@ -95,16 +95,16 @@
"windows": [
{
"fullscreen": false,
"height": 800,
"hiddenTitle": true,
"minHeight": 720,
"minWidth": 1080,
"minHeight": 400,
"minWidth": 500,
"resizable": true,
"theme": "Dark",
"title": "Lume",
"titleBarStyle": "Overlay",
"transparent": true,
"width": 1080,
"width": 400,
"height": 500,
"center": true
}
],

View File

@ -11,14 +11,23 @@ import { compactNumber } from '@utils/number';
import { shortenKey } from '@utils/shortenKey';
export function Profile({ data }: { data: any }) {
const { status, data: userStats } = useQuery(['user-stats', data.pubkey], async () => {
const res = await fetch(`https://api.nostr.band/v0/stats/profile/${data.pubkey}`);
return res.json();
});
const { status: socialStatus, userFollows, follow, unfollow } = useSocial();
const { status, data: userStats } = useQuery(
['user-stats', data.pubkey],
async () => {
const res = await fetch(`https://api.nostr.band/v0/stats/profile/${data.pubkey}`);
return res.json();
},
{
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
staleTime: Infinity,
}
);
const embedProfile = data.profile ? JSON.parse(data.profile.content) : null;
const profile = embedProfile;
const { status: socialStatus, userFollows, follow, unfollow } = useSocial();
const [followed, setFollowed] = useState(false);
@ -50,12 +59,13 @@ export function Profile({ data }: { data: any }) {
}
}, [status]);
if (!profile)
if (!profile) {
return (
<div className="rounded-md bg-zinc-900 px-5 py-5">
<div className="rounded-xl bg-white/10 px-5 py-5">
<p>Can&apos;t fetch profile</p>
</div>
);
}
return (
<div className="rounded-xl bg-white/10 px-5 py-5">

View File

@ -1,17 +1,36 @@
import { useQuery } from '@tanstack/react-query';
import { fetch } from '@tauri-apps/plugin-http';
import { NoteKind_1 } from '@shared/notes';
import { NoteSkeleton } from '@shared/notes/skeleton';
import { TitleBar } from '@shared/titleBar';
import { LumeEvent } from '@utils/types';
interface Response {
ok: boolean;
data: {
notes: Array<{ event: LumeEvent }>;
};
}
export function TrendingNotes() {
const { status, data, error } = useQuery(['trending-notes'], async () => {
const res = await fetch('https://api.nostr.band/v0/trending/notes');
if (!res.ok) {
throw new Error('Error');
const { status, data, error } = useQuery(
['trending-notes'],
async () => {
const res: Response = await fetch('https://api.nostr.band/v0/trending/notes');
if (!res.ok) {
throw new Error('Error');
}
return res.data?.notes;
},
{
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
staleTime: Infinity,
}
return res.json();
});
);
return (
<div className="scrollbar-hide relative h-full w-[400px] shrink-0 overflow-y-auto bg-white/10 pb-20">
@ -20,14 +39,14 @@ export function TrendingNotes() {
{error && <p>Failed to fetch</p>}
{status === 'loading' ? (
<div className="px-3 py-1.5">
<div className="shadow-input rounded-md px-3 py-3">
<div className="rounded-xl bg-white/10 px-3 py-3">
<NoteSkeleton />
</div>
</div>
) : (
<div className="relative flex w-full flex-col">
{data.notes.map((item) => (
<NoteKind_1 key={item.id} event={item.event} skipMetadata={true} />
{data.map((item) => (
<NoteKind_1 key={item.event.id} event={item.event} skipMetadata={true} />
))}
</div>
)}

View File

@ -1,18 +1,35 @@
import { useQuery } from '@tanstack/react-query';
import { fetch } from '@tauri-apps/plugin-http';
import { Profile } from '@app/trending/components/profile';
import { NoteSkeleton } from '@shared/notes/skeleton';
import { TitleBar } from '@shared/titleBar';
interface Response {
ok: boolean;
data: {
profiles: Array<{ pubkey: string }>;
};
}
export function TrendingProfiles() {
const { status, data, error } = useQuery(['trending-profiles'], async () => {
const res = await fetch('https://api.nostr.band/v0/trending/profiles');
if (!res.ok) {
throw new Error('Error');
const { status, data, error } = useQuery(
['trending-profiles'],
async () => {
const res: Response = await fetch('https://api.nostr.band/v0/trending/profiles');
if (!res.ok) {
throw new Error('Error');
}
return res.data?.profiles;
},
{
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
staleTime: Infinity,
}
return res.json();
});
);
return (
<div className="scrollbar-hide relative h-full w-[400px] shrink-0 overflow-y-auto bg-white/10 pb-20">
@ -21,13 +38,13 @@ export function TrendingProfiles() {
{error && <p>Failed to fetch</p>}
{status === 'loading' ? (
<div className="px-3 py-1.5">
<div className="shadow-input rounded-md bg-zinc-900 px-3 py-3 shadow-black/20">
<div className="rounded-xl bg-white/10 px-3 py-3">
<NoteSkeleton />
</div>
</div>
) : (
<div className="relative flex w-full flex-col gap-3 px-3 pt-1.5">
{data.profiles.map((item) => (
{data.map((item) => (
<Profile key={item.pubkey} data={item} />
))}
</div>

View File

@ -88,7 +88,7 @@ export function ActiveAccount({ data }: { data: { pubkey: string; npub: string }
}, []);
if (status === 'loading') {
return <div className="h-9 w-9 animate-pulse rounded-md bg-zinc-800" />;
return <div className="h-9 w-9 animate-pulse rounded-md bg-white/50" />;
}
return (

View File

@ -1,7 +1,10 @@
import { LogicalSize, appWindow } from '@tauri-apps/plugin-window';
import { Outlet, ScrollRestoration } from 'react-router-dom';
import { Navigation } from '@shared/navigation';
await appWindow.setSize(new LogicalSize(1080, 800));
export function AppLayout() {
return (
<div className="flex h-screen w-screen">

View File

@ -66,10 +66,13 @@ export function NoteMetadata({ id }: { id: string }) {
if (status === 'loading') {
return (
<div className="mb-3 flex items-center gap-3">
<div className="mt-2h-6 w-11 shrink-0"></div>
<div className="mt-2 inline-flex h-6 items-center">
<LoaderIcon className="h-4 w-4 animate-spin text-white" />
<div>
<div className="absolute left-[18px] top-14 h-[calc(100%-6.4rem)] w-0.5 bg-gradient-to-t from-white/20 to-white/10" />
<div className="relative z-10 flex items-center gap-3 pb-3">
<div className="mt-2 h-6 w-11 shrink-0"></div>
<div className="mt-2 inline-flex h-6">
<LoaderIcon className="h-4 w-4 animate-spin text-white" />
</div>
</div>
</div>
);