DEV: prevent duplication of chat drawer routes (#27381)
This change prevents explicitly declaring each route that should be intercepted for chat drawer mode. In theory all chat drawer routes should be intercepted from the main chat routes file and therefore we would only need to add new drawer routes directly within chat-drawer-router.js.
This commit is contained in:
parent
35792ea18c
commit
9e6dc4c5c8
|
@ -15,6 +15,7 @@ export default class ChatRoute extends DiscourseRoute {
|
||||||
@service chat;
|
@service chat;
|
||||||
@service router;
|
@service router;
|
||||||
@service chatStateManager;
|
@service chatStateManager;
|
||||||
|
@service chatDrawerRouter;
|
||||||
@service currentUser;
|
@service currentUser;
|
||||||
|
|
||||||
titleToken() {
|
titleToken() {
|
||||||
|
@ -26,29 +27,10 @@ export default class ChatRoute extends DiscourseRoute {
|
||||||
return this.router.transitionTo(`discovery.${defaultHomepage()}`);
|
return this.router.transitionTo(`discovery.${defaultHomepage()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const INTERCEPTABLE_ROUTES = [
|
|
||||||
"chat.channel",
|
|
||||||
"chat.direct-messages",
|
|
||||||
"chat.channels",
|
|
||||||
"chat.threads",
|
|
||||||
"chat.channel.thread",
|
|
||||||
"chat.channel.thread.index",
|
|
||||||
"chat.channel.thread.near-message",
|
|
||||||
"chat.channel.near-message-with-thread",
|
|
||||||
"chat.channel.threads",
|
|
||||||
"chat.channel.index",
|
|
||||||
"chat.channel.near-message",
|
|
||||||
"chat.channel-legacy",
|
|
||||||
"chat.channel.info.settings",
|
|
||||||
"chat.channel.info.members",
|
|
||||||
"chat",
|
|
||||||
"chat.index",
|
|
||||||
];
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
transition.from && // don't intercept when directly loading chat
|
transition.from && // don't intercept when directly loading chat
|
||||||
this.chatStateManager.isDrawerPreferred &&
|
this.chatStateManager.isDrawerPreferred &&
|
||||||
INTERCEPTABLE_ROUTES.includes(transition.targetName)
|
this.chatDrawerRouter.routeNames.includes(transition.targetName)
|
||||||
) {
|
) {
|
||||||
transition.abort();
|
transition.abort();
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,9 @@ import ChatDrawerRoutesSettings from "discourse/plugins/chat/discourse/component
|
||||||
import ChatDrawerRoutesThreads from "discourse/plugins/chat/discourse/components/chat/drawer-routes/threads";
|
import ChatDrawerRoutesThreads from "discourse/plugins/chat/discourse/components/chat/drawer-routes/threads";
|
||||||
|
|
||||||
const ROUTES = {
|
const ROUTES = {
|
||||||
|
"chat.index": { name: ChatDrawerRoutesChannels },
|
||||||
"chat.channel": { name: ChatDrawerRoutesChannel },
|
"chat.channel": { name: ChatDrawerRoutesChannel },
|
||||||
|
"chat.channel.index": { name: ChatDrawerRoutesChannel },
|
||||||
"chat.channel.thread": {
|
"chat.channel.thread": {
|
||||||
name: ChatDrawerRoutesChannelThread,
|
name: ChatDrawerRoutesChannelThread,
|
||||||
extractParams: (route) => {
|
extractParams: (route) => {
|
||||||
|
@ -103,6 +105,8 @@ export default class ChatDrawerRouter extends Service {
|
||||||
@tracked drawerRoute = null;
|
@tracked drawerRoute = null;
|
||||||
@tracked params = null;
|
@tracked params = null;
|
||||||
|
|
||||||
|
routeNames = Object.keys(ROUTES);
|
||||||
|
|
||||||
stateFor(route) {
|
stateFor(route) {
|
||||||
this.drawerRoute?.deactivate?.(this.chatHistory.currentRoute);
|
this.drawerRoute?.deactivate?.(this.chatHistory.currentRoute);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue