mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-19 11:43:30 +00:00
refactor
This commit is contained in:
parent
e2491e47c0
commit
6e1fa10402
@ -16,7 +16,7 @@ tauri-build = { version = "1.2", features = [] }
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
tauri = { version = "1.2", features = ["clipboard-read-text", "clipboard-write-text", "dialog-open", "fs-read-dir", "fs-read-file", "http-all", "http-multipart", "notification-all", "os-all", "shell-open", "system-tray", "updater", "window-close", "window-start-dragging"] }
|
tauri = { version = "1.2", features = ["clipboard-read-text", "clipboard-write-text", "dialog-open", "fs-read-dir", "fs-read-file", "http-all", "http-multipart", "notification-all", "os-all", "process-relaunch", "shell-open", "system-tray", "updater", "window-close", "window-start-dragging"] }
|
||||||
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
|
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
|
||||||
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
|
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
|
||||||
sqlx-cli = {version = "0.6.3", default-features = false, features = ["sqlite"] }
|
sqlx-cli = {version = "0.6.3", default-features = false, features = ["sqlite"] }
|
||||||
|
@ -60,6 +60,12 @@
|
|||||||
"window": {
|
"window": {
|
||||||
"startDragging": true,
|
"startDragging": true,
|
||||||
"close": true
|
"close": true
|
||||||
|
},
|
||||||
|
"process": {
|
||||||
|
"all": false,
|
||||||
|
"exit": false,
|
||||||
|
"relaunch": true,
|
||||||
|
"relaunchDangerousAllowSymlinkMacos": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bundle": {
|
"bundle": {
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import { EyeOffIcon, EyeOnIcon } from "@shared/icons";
|
import { EyeOffIcon, EyeOnIcon } from "@shared/icons";
|
||||||
import { createAccount } from "@utils/storage";
|
import { useActiveAccount } from "@stores/accounts";
|
||||||
import { generatePrivateKey, getPublicKey, nip19 } from "nostr-tools";
|
import { generatePrivateKey, getPublicKey, nip19 } from "nostr-tools";
|
||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { navigate } from "vite-plugin-ssr/client/router";
|
import { navigate } from "vite-plugin-ssr/client/router";
|
||||||
|
|
||||||
export function Page() {
|
export function Page() {
|
||||||
|
const createAccount = useActiveAccount((state: any) => state.create);
|
||||||
|
|
||||||
const [type, setType] = useState("password");
|
const [type, setType] = useState("password");
|
||||||
const privkey = useMemo(() => generatePrivateKey(), []);
|
const privkey = useMemo(() => generatePrivateKey(), []);
|
||||||
|
|
||||||
@ -22,11 +24,8 @@ export function Page() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
const account = await createAccount(npub, pubkey, privkey, null, 1);
|
createAccount(npub, pubkey, privkey, null, 1);
|
||||||
|
navigate("/app/auth/create/step-2");
|
||||||
if (account) {
|
|
||||||
navigate("/app/auth/create/step-2");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -10,11 +10,8 @@ import { navigate } from "vite-plugin-ssr/client/router";
|
|||||||
|
|
||||||
export function Page() {
|
export function Page() {
|
||||||
const pool: any = useContext(RelayContext);
|
const pool: any = useContext(RelayContext);
|
||||||
|
const account = useActiveAccount((state: any) => state.account);
|
||||||
|
|
||||||
const [account, fetchAccount] = useActiveAccount((state: any) => [
|
|
||||||
state.account,
|
|
||||||
state.fetch,
|
|
||||||
]);
|
|
||||||
const [image, setImage] = useState(DEFAULT_AVATAR);
|
const [image, setImage] = useState(DEFAULT_AVATAR);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
@ -52,10 +49,6 @@ export function Page() {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchAccount();
|
|
||||||
}, [fetchAccount]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setValue("picture", image);
|
setValue("picture", image);
|
||||||
}, [setValue, image]);
|
}, [setValue, image]);
|
||||||
|
@ -3,7 +3,6 @@ import { CheckCircleIcon } from "@shared/icons";
|
|||||||
import { RelayContext } from "@shared/relayProvider";
|
import { RelayContext } from "@shared/relayProvider";
|
||||||
import { useActiveAccount } from "@stores/accounts";
|
import { useActiveAccount } from "@stores/accounts";
|
||||||
import { WRITEONLY_RELAYS } from "@stores/constants";
|
import { WRITEONLY_RELAYS } from "@stores/constants";
|
||||||
import { updateAccount } from "@utils/storage";
|
|
||||||
import { arrayToNIP02 } from "@utils/transform";
|
import { arrayToNIP02 } from "@utils/transform";
|
||||||
import { getEventHash, getSignature } from "nostr-tools";
|
import { getEventHash, getSignature } from "nostr-tools";
|
||||||
import { useContext, useState } from "react";
|
import { useContext, useState } from "react";
|
||||||
@ -130,11 +129,8 @@ export function Page() {
|
|||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
// update account follows in database
|
// update account follows
|
||||||
updateAccount("follows", follows, account.pubkey);
|
updateFollows(follows);
|
||||||
|
|
||||||
// update account follows in state
|
|
||||||
updateFollows(JSON.stringify(follows));
|
|
||||||
|
|
||||||
const tags = arrayToNIP02(follows);
|
const tags = arrayToNIP02(follows);
|
||||||
|
|
||||||
@ -155,7 +151,7 @@ export function Page() {
|
|||||||
// redirect to step 3
|
// redirect to step 3
|
||||||
setTimeout(
|
setTimeout(
|
||||||
() =>
|
() =>
|
||||||
navigate("/app/prefetch", {
|
navigate("/", {
|
||||||
overwriteLastHistoryEntry: true,
|
overwriteLastHistoryEntry: true,
|
||||||
}),
|
}),
|
||||||
2000,
|
2000,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { createAccount } from "@utils/storage";
|
import { useActiveAccount } from "@stores/accounts";
|
||||||
import { getPublicKey, nip19 } from "nostr-tools";
|
import { getPublicKey, nip19 } from "nostr-tools";
|
||||||
import { Resolver, useForm } from "react-hook-form";
|
import { Resolver, useForm } from "react-hook-form";
|
||||||
import { navigate } from "vite-plugin-ssr/client/router";
|
import { navigate } from "vite-plugin-ssr/client/router";
|
||||||
@ -22,6 +22,7 @@ const resolver: Resolver<FormValues> = async (values) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function Page() {
|
export function Page() {
|
||||||
|
const createAccount = useActiveAccount((state: any) => state.create);
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
setError,
|
setError,
|
||||||
@ -41,11 +42,8 @@ export function Page() {
|
|||||||
const pubkey = getPublicKey(privkey);
|
const pubkey = getPublicKey(privkey);
|
||||||
const npub = nip19.npubEncode(pubkey);
|
const npub = nip19.npubEncode(pubkey);
|
||||||
|
|
||||||
const account = await createAccount(npub, pubkey, privkey, null, 1);
|
createAccount(npub, pubkey, privkey, null, 1);
|
||||||
|
navigate("/app/auth/import/step-2");
|
||||||
if (account) {
|
|
||||||
navigate("/app/auth/import/step-2");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError("key", {
|
setError("key", {
|
||||||
|
@ -1,31 +1,31 @@
|
|||||||
import { User } from "@app/auth/components/user";
|
import { User } from "@app/auth/components/user";
|
||||||
import { RelayContext } from "@shared/relayProvider";
|
import { RelayContext } from "@shared/relayProvider";
|
||||||
import { useActiveAccount } from "@stores/accounts";
|
import { useActiveAccount } from "@stores/accounts";
|
||||||
import { READONLY_RELAYS } from "@stores/constants";
|
import { METADATA_RELAY } from "@stores/constants";
|
||||||
import { updateAccount } from "@utils/storage";
|
|
||||||
import { nip02ToArray } from "@utils/transform";
|
import { nip02ToArray } from "@utils/transform";
|
||||||
import { useContext, useEffect, useState } from "react";
|
import { useContext, useState } from "react";
|
||||||
import useSWRSubscription from "swr/subscription";
|
import useSWRSubscription from "swr/subscription";
|
||||||
import { navigate } from "vite-plugin-ssr/client/router";
|
import { navigate } from "vite-plugin-ssr/client/router";
|
||||||
|
|
||||||
export function Page() {
|
export function Page() {
|
||||||
const pool: any = useContext(RelayContext);
|
const pool: any = useContext(RelayContext);
|
||||||
|
|
||||||
const [account, fetchAccount, updateFollows] = useActiveAccount(
|
const [account, updateFollows] = useActiveAccount((state: any) => [
|
||||||
(state: any) => [state.account, state.fetch, state.updateFollows],
|
state.account,
|
||||||
);
|
state.updateFollows,
|
||||||
|
]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [follows, setFollows] = useState([]);
|
const [follows, setFollows] = useState(null);
|
||||||
|
|
||||||
useSWRSubscription(account ? account.pubkey : null, (key: string) => {
|
useSWRSubscription(account ? ["follows", account.pubkey] : null, () => {
|
||||||
const unsubscribe = pool.subscribe(
|
const unsubscribe = pool.subscribe(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
kinds: [3],
|
kinds: [3],
|
||||||
authors: [key],
|
authors: [account.pubkey],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
READONLY_RELAYS,
|
METADATA_RELAY,
|
||||||
(event: any) => {
|
(event: any) => {
|
||||||
setFollows(event.tags);
|
setFollows(event.tags);
|
||||||
},
|
},
|
||||||
@ -43,23 +43,13 @@ export function Page() {
|
|||||||
// follows as list
|
// follows as list
|
||||||
const followsList = nip02ToArray(follows);
|
const followsList = nip02ToArray(follows);
|
||||||
|
|
||||||
// update account follows in database
|
|
||||||
updateAccount("follows", followsList, account.pubkey);
|
|
||||||
|
|
||||||
// update account follows in store
|
// update account follows in store
|
||||||
updateFollows(JSON.stringify(followsList));
|
updateFollows(followsList);
|
||||||
|
|
||||||
// redirect to home
|
// redirect to home
|
||||||
setTimeout(
|
setTimeout(() => navigate("/", { overwriteLastHistoryEntry: true }), 2000);
|
||||||
() => navigate("/app/prefetch", { overwriteLastHistoryEntry: true }),
|
|
||||||
2000,
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchAccount();
|
|
||||||
}, [fetchAccount]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-full w-full items-center justify-center">
|
<div className="flex h-full w-full items-center justify-center">
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="mx-auto w-full max-w-md">
|
||||||
|
@ -6,19 +6,23 @@ export function Page() {
|
|||||||
const fetchLastLogin = useActiveAccount((state: any) => state.fetchLastLogin);
|
const fetchLastLogin = useActiveAccount((state: any) => state.fetchLastLogin);
|
||||||
const fetchAccount = useActiveAccount((state: any) => state.fetch);
|
const fetchAccount = useActiveAccount((state: any) => state.fetch);
|
||||||
const account = useActiveAccount((state: any) => state.account);
|
const account = useActiveAccount((state: any) => state.account);
|
||||||
|
const lastLogin = useActiveAccount((state: any) => state.lastLogin);
|
||||||
if (!account && typeof window !== "undefined") {
|
|
||||||
navigate("/app/auth", { overwriteLastHistoryEntry: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (account && typeof window !== "undefined") {
|
|
||||||
navigate("/app/prefetch", { overwriteLastHistoryEntry: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchAccount();
|
if (!account) {
|
||||||
fetchLastLogin();
|
navigate("/app/auth", { overwriteLastHistoryEntry: true });
|
||||||
}, [fetchAccount, fetchLastLogin]);
|
}
|
||||||
|
|
||||||
|
if (account) {
|
||||||
|
navigate("/app/prefetch", { overwriteLastHistoryEntry: true });
|
||||||
|
}
|
||||||
|
if (account === null) {
|
||||||
|
fetchAccount();
|
||||||
|
}
|
||||||
|
if (lastLogin === null) {
|
||||||
|
fetchLastLogin();
|
||||||
|
}
|
||||||
|
}, [fetchAccount, fetchLastLogin, account, lastLogin]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-screen w-screen bg-zinc-50 text-zinc-900 dark:bg-black dark:text-white" />
|
<div className="h-screen w-screen bg-zinc-50 text-zinc-900 dark:bg-black dark:text-white" />
|
||||||
|
@ -11,7 +11,6 @@ export function NoteReplyForm({ id }: { id: string }) {
|
|||||||
const pool: any = useContext(RelayContext);
|
const pool: any = useContext(RelayContext);
|
||||||
const account = useActiveAccount((state: any) => state.account);
|
const account = useActiveAccount((state: any) => state.account);
|
||||||
|
|
||||||
const { user } = useProfile(account.pubkey);
|
|
||||||
const [value, setValue] = useState("");
|
const [value, setValue] = useState("");
|
||||||
|
|
||||||
const submitEvent = () => {
|
const submitEvent = () => {
|
||||||
@ -35,15 +34,6 @@ export function NoteReplyForm({ id }: { id: string }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex gap-2.5 py-4">
|
<div className="flex gap-2.5 py-4">
|
||||||
<div>
|
|
||||||
<div className="relative h-9 w-9 shrink-0 overflow-hidden rounded-md">
|
|
||||||
<Image
|
|
||||||
src={user?.picture}
|
|
||||||
alt={id}
|
|
||||||
className="h-9 w-9 rounded-md object-cover"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="relative h-24 w-full flex-1 overflow-hidden before:pointer-events-none before:absolute before:-inset-1 before:rounded-[11px] before:border before:border-fuchsia-500 before:opacity-0 before:ring-2 before:ring-fuchsia-500/20 before:transition after:pointer-events-none after:absolute after:inset-px after:rounded-[7px] after:shadow-highlight after:shadow-white/5 after:transition focus-within:before:opacity-100 focus-within:after:shadow-fuchsia-500/100 dark:focus-within:after:shadow-fuchsia-500/20">
|
<div className="relative h-24 w-full flex-1 overflow-hidden before:pointer-events-none before:absolute before:-inset-1 before:rounded-[11px] before:border before:border-fuchsia-500 before:opacity-0 before:ring-2 before:ring-fuchsia-500/20 before:transition after:pointer-events-none after:absolute after:inset-px after:rounded-[7px] after:shadow-highlight after:shadow-white/5 after:transition focus-within:before:opacity-100 focus-within:after:shadow-fuchsia-500/100 dark:focus-within:after:shadow-fuchsia-500/20">
|
||||||
<div>
|
<div>
|
||||||
<textarea
|
<textarea
|
||||||
|
@ -19,6 +19,15 @@ if (typeof window !== "undefined") {
|
|||||||
totalNotes = await countTotalNotes();
|
totalNotes = await countTotalNotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isJSON(str: string) {
|
||||||
|
try {
|
||||||
|
JSON.parse(str);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
export function Page() {
|
export function Page() {
|
||||||
const pool: any = useContext(RelayContext);
|
const pool: any = useContext(RelayContext);
|
||||||
const [account, lastLogin] = useActiveAccount((state: any) => [
|
const [account, lastLogin] = useActiveAccount((state: any) => [
|
||||||
@ -73,10 +82,17 @@ export function Page() {
|
|||||||
since: lastLogin,
|
since: lastLogin,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// long post
|
||||||
|
query.push({
|
||||||
|
kinds: [30023],
|
||||||
|
since: lastLogin,
|
||||||
|
});
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}, [account]);
|
}, [account]);
|
||||||
|
|
||||||
useSWRSubscription(account ? "prefetch" : null, () => {
|
useSWRSubscription(account ? "prefetch" : null, () => {
|
||||||
|
console.log("data prefetching... ", account.pubkey);
|
||||||
const query = getQuery();
|
const query = getQuery();
|
||||||
const unsubscribe = pool.subscribe(
|
const unsubscribe = pool.subscribe(
|
||||||
query,
|
query,
|
||||||
@ -148,6 +164,7 @@ export function Page() {
|
|||||||
addToBlacklist(account.id, event.tags[0][1], 44, 1);
|
addToBlacklist(account.id, event.tags[0][1], 44, 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
// file metadata
|
||||||
case 1063:
|
case 1063:
|
||||||
createNote(
|
createNote(
|
||||||
event.id,
|
event.id,
|
||||||
@ -157,9 +174,26 @@ export function Page() {
|
|||||||
event.tags,
|
event.tags,
|
||||||
event.content,
|
event.content,
|
||||||
event.created_at,
|
event.created_at,
|
||||||
"",
|
event.id,
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
// long post
|
||||||
|
case 30023: {
|
||||||
|
const verifyMetadata = isJSON(event.tags);
|
||||||
|
if (verifyMetadata) {
|
||||||
|
createNote(
|
||||||
|
event.id,
|
||||||
|
account.id,
|
||||||
|
event.pubkey,
|
||||||
|
event.kind,
|
||||||
|
event.tags,
|
||||||
|
event.content,
|
||||||
|
event.created_at,
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -168,7 +202,10 @@ export function Page() {
|
|||||||
() => {
|
() => {
|
||||||
eose.current += 1;
|
eose.current += 1;
|
||||||
if (eose.current === READONLY_RELAYS.length) {
|
if (eose.current === READONLY_RELAYS.length) {
|
||||||
navigate("/app/space", { overwriteLastHistoryEntry: true });
|
setTimeout(
|
||||||
|
() => navigate("/app/space", { overwriteLastHistoryEntry: true }),
|
||||||
|
2000,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
addBlockToDB,
|
addBlockToDB,
|
||||||
|
createAccount,
|
||||||
getActiveAccount,
|
getActiveAccount,
|
||||||
getBlocks,
|
getBlocks,
|
||||||
getLastLogin,
|
getLastLogin,
|
||||||
removeBlockFromDB,
|
removeBlockFromDB,
|
||||||
|
updateAccount,
|
||||||
} from "@utils/storage";
|
} from "@utils/storage";
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { createJSONStorage, persist } from "zustand/middleware";
|
import { createJSONStorage, persist } from "zustand/middleware";
|
||||||
@ -15,7 +17,16 @@ export const useActiveAccount = create(
|
|||||||
(set: any, get: any) => ({
|
(set: any, get: any) => ({
|
||||||
account: null,
|
account: null,
|
||||||
blocks: null,
|
blocks: null,
|
||||||
lastLogin: 0,
|
lastLogin: null,
|
||||||
|
create: async (npub: string, pubkey: string, privkey: string) => {
|
||||||
|
const response = await createAccount(npub, pubkey, privkey, null, 1);
|
||||||
|
if (response) {
|
||||||
|
const activeAccount = await getActiveAccount();
|
||||||
|
set({
|
||||||
|
account: activeAccount,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
fetch: async () => {
|
fetch: async () => {
|
||||||
const response = await getActiveAccount();
|
const response = await getActiveAccount();
|
||||||
set({ account: response });
|
set({ account: response });
|
||||||
@ -59,8 +70,12 @@ export const useActiveAccount = create(
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
updateFollows: (list: any) => {
|
updateFollows: (list: any) => {
|
||||||
|
const account = get().account;
|
||||||
|
// update db
|
||||||
|
updateAccount("follows", list, account.pubkey);
|
||||||
|
// update state
|
||||||
set((state: any) => ({
|
set((state: any) => ({
|
||||||
account: { ...state.account, follows: list },
|
account: { ...state.account, follows: JSON.stringify(list) },
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
@ -225,7 +225,7 @@ export async function createNote(
|
|||||||
) {
|
) {
|
||||||
const db = await connect();
|
const db = await connect();
|
||||||
return await db.execute(
|
return await db.execute(
|
||||||
"INSERT OR IGNORE INTO notes (event_id, account_id, pubkey, kind, tags, content, created_at, parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?);",
|
"INSERT INTO notes (event_id, account_id, pubkey, kind, tags, content, created_at, parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?);",
|
||||||
[event_id, account_id, pubkey, kind, tags, content, created_at, parent_id],
|
[event_id, account_id, pubkey, kind, tags, content, created_at, parent_id],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user