feat: readd for you column

This commit is contained in:
2024-04-04 13:47:15 +07:00
parent 174b28f1a7
commit 999073f84c
34 changed files with 984 additions and 647 deletions

View File

@@ -4,6 +4,7 @@ import type {
Contact,
Event,
EventWithReplies,
Interests,
Keys,
Metadata,
Settings,
@@ -14,10 +15,10 @@ import { readFile } from "@tauri-apps/plugin-fs";
import { generateContentTags } from "@lume/utils";
export class Ark {
public accounts: Account[];
public windows: WebviewWindow[];
constructor() {
this.accounts = [];
this.windows = [];
}
public async get_all_accounts() {
@@ -29,8 +30,6 @@ export class Ark {
for (const item of cmd) {
accounts.push({ npub: item.replace(".npub", "") });
}
this.accounts = accounts;
return accounts;
}
} catch {
@@ -127,21 +126,24 @@ export class Ark {
}
public async get_events(
type: "local" | "global",
limit: number,
asOf?: number,
dedup?: boolean,
contacts?: string[],
global?: boolean,
) {
try {
let until: string = undefined;
if (asOf && asOf > 0) until = asOf.toString();
const dedup = true;
const seenIds = new Set<string>();
const dedupQueue = new Set<string>();
const nostrEvents: Event[] = await invoke(`get_${type}_events`, {
const nostrEvents: Event[] = await invoke("get_events", {
limit,
until,
contacts,
global,
});
if (dedup) {
@@ -156,7 +158,6 @@ export class Ark {
dedupQueue.add(event.id);
break;
}
seenIds.add(tag);
}
}
@@ -173,6 +174,51 @@ export class Ark {
}
}
public async get_events_from_interests(
hashtags: string[],
limit: number,
asOf?: number,
global?: boolean,
) {
let until: string = undefined;
if (asOf && asOf > 0) until = asOf.toString();
const dedup = true;
const seenIds = new Set<string>();
const dedupQueue = new Set<string>();
const nostrEvents: Event[] = await invoke("get_events_from_interests", {
hashtags,
limit,
until,
global,
});
if (dedup) {
for (const event of nostrEvents) {
const tags = event.tags
.filter((el) => el[0] === "e")
?.map((item) => item[1]);
if (tags.length) {
for (const tag of tags) {
if (seenIds.has(tag)) {
dedupQueue.add(event.id);
break;
}
seenIds.add(tag);
}
}
}
return nostrEvents
.filter((event) => !dedupQueue.has(event.id))
.sort((a, b) => b.created_at - a.created_at);
}
return nostrEvents.sort((a, b) => b.created_at - a.created_at);
}
public async publish(content: string, reply_to?: string, quote?: boolean) {
try {
const g = await generateContentTags(content);
@@ -548,89 +594,159 @@ export class Ark {
}
}
public async get_interest(id: string) {
try {
const cmd: string = await invoke("get_interest", { id });
if (!cmd) return null;
if (!cmd.length) return null;
const interests: Interests = JSON.parse(cmd);
return interests;
} catch {
return null;
}
}
public async set_interest(
words: string[],
users: string[],
hashtags: string[],
) {
try {
const interests: Interests = {
words: words ?? [],
users: users ?? [],
hashtags: hashtags ?? [],
};
const cmd: string = await invoke("set_interest", {
content: JSON.stringify(interests),
});
return cmd;
} catch {
return null;
}
}
public open_thread(id: string) {
return new WebviewWindow(`event-${id}`, {
title: "Thread",
url: `/events/${id}`,
minWidth: 500,
width: 500,
height: 800,
hiddenTitle: true,
titleBarStyle: "overlay",
center: false,
});
try {
const window = new WebviewWindow(`event-${id}`, {
title: "Thread",
url: `/events/${id}`,
minWidth: 500,
minHeight: 800,
width: 500,
height: 800,
hiddenTitle: true,
titleBarStyle: "overlay",
center: false,
});
this.windows.push(window);
} catch (e) {
throw new Error(String(e));
}
}
public open_profile(pubkey: string) {
return new WebviewWindow(`user-${pubkey}`, {
title: "Profile",
url: `/users/${pubkey}`,
minWidth: 500,
width: 500,
height: 800,
hiddenTitle: true,
titleBarStyle: "overlay",
});
try {
const window = new WebviewWindow(`user-${pubkey}`, {
title: "Profile",
url: `/users/${pubkey}`,
minWidth: 500,
minHeight: 800,
width: 500,
height: 800,
hiddenTitle: true,
titleBarStyle: "overlay",
});
this.windows.push(window);
} catch (e) {
throw new Error(String(e));
}
}
public open_editor(reply_to?: string, quote: boolean = false) {
let url: string;
try {
let url: string;
if (reply_to) {
url = `/editor?reply_to=${reply_to}&quote=${quote}`;
} else {
url = "/editor";
if (reply_to) {
url = `/editor?reply_to=${reply_to}&quote=${quote}`;
} else {
url = "/editor";
}
const window = new WebviewWindow(`editor-${reply_to ? reply_to : 0}`, {
title: "Editor",
url,
minWidth: 500,
minHeight: 400,
width: 600,
height: 400,
hiddenTitle: true,
titleBarStyle: "overlay",
});
this.windows.push(window);
} catch (e) {
throw new Error(String(e));
}
return new WebviewWindow("editor", {
title: "Editor",
url,
minWidth: 500,
minHeight: 400,
width: 600,
height: 400,
hiddenTitle: true,
titleBarStyle: "overlay",
fileDropEnabled: true,
});
}
public open_nwc() {
return new WebviewWindow("nwc", {
title: "Nostr Wallet Connect",
url: "/nwc",
minWidth: 400,
width: 400,
height: 600,
hiddenTitle: true,
titleBarStyle: "overlay",
fileDropEnabled: true,
});
try {
const window = new WebviewWindow("nwc", {
title: "Nostr Wallet Connect",
url: "/nwc",
minWidth: 400,
minHeight: 600,
width: 400,
height: 600,
hiddenTitle: true,
titleBarStyle: "overlay",
});
this.windows.push(window);
} catch (e) {
throw new Error(String(e));
}
}
public open_zap(id: string, pubkey: string, account: string) {
return new WebviewWindow(`zap-${id}`, {
title: "Nostr Wallet Connect",
url: `/zap/${id}?pubkey=${pubkey}&account=${account}`,
minWidth: 400,
width: 400,
height: 500,
hiddenTitle: true,
titleBarStyle: "overlay",
fileDropEnabled: true,
});
try {
const window = new WebviewWindow(`zap-${id}`, {
title: "Zap",
url: `/zap/${id}?pubkey=${pubkey}&account=${account}`,
minWidth: 400,
minHeight: 500,
width: 400,
height: 500,
hiddenTitle: true,
titleBarStyle: "overlay",
});
this.windows.push(window);
} catch (e) {
throw new Error(String(e));
}
}
public open_settings() {
return new WebviewWindow("settings", {
title: "Settings",
url: "/settings",
minWidth: 600,
width: 800,
height: 500,
hiddenTitle: true,
titleBarStyle: "overlay",
fileDropEnabled: true,
});
try {
const window = new WebviewWindow("settings", {
title: "Settings",
url: "/settings",
minWidth: 600,
minHeight: 500,
width: 800,
height: 500,
hiddenTitle: true,
titleBarStyle: "overlay",
});
this.windows.push(window);
} catch (e) {
throw new Error(String(e));
}
}
}

View File

@@ -9,7 +9,12 @@ export function ColumnContent({
className?: string;
}) {
return (
<div className={cn("flex-1 overflow-y-auto overflow-x-hidden", className)}>
<div
className={cn(
"flex-1 overflow-y-auto overflow-x-hidden scrollbar-none",
className,
)}
>
{children}
</div>
);

View File

@@ -34,6 +34,7 @@ export function NoteUser({ className }: { className?: string }) {
<HoverCard.Content
className="w-[300px] rounded-xl bg-black p-3 data-[side=bottom]:animate-slideUpAndFade data-[state=open]:transition-all dark:bg-white dark:shadow-none"
sideOffset={5}
side="right"
>
<div className="flex flex-col gap-2">
<User.Avatar className="size-11 rounded-lg object-cover" />

View File

@@ -22,7 +22,7 @@
"@lume/tsconfig": "workspace:^",
"@lume/types": "workspace:^",
"@types/react": "^18.2.74",
"@types/react-dom": "^18.2.23",
"@types/react-dom": "^18.2.24",
"tailwind-merge": "^2.2.2",
"typescript": "^5.4.3"
}