PreviewMessage, SendTimestamps: add chat bar button in split view

This commit is contained in:
Vendicated 2025-12-06 02:41:37 +01:00
parent 192d6a2237
commit 9aa3f38033
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18
5 changed files with 10 additions and 15 deletions

View file

@ -79,7 +79,7 @@ export interface ChatBarProps {
};
}
export type ChatBarButtonFactory = (props: ChatBarProps & { isMainChat: boolean; }) => JSX.Element | null;
export type ChatBarButtonFactory = (props: ChatBarProps & { isMainChat: boolean; isAnyChat: boolean; }) => JSX.Element | null;
export type ChatBarButtonData = {
render: ChatBarButtonFactory;
/**
@ -98,13 +98,14 @@ const logger = new Logger("ChatButtons");
function VencordChatBarButtons(props: ChatBarProps) {
const { chatBarButtons } = useSettings(["uiElements.chatBarButtons.*"]).uiElements;
const { analyticsName } = props.type;
return (
<>
{Array.from(ChatBarButtonMap)
.filter(([key]) => chatBarButtons[key]?.enabled !== false)
.map(([key, { render: Button }]) => (
<ErrorBoundary noop key={key} onError={e => logger.error(`Failed to render ${key}`, e.error)}>
<Button {...props} isMainChat={props.type.analyticsName === "normal"} />
<Button {...props} isMainChat={analyticsName === "normal"} isAnyChat={["normal", "sidebar"].includes(analyticsName)} />
</ErrorBoundary>
))}
</>

View file

@ -22,7 +22,7 @@ import { Devs } from "@utils/constants";
import definePlugin, { IconComponent, StartAt } from "@utils/types";
import { CloudUpload, MessageAttachment } from "@vencord/discord-types";
import { findByPropsLazy } from "@webpack";
import { DraftStore, DraftType, SelectedChannelStore, UserStore, useStateFromStores } from "@webpack/common";
import { DraftStore, DraftType, UserStore, useStateFromStores } from "@webpack/common";
const UploadStore = findByPropsLazy("getUploads");
@ -89,11 +89,10 @@ const PreviewIcon: IconComponent = ({ height = 20, width = 20, className }) => {
);
};
const PreviewButton: ChatBarButtonFactory = ({ isMainChat, isEmpty, type: { attachments } }) => {
const channelId = SelectedChannelStore.getChannelId();
const PreviewButton: ChatBarButtonFactory = ({ isAnyChat, isEmpty, type: { attachments }, channel: { id: channelId } }) => {
const draft = useStateFromStores([DraftStore], () => getDraft(channelId));
if (!isMainChat) return null;
if (!isAnyChat) return null;
const hasAttachments = attachments && UploadStore.getUploads(channelId, DraftType.ChannelMessage).length > 0;
const hasContent = !isEmpty && draft?.length > 0;

View file

@ -144,8 +144,8 @@ const SendTimestampIcon: IconComponent = ({ height = 20, width = 20, className }
);
};
const SendTimestampButton: ChatBarButtonFactory = ({ isMainChat }) => {
if (!isMainChat) return null;
const SendTimestampButton: ChatBarButtonFactory = ({ isAnyChat }) => {
if (!isAnyChat) return null;
return (
<ChatBarButton

View file

@ -42,7 +42,7 @@ export const TranslateIcon: IconComponent = ({ height = 20, width = 20, classNam
export let setShouldShowTranslateEnabledTooltip: undefined | ((show: boolean) => void);
export const TranslateChatBarIcon: ChatBarButtonFactory = ({ isMainChat }) => {
const { autoTranslate, showChatBarButton } = settings.use(["autoTranslate", "showChatBarButton"]);
const { autoTranslate } = settings.use(["autoTranslate"]);
const [shouldShowTranslateEnabledTooltip, setter] = useState(false);
useEffect(() => {
@ -50,7 +50,7 @@ export const TranslateChatBarIcon: ChatBarButtonFactory = ({ isMainChat }) => {
return () => setShouldShowTranslateEnabledTooltip = undefined;
}, []);
if (!isMainChat || !showChatBarButton) return null;
if (!isMainChat) return null;
const toggle = () => {
const newState = !autoTranslate;

View file

@ -45,11 +45,6 @@ export const settings = definePluginSettings({
hidden: true
},
showChatBarButton: {
type: OptionType.BOOLEAN,
description: "Show translate button in chat bar",
default: true
},
service: {
type: OptionType.SELECT,
description: IS_WEB ? "Translation service (Not supported on Web!)" : "Translation service",