further work
This commit is contained in:
parent
b9cd52285e
commit
e24e4928a2
3 changed files with 30 additions and 5 deletions
|
@ -22,6 +22,7 @@ export const ChannelDeckStore = proxyLazyWebpack(() => {
|
||||||
public _decks = new Map<string, ChannelDeck>();
|
public _decks = new Map<string, ChannelDeck>();
|
||||||
|
|
||||||
public loaded = false;
|
public loaded = false;
|
||||||
|
public pageUnloading = false;
|
||||||
|
|
||||||
public windowKeyPrefix = "DISCORD_VC_CHANNELDECK_";
|
public windowKeyPrefix = "DISCORD_VC_CHANNELDECK_";
|
||||||
public dataStoreKey = "ChannelDeck_Decks";
|
public dataStoreKey = "ChannelDeck_Decks";
|
||||||
|
@ -46,7 +47,8 @@ export const ChannelDeckStore = proxyLazyWebpack(() => {
|
||||||
this._decks.set(deck.id, deck);
|
this._decks.set(deck.id, deck);
|
||||||
const { id } = deck;
|
const { id } = deck;
|
||||||
const windowKey = this.windowKeyPrefix + id;
|
const windowKey = this.windowKeyPrefix + id;
|
||||||
if (deck?.open && !PopoutWindowStore.getWindowKeys().includes(windowKey))
|
// @ts-ignore
|
||||||
|
if (deck?.open && !PopoutWindowStore.getWindowOpen(windowKey))
|
||||||
PopoutActions.open(
|
PopoutActions.open(
|
||||||
windowKey,
|
windowKey,
|
||||||
(key) => <DeckPopout deckId={id} windowKey={key} />, {
|
(key) => <DeckPopout deckId={id} windowKey={key} />, {
|
||||||
|
@ -54,7 +56,8 @@ export const ChannelDeckStore = proxyLazyWebpack(() => {
|
||||||
defaultHeight: 960
|
defaultHeight: 960
|
||||||
});
|
});
|
||||||
// We cannot add a beforeunload event to the window here, it will be never fired as Discord has their own handler.
|
// We cannot add a beforeunload event to the window here, it will be never fired as Discord has their own handler.
|
||||||
if (!deck?.open && PopoutWindowStore.getWindowKeys().includes(windowKey))
|
// @ts-ignore
|
||||||
|
if (!deck?.open && PopoutWindowStore.getWindowOpen(windowKey))
|
||||||
this.getDeckWindow(id).close();
|
this.getDeckWindow(id).close();
|
||||||
if (noWrite || !this.loaded) return;
|
if (noWrite || !this.loaded) return;
|
||||||
this.writeData();
|
this.writeData();
|
||||||
|
@ -79,8 +82,10 @@ export const ChannelDeckStore = proxyLazyWebpack(() => {
|
||||||
|
|
||||||
// Workaround for Discord's beforeunload event
|
// Workaround for Discord's beforeunload event
|
||||||
public syncClosedWindows() {
|
public syncClosedWindows() {
|
||||||
|
if (this.pageUnloading) return;
|
||||||
this._decks.forEach((deck) => {
|
this._decks.forEach((deck) => {
|
||||||
if (deck.open && !PopoutWindowStore.getWindowKeys().includes(this.windowKeyPrefix + deck.id))
|
// @ts-ignore
|
||||||
|
if (deck.open && !PopoutWindowStore.getWindowOpen(this.windowKeyPrefix + deck.id))
|
||||||
this.setDeck({ ...deck, open: false });
|
this.setDeck({ ...deck, open: false });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -109,6 +114,8 @@ export const ChannelDeckStore = proxyLazyWebpack(() => {
|
||||||
const store = new ChannelDeckStore(FluxDispatcher, {
|
const store = new ChannelDeckStore(FluxDispatcher, {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.addEventListener("beforeunload", () => store.pageUnloading = true);
|
||||||
|
|
||||||
PopoutWindowStore.addChangeListener(() => store.syncClosedWindows());
|
PopoutWindowStore.addChangeListener(() => store.syncClosedWindows());
|
||||||
|
|
||||||
return store;
|
return store;
|
||||||
|
|
|
@ -3,7 +3,7 @@ import "./DeckColumn.css";
|
||||||
|
|
||||||
import { cl } from "./util";
|
import { cl } from "./util";
|
||||||
import { ChannelDeck, ChannelDeckStore, DeckColumn } from "../ChannelDeckStore";
|
import { ChannelDeck, ChannelDeckStore, DeckColumn } from "../ChannelDeckStore";
|
||||||
import { ChannelStore, GuildStore, useMemo } from "@webpack/common";
|
import { ChannelStore, GuildStore, MessageActions, MessageCache, useEffect, useMemo } from "@webpack/common";
|
||||||
|
|
||||||
const { HeaderBar, HeaderBarIcon } = mapMangledModuleLazy(".themedMobile]:", {
|
const { HeaderBar, HeaderBarIcon } = mapMangledModuleLazy(".themedMobile]:", {
|
||||||
HeaderBarIcon: filters.byCode('size:"custom",'),
|
HeaderBarIcon: filters.byCode('size:"custom",'),
|
||||||
|
@ -17,7 +17,21 @@ const ChatInputTypes = findByPropsLazy("FORM", "NORMAL");
|
||||||
export default function DeckColumn({ column, deck, index }: { column: DeckColumn; deck: ChannelDeck; index: number; }) {
|
export default function DeckColumn({ column, deck, index }: { column: DeckColumn; deck: ChannelDeck; index: number; }) {
|
||||||
const channel = ChannelStore.getChannel(column.channelId);
|
const channel = ChannelStore.getChannel(column.channelId);
|
||||||
const guild = GuildStore.getGuild(channel.guild_id);
|
const guild = GuildStore.getGuild(channel.guild_id);
|
||||||
const chatInputType = useMemo(() => ({ ...ChatInputTypes.SIDEBAR }), []);
|
const chatInputType = useMemo(() => ({
|
||||||
|
...ChatInputTypes.SIDEBAR
|
||||||
|
}), []);
|
||||||
|
useEffect(() => {
|
||||||
|
// Manually load messages :/
|
||||||
|
MessageActions.fetchMessages({
|
||||||
|
channelId: channel.id,
|
||||||
|
limit: 50,
|
||||||
|
isPreload: undefined,
|
||||||
|
skipLocalFetch: undefined,
|
||||||
|
jump: {
|
||||||
|
jumpType: "ANIMATED"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
return <div className={cl("column")} style={{
|
return <div className={cl("column")} style={{
|
||||||
width: column.width
|
width: column.width
|
||||||
}}>
|
}}>
|
||||||
|
|
|
@ -2,6 +2,7 @@ import "./DeckContent.css";
|
||||||
|
|
||||||
import { cl, useDeck } from "./util";
|
import { cl, useDeck } from "./util";
|
||||||
import DeckColumn from "./DeckColumn";
|
import DeckColumn from "./DeckColumn";
|
||||||
|
import { ScrollerThin } from "@webpack/common";
|
||||||
|
|
||||||
export default function DeckContent() {
|
export default function DeckContent() {
|
||||||
const deck = useDeck();
|
const deck = useDeck();
|
||||||
|
@ -9,3 +10,6 @@ export default function DeckContent() {
|
||||||
{deck?.columns.map((column, i) => <DeckColumn key={column.channelId} deck={deck} index={i} column={column} />)}
|
{deck?.columns.map((column, i) => <DeckColumn key={column.channelId} deck={deck} index={i} column={column} />)}
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
||||||
|
// <ScrollerThin orientation="horizontal">
|
||||||
|
|
||||||
|
{/* </ScrollerThin> */ }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue