Skip to content

Commit

Permalink
faster profile & event render
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalmi committed Jul 29, 2023
1 parent b19348f commit 1c72154
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
8 changes: 2 additions & 6 deletions src/js/components/events/EventComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ declare global {
}

interface EventComponentProps {
id?: string;
id: string;
standalone?: boolean;
asInlineQuote?: boolean;
showReplies?: number;
Expand All @@ -39,9 +39,8 @@ const EventComponent = (props: EventComponentProps) => {
const [state, setState] = useState<{ [key: string]: any }>({
sortedReplies: [],
meta: {},
event: Events.db.by('id', props.id),
event: Events.db.by('id', Key.toNostrHexAddress(props.id)),
});
const subscriptions: (() => void)[] = [];
const retrievingTimeout = useRef<any>();
const unmounted = useRef<boolean>(false);

Expand Down Expand Up @@ -93,9 +92,6 @@ const EventComponent = (props: EventComponentProps) => {
hexId && Events.getEventById(hexId, true, (event) => handleEvent(event));

return () => {
subscriptions.forEach((unsub) => {
unsub();
});
unmounted.current = true;
};
}, []);
Expand Down
3 changes: 3 additions & 0 deletions src/js/components/events/NoteImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ function NoteImage(props: { event: Event; fadeIn?: boolean }) {

if (props.event.kind !== 1) {
const id = Events.getEventReplyingTo(props.event);
if (!id) {
return null;
}
return <EventComponent id={id} renderAs="NoteImage" />;
}
const attachments = [] as { type: string; url: string }[];
Expand Down
4 changes: 4 additions & 0 deletions src/js/components/events/Zap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export default function Zap(props: Props) {
: () => null;
}, [zappedId]);

if (!zappedId) {
return null;
}

let zappingUser = null as string | null;
try {
zappingUser = Events.getZappingUser(props.event.id);
Expand Down
3 changes: 2 additions & 1 deletion src/js/components/user/ProfileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Events from '../../nostr/Events';
import Key from '../../nostr/Key';
import PubSub from '../../nostr/PubSub';
import SocialNetwork from '../../nostr/SocialNetwork';
import { ID } from '../../nostr/UserIds';
import { translate as t } from '../../translations/Translation.mjs';
import Follow from '../buttons/Follow';
import Show from '../helpers/Show';
Expand All @@ -19,7 +20,7 @@ import Stats from './Stats';

const ProfileCard = (props: { hexPub: string; npub: string }) => {
const { hexPub, npub } = props;
const [profile, setProfile] = useState<any>({});
const [profile, setProfile] = useState<any>(SocialNetwork.profiles.get(ID(hexPub)));
const [lightning, setLightning] = useState<string>('');
const [website, setWebsite] = useState<string>('');
const [loggedIn, setLoggedIn] = useState<boolean>(false);
Expand Down

0 comments on commit 1c72154

Please sign in to comment.