feed loading

This commit is contained in:
Martti Malmi 2023-08-08 12:21:42 +03:00
parent 4e4ab4798b
commit 74d65bd8ea
9 changed files with 33 additions and 12 deletions

View File

@ -29,7 +29,6 @@ const HyperText = memo(
processedChildren = processedChildren.map((x, index, array) => {
if (typeof x === 'string') {
console.log(' array[index + 1]', array[index + 1]);
if (index < array.length - 1 && !array[index + 1].props?.href) {
x = x.replace(/\n+$/, ''); // Remove trailing newlines if next element is not a link
}

View File

@ -7,7 +7,7 @@ const Url: Embed = {
component: ({ match }) => {
const url = match.replace(/^(https:\/\/)?iris.to/, '');
return (
<Link className="link mx-1" target="_blank" href={url}>
<Link className="link" target="_blank" href={url}>
{match.replace(/^https?:\/\//, '').replace(/\/$/, '')}
</Link>
);

View File

@ -24,7 +24,7 @@ const InlineMention: Embed = {
const [type, id] = tag;
if (type === 'p') {
return (
<Link href={`/${nip19.npubEncode(id)}`} className="mx-1 link">
<Link href={`/${nip19.npubEncode(id)}`} className="link">
<Name pub={id} hideBadge={true} />
</Link>
);

View File

@ -15,7 +15,7 @@ const NostrUser: Embed = {
if (type === 'nprofile') {
return (
<>
<Link className="link mx-1" href={`/${data.pubkey}`}>
<Link className="link" href={`/${data.pubkey}`}>
<Name pub={data.pubkey} />
</Link>
</>

View File

@ -11,7 +11,7 @@ const NostrNpub: Embed = {
component: ({ match }) => {
const pub = match.replace('@', '');
return (
<Link href={`/${pub}`} className="link mx-1">
<Link href={`/${pub}`} className="link">
<Name pub={pub} hideBadge={true} />
</Link>
);

View File

@ -51,10 +51,12 @@ const Feed = ({ showDisplayAs, filterOptions, emptyMessage }: Props) => {
const lastElementRef = useRef(null);
const [mutedUsers] = useLocalState('muted', {});
console.log('subscribe to filter', filterOption.filter);
const { events: allEvents, loadMore } = useSubscribe({
filter: filterOption.filter,
// in keyword search, relays should be queried for all events, not just sinceLastOpened
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
sinceLastOpened: false,
});
// deduplicate

View File

@ -11,12 +11,13 @@ const useSubscribe = (ops: {
enabled?: boolean;
}) => {
const [sortedEvents] = useState(new SortedEventMap());
const { filter, enabled = true, sinceLastOpened = true, mergeSubscriptions = true } = ops;
const { filter, enabled = true, sinceLastOpened = false, mergeSubscriptions = true } = ops;
const [events, setEvents] = useState<Event[]>([]);
// TODO save into SortedMap
useEffect(() => {
if (!enabled || !filter) return;
filter.limit = filter.limit || 10;
return PubSub.subscribe(
filter,
(event: any) => {

View File

@ -25,7 +25,7 @@ class Feed extends View {
<div className="hidden md:block px-4">
<PublicMessageForm autofocus={false} placeholder={t('whats_on_your_mind')} />
</div>
<FeedComponent filterOptions={[{ name: 'Global', filter: { kinds: [1] } }]} />
<FeedComponent filterOptions={[{ name: 'Global', filter: { kinds: [1], limit: 50 } }]} />
</div>
</div>
);

View File

@ -1,24 +1,44 @@
import FeedComponent from '@/components/feed/Feed';
import OnboardingNotification from '@/components/OnboardingNotification';
import PublicMessageForm from '@/components/PublicMessageForm';
import Key from '@/nostr/Key';
import { Unsubscribe } from '@/nostr/PubSub';
import { ID, PUB } from '@/nostr/UserIds';
import { translate as t } from '@/translations/Translation.mjs';
import SocialNetwork from '../../nostr/SocialNetwork';
import View from '../View';
class Feed extends View {
unsub?: Unsubscribe;
constructor() {
super();
this.state = { sortedMessages: [] };
const followedUsers: string[] = Array.from(
SocialNetwork.followedByUser.get(ID(Key.getPubKey())) || [],
).map((n) => PUB(n));
this.state = {
followedUsers,
};
this.id = 'message-view';
this.class = 'public-messages-view';
}
componentDidMount() {
this.restoreScrollPosition();
this.unsub = SocialNetwork.getFollowedByUser(Key.getPubKey(), (followedUsers) => {
this.setState({ followedUsers: Array.from(followedUsers) });
});
}
componentWillUnmount() {
super.componentWillUnmount();
this.unsub?.();
}
renderView() {
if (!this.state.followedUsers.length) return <></>;
console.log('this.state.followedUsers', this.state.followedUsers);
return (
<div className="flex flex-row">
<div className="flex flex-col w-full">
@ -30,8 +50,7 @@ class Feed extends View {
filterOptions={[
{
name: 'Followed users',
filter: { kinds: [1] },
filterFn: (event) => SocialNetwork.getFollowDistance(event.pubkey) <= 1,
filter: { kinds: [1], authors: this.state.followedUsers, limit: 100 },
},
]}
/>