Revert "UX: preloads a thread when hovering thread indicator (#21406)" (#21407)

This reverts commit 028dba144d.
This commit is contained in:
Joffrey JAFFEUX 2023-05-05 12:06:30 +02:00 committed by GitHub
parent 028dba144d
commit e88b997153
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 88 deletions

View File

@ -2,7 +2,6 @@
@route="chat.channel.thread"
@models={{@message.thread.routeModels}}
class="chat-message-thread-indicator"
{{on "mouseenter" this.preloadThread}}
>
<span class="chat-message-thread-indicator__replies-count">
{{i18n "chat.thread.replies" count=@message.threadReplyCount}}

View File

@ -1,21 +1,3 @@
import Component from "@glimmer/component";
import { action } from "@ember/object";
import { addPreloadLink } from "../lib/chat-preload-link";
import { PAGE_SIZE } from "./chat-thread";
export default class ChatMessageThreadIndicator extends Component {
@action
preloadThread() {
const channel = this.args.message.channel;
const thread = this.args.message.thread;
addPreloadLink(
`/chat/api/channels/${channel.id}/threads/${thread.id}.json`,
`thread-preload-${thread.id}`
);
addPreloadLink(
`/chat/${channel.id}/messages.json?page_size=${PAGE_SIZE}&thread_id=${thread.id}`,
`thread-preload-messages-${thread.id}`
);
}
}
export default class ChatMessageThreadIndicator extends Component {}

View File

@ -10,7 +10,7 @@ import { schedule } from "@ember/runloop";
import discourseLater from "discourse-common/lib/later";
import { resetIdle } from "discourse/lib/desktop-notifications";
export const PAGE_SIZE = 50;
const PAGE_SIZE = 50;
export default class ChatThreadPanel extends Component {
@service siteSettings;

View File

@ -1,17 +0,0 @@
export function addPreloadLink(url, id) {
if (document.querySelector(`link[href="${url}"][rel="preload"]`)) {
return;
}
const importNode = document.createElement("link");
importNode.id = id;
importNode.rel = "preload";
importNode.crossOrigin = "anonymous";
importNode.as = "fetch";
importNode.href = url;
importNode.onload = () => {
importNode?.classList?.add("is-preloaded");
};
document.head.appendChild(importNode);
}

View File

@ -39,13 +39,12 @@ export default class ChatApi extends Service {
* this.chatApi.thread(5, 1).then(thread => { ... })
*/
thread(channelId, threadId) {
return this.#getRequest(
`/channels/${channelId}/threads/${threadId}.json`
).then((result) =>
this.chat.activeChannel.threadsManager.store(
this.chat.activeChannel,
result.thread
)
return this.#getRequest(`/channels/${channelId}/threads/${threadId}`).then(
(result) =>
this.chat.activeChannel.threadsManager.store(
this.chat.activeChannel,
result.thread
)
);
}
@ -267,7 +266,7 @@ export default class ChatApi extends Service {
args.chat_channel_id = channelId;
} else {
args.page_size = data.pageSize;
path = `/chat/${channelId}/messages.json`;
path = `/chat/${channelId}/messages`;
if (data.messageId) {
args.message_id = data.messageId;

View File

@ -1,42 +0,0 @@
# frozen_string_literal: true
describe "Thread preload", type: :system, js: true do
fab!(:current_user) { Fabricate(:user) }
fab!(:channel_1) { Fabricate(:chat_channel) }
let(:chat_page) { PageObjects::Pages::Chat.new }
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
let(:thread_page) { PageObjects::Pages::ChatThread.new }
before do
SiteSetting.enable_experimental_chat_threaded_discussions = true
chat_system_bootstrap(current_user)
channel_1.add(current_user)
channel_1.update!(threading_enabled: true)
sign_in(current_user)
end
context "when hovering a thread indicator" do
it "preloads the thread" do
thread =
chat_thread_chain_bootstrap(channel: channel_1, users: [current_user, Fabricate(:user)])
chat_page.visit_channel(channel_1)
channel_page.message_thread_indicator(thread.original_message).hover
expect(page).to have_selector("link#thread-preload-#{thread.id}.is-preloaded", visible: false)
expect(page).to have_selector(
"link#thread-preload-messages-#{thread.id}.is-preloaded",
visible: false,
)
page.driver.browser.network_conditions = { offline: true }
channel_page.message_thread_indicator(thread.original_message).click
expect(thread_page).to have_message(text: thread.replies.last.message)
ensure
page.driver.browser.network_conditions = { offline: false }
end
end
end