mirror of
https://github.com/irislib/iris-messenger.git
synced 2024-10-18 06:03:22 +00:00
feed loading
This commit is contained in:
parent
4e4ab4798b
commit
74d65bd8ea
@ -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
|
||||
}
|
||||
|
@ -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>
|
||||
);
|
||||
|
@ -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>
|
||||
);
|
||||
|
@ -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>
|
||||
</>
|
||||
|
@ -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>
|
||||
);
|
||||
|
@ -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
|
||||
|
@ -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) => {
|
||||
|
@ -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>
|
||||
);
|
||||
|
@ -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 },
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
Loading…
Reference in New Issue
Block a user