mirror of
https://github.com/lumehq/lume.git
synced 2025-03-28 18:52:33 +01:00
fixed errors
This commit is contained in:
parent
0d94313b45
commit
5da94e091f
@ -37,6 +37,11 @@ struct GetFollowData {
|
|||||||
account_id: i32,
|
account_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Type)]
|
||||||
|
struct GetFollowPubkeyData {
|
||||||
|
pubkey: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Type)]
|
#[derive(Deserialize, Type)]
|
||||||
struct CreateFollowData {
|
struct CreateFollowData {
|
||||||
pubkey: String,
|
pubkey: String,
|
||||||
@ -105,6 +110,19 @@ async fn get_follows(db: DbState<'_>, data: GetFollowData) -> Result<Vec<follow:
|
|||||||
.map_err(|_| ())
|
.map_err(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
#[specta::specta]
|
||||||
|
async fn get_follow_by_pubkey(
|
||||||
|
db: DbState<'_>,
|
||||||
|
data: GetFollowPubkeyData,
|
||||||
|
) -> Result<Option<follow::Data>, ()> {
|
||||||
|
db.follow()
|
||||||
|
.find_first(vec![follow::pubkey::equals(data.pubkey)])
|
||||||
|
.exec()
|
||||||
|
.await
|
||||||
|
.map_err(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
#[specta::specta]
|
#[specta::specta]
|
||||||
async fn create_follow(db: DbState<'_>, data: CreateFollowData) -> Result<follow::Data, ()> {
|
async fn create_follow(db: DbState<'_>, data: CreateFollowData) -> Result<follow::Data, ()> {
|
||||||
@ -198,6 +216,7 @@ async fn main() {
|
|||||||
get_accounts,
|
get_accounts,
|
||||||
create_account,
|
create_account,
|
||||||
get_follows,
|
get_follows,
|
||||||
|
get_follow_by_pubkey,
|
||||||
create_follow,
|
create_follow,
|
||||||
create_note,
|
create_note,
|
||||||
get_notes,
|
get_notes,
|
||||||
@ -238,6 +257,7 @@ async fn main() {
|
|||||||
get_accounts,
|
get_accounts,
|
||||||
create_account,
|
create_account,
|
||||||
get_follows,
|
get_follows,
|
||||||
|
get_follow_by_pubkey,
|
||||||
create_follow,
|
create_follow,
|
||||||
create_note,
|
create_note,
|
||||||
get_notes,
|
get_notes,
|
||||||
|
@ -45,7 +45,7 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
|
|||||||
parent_id: parentID,
|
parent_id: parentID,
|
||||||
parent_comment_id: '',
|
parent_comment_id: '',
|
||||||
created_at: event.created_at,
|
created_at: event.created_at,
|
||||||
account_id: activeAccount.pubkey,
|
account_id: activeAccount.id,
|
||||||
}).catch(console.error);
|
}).catch(console.error);
|
||||||
},
|
},
|
||||||
undefined,
|
undefined,
|
||||||
|
@ -41,7 +41,7 @@ export const NoteRepost = memo(function NoteRepost({ id }: { id: string }) {
|
|||||||
parent_id: parentID,
|
parent_id: parentID,
|
||||||
parent_comment_id: '',
|
parent_comment_id: '',
|
||||||
created_at: event.created_at,
|
created_at: event.created_at,
|
||||||
account_id: activeAccount.pubkey,
|
account_id: activeAccount.id,
|
||||||
}).catch(console.error);
|
}).catch(console.error);
|
||||||
},
|
},
|
||||||
undefined,
|
undefined,
|
||||||
|
@ -1,23 +1,20 @@
|
|||||||
import { ImageWithFallback } from '@components/imageWithFallback';
|
import { ImageWithFallback } from '@components/imageWithFallback';
|
||||||
import { RelayContext } from '@components/relaysProvider';
|
|
||||||
|
|
||||||
import { DEFAULT_AVATAR } from '@stores/constants';
|
import { DEFAULT_AVATAR } from '@stores/constants';
|
||||||
|
|
||||||
import { truncate } from '@utils/truncate';
|
import { truncate } from '@utils/truncate';
|
||||||
|
|
||||||
import { DotsHorizontalIcon } from '@radix-ui/react-icons';
|
import { DotsHorizontalIcon } from '@radix-ui/react-icons';
|
||||||
|
import { fetch } from '@tauri-apps/api/http';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import relativeTime from 'dayjs/plugin/relativeTime';
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { Author } from 'nostr-relaypool';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { memo, useContext, useEffect, useState } from 'react';
|
|
||||||
|
|
||||||
dayjs.extend(relativeTime);
|
dayjs.extend(relativeTime);
|
||||||
|
|
||||||
export const UserExtend = memo(function UserExtend({ pubkey, time }: { pubkey: string; time: any }) {
|
export const UserExtend = ({ pubkey, time }: { pubkey: string; time: number }) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [pool, relays]: any = useContext(RelayContext);
|
|
||||||
|
|
||||||
const [profile, setProfile] = useState(null);
|
const [profile, setProfile] = useState(null);
|
||||||
|
|
||||||
const openUserPage = (e) => {
|
const openUserPage = (e) => {
|
||||||
@ -25,10 +22,36 @@ export const UserExtend = memo(function UserExtend({ pubkey, time }: { pubkey: s
|
|||||||
router.push(`/users/${pubkey}`);
|
router.push(`/users/${pubkey}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fetchMetadata = useCallback(async (pubkey: string) => {
|
||||||
|
const res = await fetch(`https://rbr.bio/${pubkey}/metadata.json`, {
|
||||||
|
method: 'GET',
|
||||||
|
timeout: 5,
|
||||||
|
});
|
||||||
|
return res.data;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const getCachedMetadata = useCallback(async () => {
|
||||||
|
const { getFollowByPubkey } = await import('@utils/bindings');
|
||||||
|
getFollowByPubkey({ pubkey: pubkey })
|
||||||
|
.then((res) => {
|
||||||
|
if (res) {
|
||||||
|
const metadata = JSON.parse(res.metadata);
|
||||||
|
setProfile(metadata);
|
||||||
|
} else {
|
||||||
|
fetchMetadata(pubkey).then((res: any) => {
|
||||||
|
if (res.content) {
|
||||||
|
const metadata = JSON.parse(res.content);
|
||||||
|
setProfile(metadata);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
}, [fetchMetadata, pubkey]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const user = new Author(pool, relays, pubkey);
|
getCachedMetadata().catch(console.error);
|
||||||
user.metaData((res) => setProfile(JSON.parse(res.content)), 0);
|
}, [getCachedMetadata]);
|
||||||
}, [pool, relays, pubkey]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="group flex items-start gap-2">
|
<div className="group flex items-start gap-2">
|
||||||
@ -61,4 +84,4 @@ export const UserExtend = memo(function UserExtend({ pubkey, time }: { pubkey: s
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
};
|
||||||
|
@ -1,22 +1,29 @@
|
|||||||
import { ImageWithFallback } from '@components/imageWithFallback';
|
import { ImageWithFallback } from '@components/imageWithFallback';
|
||||||
import { RelayContext } from '@components/relaysProvider';
|
|
||||||
|
|
||||||
import { DEFAULT_AVATAR } from '@stores/constants';
|
import { DEFAULT_AVATAR } from '@stores/constants';
|
||||||
|
|
||||||
import { truncate } from '@utils/truncate';
|
import { truncate } from '@utils/truncate';
|
||||||
|
|
||||||
import { Author } from 'nostr-relaypool';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { memo, useContext, useEffect, useMemo, useState } from 'react';
|
|
||||||
|
|
||||||
export const UserFollow = memo(function UserFollow({ pubkey }: { pubkey: string }) {
|
|
||||||
const [pool, relays]: any = useContext(RelayContext);
|
|
||||||
|
|
||||||
|
export const UserFollow = ({ pubkey }: { pubkey: string }) => {
|
||||||
const [profile, setProfile] = useState(null);
|
const [profile, setProfile] = useState(null);
|
||||||
const user = useMemo(() => new Author(pool, relays, pubkey), [pubkey, pool, relays]);
|
|
||||||
|
const getCachedMetadata = useCallback(async () => {
|
||||||
|
const { getFollowByPubkey } = await import('@utils/bindings');
|
||||||
|
getFollowByPubkey({ pubkey: pubkey })
|
||||||
|
.then((res) => {
|
||||||
|
if (res) {
|
||||||
|
const metadata = JSON.parse(res.metadata);
|
||||||
|
setProfile(metadata);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
}, [pubkey]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
user.metaData((res) => setProfile(JSON.parse(res.content)), 0);
|
getCachedMetadata().catch(console.error);
|
||||||
}, [user]);
|
}, [getCachedMetadata]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
@ -36,4 +43,4 @@ export const UserFollow = memo(function UserFollow({ pubkey }: { pubkey: string
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
};
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { ImageWithFallback } from '@components/imageWithFallback';
|
import { ImageWithFallback } from '@components/imageWithFallback';
|
||||||
import { RelayContext } from '@components/relaysProvider';
|
|
||||||
|
|
||||||
import { DEFAULT_AVATAR } from '@stores/constants';
|
import { DEFAULT_AVATAR } from '@stores/constants';
|
||||||
|
|
||||||
@ -8,19 +7,28 @@ import { truncate } from '@utils/truncate';
|
|||||||
import { DotsHorizontalIcon } from '@radix-ui/react-icons';
|
import { DotsHorizontalIcon } from '@radix-ui/react-icons';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import relativeTime from 'dayjs/plugin/relativeTime';
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||||
import { Author } from 'nostr-relaypool';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { memo, useContext, useEffect, useState } from 'react';
|
|
||||||
|
|
||||||
dayjs.extend(relativeTime);
|
dayjs.extend(relativeTime);
|
||||||
|
|
||||||
export const UserLarge = memo(function UserLarge({ pubkey, time }: { pubkey: string; time: any }) {
|
export const UserLarge = ({ pubkey, time }: { pubkey: string; time: number }) => {
|
||||||
const [pool, relays]: any = useContext(RelayContext);
|
|
||||||
const [profile, setProfile] = useState(null);
|
const [profile, setProfile] = useState(null);
|
||||||
|
|
||||||
|
const getCachedMetadata = useCallback(async () => {
|
||||||
|
const { getFollowByPubkey } = await import('@utils/bindings');
|
||||||
|
getFollowByPubkey({ pubkey: pubkey })
|
||||||
|
.then((res) => {
|
||||||
|
if (res) {
|
||||||
|
const metadata = JSON.parse(res.metadata);
|
||||||
|
setProfile(metadata);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
}, [pubkey]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const user = new Author(pool, relays, pubkey);
|
getCachedMetadata().catch(console.error);
|
||||||
user.metaData((res) => setProfile(JSON.parse(res.content)), 0);
|
}, [getCachedMetadata]);
|
||||||
}, [pool, relays, pubkey]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
@ -51,4 +59,4 @@ export const UserLarge = memo(function UserLarge({ pubkey, time }: { pubkey: str
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
};
|
||||||
|
@ -1,18 +1,41 @@
|
|||||||
import { RelayContext } from '@components/relaysProvider';
|
|
||||||
|
|
||||||
import { truncate } from '@utils/truncate';
|
import { truncate } from '@utils/truncate';
|
||||||
|
|
||||||
import { Author } from 'nostr-relaypool';
|
import { fetch } from '@tauri-apps/api/http';
|
||||||
import { memo, useContext, useEffect, useState } from 'react';
|
import { memo, useCallback, useEffect, useState } from 'react';
|
||||||
|
|
||||||
export const UserMention = memo(function UserMention({ pubkey }: { pubkey: string }) {
|
export const UserMention = memo(function UserMention({ pubkey }: { pubkey: string }) {
|
||||||
const [pool, relays]: any = useContext(RelayContext);
|
|
||||||
const [profile, setProfile] = useState(null);
|
const [profile, setProfile] = useState(null);
|
||||||
|
|
||||||
|
const fetchMetadata = useCallback(async (pubkey: string) => {
|
||||||
|
const res = await fetch(`https://rbr.bio/${pubkey}/metadata.json`, {
|
||||||
|
method: 'GET',
|
||||||
|
timeout: 5,
|
||||||
|
});
|
||||||
|
return res.data;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const getCachedMetadata = useCallback(async () => {
|
||||||
|
const { getFollowByPubkey } = await import('@utils/bindings');
|
||||||
|
getFollowByPubkey({ pubkey: pubkey })
|
||||||
|
.then((res) => {
|
||||||
|
if (res) {
|
||||||
|
const metadata = JSON.parse(res.metadata);
|
||||||
|
setProfile(metadata);
|
||||||
|
} else {
|
||||||
|
fetchMetadata(pubkey).then((res: any) => {
|
||||||
|
if (res.content) {
|
||||||
|
const metadata = JSON.parse(res.content);
|
||||||
|
setProfile(metadata);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
}, [fetchMetadata, pubkey]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const user = new Author(pool, relays, pubkey);
|
getCachedMetadata().catch(console.error);
|
||||||
user.metaData((res) => setProfile(JSON.parse(res.content)), 0);
|
}, [getCachedMetadata]);
|
||||||
}, [pool, relays, pubkey]);
|
|
||||||
|
|
||||||
return <span className="cursor-pointer text-fuchsia-500">@{profile?.name || truncate(pubkey, 16, ' .... ')}</span>;
|
return <span className="cursor-pointer text-fuchsia-500">@{profile?.name || truncate(pubkey, 16, ' .... ')}</span>;
|
||||||
});
|
});
|
||||||
|
@ -1,21 +1,29 @@
|
|||||||
import { ImageWithFallback } from '@components/imageWithFallback';
|
import { ImageWithFallback } from '@components/imageWithFallback';
|
||||||
import { RelayContext } from '@components/relaysProvider';
|
|
||||||
|
|
||||||
import { DEFAULT_AVATAR } from '@stores/constants';
|
import { DEFAULT_AVATAR } from '@stores/constants';
|
||||||
|
|
||||||
import { truncate } from '@utils/truncate';
|
import { truncate } from '@utils/truncate';
|
||||||
|
|
||||||
import { Author } from 'nostr-relaypool';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { useContext, useEffect, useState } from 'react';
|
|
||||||
|
|
||||||
export const UserMini = ({ pubkey }: { pubkey: string }) => {
|
export const UserMini = ({ pubkey }: { pubkey: string }) => {
|
||||||
const [pool, relays]: any = useContext(RelayContext);
|
|
||||||
const [profile, setProfile] = useState(null);
|
const [profile, setProfile] = useState(null);
|
||||||
|
|
||||||
|
const getCachedMetadata = useCallback(async () => {
|
||||||
|
const { getFollowByPubkey } = await import('@utils/bindings');
|
||||||
|
getFollowByPubkey({ pubkey: pubkey })
|
||||||
|
.then((res) => {
|
||||||
|
if (res) {
|
||||||
|
const metadata = JSON.parse(res.metadata);
|
||||||
|
setProfile(metadata);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
}, [pubkey]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const user = new Author(pool, relays, pubkey);
|
getCachedMetadata().catch(console.error);
|
||||||
user.metaData((res) => setProfile(JSON.parse(res.content)), 0);
|
}, [getCachedMetadata]);
|
||||||
}, [pool, relays, pubkey]);
|
|
||||||
|
|
||||||
if (profile) {
|
if (profile) {
|
||||||
return (
|
return (
|
||||||
|
@ -42,7 +42,7 @@ export default function Page() {
|
|||||||
|
|
||||||
const computeItemKey = useCallback(
|
const computeItemKey = useCallback(
|
||||||
(index: string | number) => {
|
(index: string | number) => {
|
||||||
return data[index].id;
|
return data[index].eventId;
|
||||||
},
|
},
|
||||||
[data]
|
[data]
|
||||||
);
|
);
|
||||||
|
@ -20,6 +20,10 @@ export function getFollows(data: GetFollowData) {
|
|||||||
return invoke<Follow[]>('get_follows', { data });
|
return invoke<Follow[]>('get_follows', { data });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getFollowByPubkey(data: GetFollowPubkeyData) {
|
||||||
|
return invoke<Follow | null>('get_follow_by_pubkey', { data });
|
||||||
|
}
|
||||||
|
|
||||||
export function createFollow(data: CreateFollowData) {
|
export function createFollow(data: CreateFollowData) {
|
||||||
return invoke<Follow>('create_follow', { data });
|
return invoke<Follow>('create_follow', { data });
|
||||||
}
|
}
|
||||||
@ -41,7 +45,6 @@ export function getNoteById(data: GetNoteByIdData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type GetFollowData = { account_id: number };
|
export type GetFollowData = { account_id: number };
|
||||||
export type GetNoteByIdData = { event_id: string };
|
|
||||||
export type Note = {
|
export type Note = {
|
||||||
id: number;
|
id: number;
|
||||||
eventId: string;
|
eventId: string;
|
||||||
@ -54,9 +57,12 @@ export type Note = {
|
|||||||
createdAt: number;
|
createdAt: number;
|
||||||
accountId: number;
|
accountId: number;
|
||||||
};
|
};
|
||||||
export type GetNoteData = { date: number; limit: number; offset: number };
|
|
||||||
export type CreateFollowData = { pubkey: string; kind: number; metadata: string; account_id: number };
|
|
||||||
export type Account = { id: number; pubkey: string; privkey: string; active: boolean; metadata: string };
|
export type Account = { id: number; pubkey: string; privkey: string; active: boolean; metadata: string };
|
||||||
|
export type GetLatestNoteData = { date: number };
|
||||||
|
export type CreateFollowData = { pubkey: string; kind: number; metadata: string; account_id: number };
|
||||||
|
export type GetFollowPubkeyData = { pubkey: string };
|
||||||
|
export type CreateAccountData = { pubkey: string; privkey: string; metadata: string };
|
||||||
|
export type Follow = { id: number; pubkey: string; kind: number; metadata: string; accountId: number };
|
||||||
export type CreateNoteData = {
|
export type CreateNoteData = {
|
||||||
event_id: string;
|
event_id: string;
|
||||||
pubkey: string;
|
pubkey: string;
|
||||||
@ -68,6 +74,5 @@ export type CreateNoteData = {
|
|||||||
created_at: number;
|
created_at: number;
|
||||||
account_id: number;
|
account_id: number;
|
||||||
};
|
};
|
||||||
export type GetLatestNoteData = { date: number };
|
export type GetNoteByIdData = { event_id: string };
|
||||||
export type CreateAccountData = { pubkey: string; privkey: string; metadata: string };
|
export type GetNoteData = { date: number; limit: number; offset: number };
|
||||||
export type Follow = { id: number; pubkey: string; kind: number; metadata: string; accountId: number };
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user