Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't render the menu unless we are in the viewport #5045

Merged
merged 5 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/app/src/components/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
setUserUpgradeConcurrency,
stakeNeuronForSubmittingProposals,
updateMarketMakerConfig,
pauseEventLoop: () => client.pauseEventLoop(),
resumeEventLoop: () => client.resumeEventLoop(),
};

framed.set(window.self !== window.top);
Expand Down
439 changes: 227 additions & 212 deletions frontend/app/src/components/home/ChatMessage.svelte

Large diffs are not rendered by default.

14 changes: 4 additions & 10 deletions frontend/app/src/components/home/ChatMessageContent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import MessageReminderContent from "./MessageReminderContent.svelte";
import MessageReminderCreatedContent from "./MessageReminderCreatedContent.svelte";
import ProposalContent from "./proposals/ProposalContent.svelte";
import IntersectionObserver from "./IntersectionObserver.svelte";
import type { ChatIdentifier, MessageContent } from "openchat-client";
import { _ } from "svelte-i18n";
import PrizeContentInitial from "./PrizeContentInitial.svelte";
Expand All @@ -40,14 +39,13 @@
export let messageIndex: number;
export let collapsed = false;
export let undeleting: boolean = false;
export let intersecting: boolean;
</script>

{#if content.kind === "text_content"}
<TextContent {me} {fill} {truncate} {pinned} {content} {edited} />
{:else if content.kind === "image_content"}
<IntersectionObserver let:intersecting>
<ImageContent {edited} {intersecting} {fill} {content} {reply} {pinned} {height} />
</IntersectionObserver>
<ImageContent {edited} {intersecting} {fill} {content} {reply} {pinned} {height} />
{:else if content.kind === "video_content"}
<VideoContent {edited} {fill} {content} {reply} {height} />
{:else if content.kind === "audio_content"}
Expand All @@ -71,9 +69,7 @@
{:else if content.kind === "poll_content"}
<PollContent {readonly} {me} {content} {myUserId} {senderId} on:registerVote />
{:else if content.kind === "giphy_content"}
<IntersectionObserver let:intersecting>
<GiphyContent {edited} {intersecting} {fill} {content} {reply} {height} />
</IntersectionObserver>
<GiphyContent {edited} {intersecting} {fill} {content} {reply} {height} />
{:else if content.kind === "proposal_content"}
<ProposalContent
{content}
Expand All @@ -91,9 +87,7 @@
{:else if content.kind === "reported_message_content"}
<ReportedMessageContent {content} />
{:else if content.kind === "meme_fighter_content"}
<IntersectionObserver let:intersecting>
<ImageContent {edited} {intersecting} {fill} {content} {reply} {pinned} {height} />
</IntersectionObserver>
<ImageContent {edited} {intersecting} {fill} {content} {reply} {pinned} {height} />
{:else if content.kind === "user_referral_card"}
<UserReferralCardContent />
{/if}
2 changes: 1 addition & 1 deletion frontend/app/src/components/home/ChatMessageMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
$user.userId,
msg.sender === $user.userId,
msg,
$cryptoLookup
$cryptoLookup,
);
}

Expand Down
2 changes: 2 additions & 0 deletions frontend/app/src/components/home/RepliesTo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
export let chatId: ChatIdentifier;
export let repliesTo: RehydratedReplyContext;
export let readonly: boolean;
export let intersecting: boolean;

let debug = false;

Expand Down Expand Up @@ -71,6 +72,7 @@
{me}
{readonly}
{chatId}
{intersecting}
messageId={repliesTo.messageId}
messageIndex={repliesTo.messageIndex}
senderId={repliesTo.senderId}
Expand Down
1 change: 1 addition & 0 deletions frontend/app/src/components/home/ReplyingTo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
{chatId}
fill={false}
{me}
intersecting={true}
messageId={replyingTo.messageId}
messageIndex={replyingTo.messageIndex}
senderId={replyingTo.senderId}
Expand Down
86 changes: 49 additions & 37 deletions frontend/app/src/components/home/pinned/PinnedMessage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import { mobileWidth } from "../../../stores/screenDimensions";
import { createEventDispatcher, getContext } from "svelte";
import type { ProfileLinkClickedEvent } from "../../web-components/profileLink";
import IntersectionObserver from "../IntersectionObserver.svelte";

const client = getContext<OpenChat>("client");
const dispatch = createEventDispatcher();
Expand All @@ -37,7 +38,7 @@
new CustomEvent<ProfileLinkClickedEvent>("profile-clicked", {
detail: { userId: sender.userId, chatButton: !me, inGlobalContext: false },
bubbles: true,
})
}),
);
}

Expand All @@ -56,41 +57,49 @@
userId={sender.userId}
size={$mobileWidth ? AvatarSize.Small : AvatarSize.Default} />
</div>
<div
class="message-bubble"
class:fill={fill && !deleted}
class:me
class:deleted
class:crypto
class:rtl={$rtlStore}>
{#if !deleted}
<div class="sender" class:fill class:rtl={$rtlStore}>
<Link underline={"never"} on:click={openUserProfile}>
<h4 class="username" class:fill class:crypto>{username}</h4>
</Link>
</div>
{/if}
{#if msg.repliesTo !== undefined && !deleted}
{#if msg.repliesTo.kind === "rehydrated_reply_context"}
<RepliesTo messageId={msg.messageId} readonly {chatId} repliesTo={msg.repliesTo} />
{:else}
<UnresolvedReply />
<IntersectionObserver let:intersecting>
<div
class="message-bubble"
class:fill={fill && !deleted}
class:me
class:deleted
class:crypto
class:rtl={$rtlStore}>
{#if !deleted}
<div class="sender" class:fill class:rtl={$rtlStore}>
<Link underline={"never"} on:click={openUserProfile}>
<h4 class="username" class:fill class:crypto>{username}</h4>
</Link>
</div>
{/if}
{/if}

<ChatMessageContent
readonly
pinned
{senderId}
{fill}
{chatId}
edited={msg.edited}
messageIndex={msg.messageIndex}
messageId={msg.messageId}
{me}
myUserId={user.userId}
content={msg.content} />
</div>
{#if msg.repliesTo !== undefined && !deleted}
{#if msg.repliesTo.kind === "rehydrated_reply_context"}
<RepliesTo
{intersecting}
messageId={msg.messageId}
readonly
{chatId}
repliesTo={msg.repliesTo} />
{:else}
<UnresolvedReply />
{/if}
{/if}

<ChatMessageContent
readonly
pinned
{senderId}
{fill}
{chatId}
edited={msg.edited}
messageIndex={msg.messageIndex}
messageId={msg.messageId}
{me}
{intersecting}
myUserId={user.userId}
content={msg.content} />
</div>
</IntersectionObserver>
</div>

<style lang="scss">
Expand Down Expand Up @@ -143,8 +152,11 @@
.message-bubble {
$radius: $sp3;
$inner-radius: 4px;
transition: box-shadow ease-in-out 200ms, background-color ease-in-out 200ms,
border ease-in-out 300ms, transform ease-in-out 200ms;
transition:
box-shadow ease-in-out 200ms,
background-color ease-in-out 200ms,
border ease-in-out 300ms,
transform ease-in-out 200ms;
position: relative;
padding: 6px $sp3 6px $sp3;
background-color: var(--currentChat-msg-bg);
Expand Down
8 changes: 8 additions & 0 deletions frontend/openchat-client/src/openchat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,14 @@ export class OpenChat extends OpenChatAgentWorker {
);
}

pauseEventLoop() {
this._chatsPoller?.stop();
}

resumeEventLoop() {
this.startChatsPoller();
}

private startChatsPoller() {
this._chatsPoller?.stop();
this._chatsPoller = new Poller(
Expand Down
Loading