mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-10 18:06:22 +00:00
re-implementing setStatus
Co-authored-by: Nuckyz <61953774+Nuckyz@users.noreply.github.com>
This commit is contained in:
parent
4f5f157625
commit
5c0f1601c2
1 changed files with 22 additions and 6 deletions
|
@ -24,7 +24,7 @@ import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { classes } from "@utils/misc";
|
import { classes } from "@utils/misc";
|
||||||
import definePlugin, { OptionType, StartAt } from "@utils/types";
|
import definePlugin, { OptionType, StartAt } from "@utils/types";
|
||||||
import { findByCodeLazy, findByPropsLazy, findComponentByCodeLazy } from "@webpack";
|
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
|
||||||
import { Button, Clickable, Icons, Menu, Toasts, UserStore, useState } from "@webpack/common";
|
import { Button, Clickable, Icons, Menu, Toasts, UserStore, useState } from "@webpack/common";
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
const settings = definePluginSettings({
|
||||||
|
@ -45,19 +45,35 @@ interface Emoji {
|
||||||
interface DiscordStatus {
|
interface DiscordStatus {
|
||||||
emojiInfo: Emoji | null;
|
emojiInfo: Emoji | null;
|
||||||
text: string;
|
text: string;
|
||||||
clearAfter: string | number | null;
|
clearAfter: "TODAY" | number | null;
|
||||||
status: "online" | "dnd" | "idle" | "invisible";
|
status: "online" | "dnd" | "idle" | "invisible";
|
||||||
}
|
}
|
||||||
|
|
||||||
const StatusStyles = findByPropsLazy("statusItem");
|
const StatusStyles = findByPropsLazy("statusItem");
|
||||||
const setStatus = findByCodeLazy(".CUSTOM_STATUS_UPDATED,{");
|
|
||||||
|
|
||||||
const PMenu = findComponentByCodeLazy(".menuItemLabel", ".menuItemInner");
|
const PMenu = findComponentByCodeLazy(".menuItemLabel", ".menuItemInner");
|
||||||
const EmojiComponent = findComponentByCodeLazy(".translateSurrogatesToInlineEmoji(");
|
const EmojiComponent = findComponentByCodeLazy(".translateSurrogatesToInlineEmoji(");
|
||||||
|
|
||||||
const customStatusSettings = getUserSettingLazy("status", "customStatus");
|
const CustomStatusSettings = getUserSettingLazy("status", "customStatus")!;
|
||||||
|
|
||||||
const ClearStatusButton = () => <Clickable className={StatusStyles.clearCustomStatusHint} onClick={e => { e.stopPropagation(); customStatusSettings?.updateSetting(null); }}><Icons.CircleXIcon size="sm" /></Clickable>;
|
function getExpirationMs(expiration: "TODAY" | number) {
|
||||||
|
if (expiration !== "TODAY") return Date.now() + expiration;
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
return new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1).getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setStatus(status: DiscordStatus) {
|
||||||
|
CustomStatusSettings.updateSetting({
|
||||||
|
text: status.text.trim(),
|
||||||
|
expiresAtMs: status.clearAfter != null ? String(getExpirationMs(status.clearAfter)) : "0",
|
||||||
|
emojiId: status.emojiInfo?.id ?? "0",
|
||||||
|
emojiName: status.emojiInfo?.name ?? "",
|
||||||
|
createdAtMs: String(Date.now())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const ClearStatusButton = () => <Clickable className={StatusStyles.clearCustomStatusHint} onClick={e => { e.stopPropagation(); CustomStatusSettings?.updateSetting(null); }}><Icons.CircleXIcon size="sm" /></Clickable>;
|
||||||
|
|
||||||
function StatusIcon({ isHovering, status }: { isHovering: boolean; status: DiscordStatus; }) {
|
function StatusIcon({ isHovering, status }: { isHovering: boolean; status: DiscordStatus; }) {
|
||||||
return <div className={StatusStyles.status}>{isHovering ?
|
return <div className={StatusStyles.status}>{isHovering ?
|
||||||
|
@ -96,7 +112,7 @@ const StatusSubMenuComponent = () => {
|
||||||
{Object.entries((settings.store.StatusPresets as { [k: string]: DiscordStatus; })).map(([index, status]) => <Menu.MenuItem
|
{Object.entries((settings.store.StatusPresets as { [k: string]: DiscordStatus; })).map(([index, status]) => <Menu.MenuItem
|
||||||
id={"status-presets-" + index}
|
id={"status-presets-" + index}
|
||||||
label={status.status}
|
label={status.status}
|
||||||
action={() => (status.emojiInfo?.id != null && UserStore.getCurrentUser().hasPremiumPerks || status.emojiInfo?.id == null) && setStatus(status.text, status.emojiInfo, status.clearAfter, { "location": { "section": "Account Panel", "object": "Avatar" } })}
|
action={() => (status.emojiInfo?.id != null && UserStore.getCurrentUser().hasPremiumPerks || status.emojiInfo?.id == null) && setStatus(status)}
|
||||||
render={() => <RenderStatusMenuItem
|
render={() => <RenderStatusMenuItem
|
||||||
status={status}
|
status={status}
|
||||||
forceRerender={forceRerender}
|
forceRerender={forceRerender}
|
||||||
|
|
Loading…
Reference in a new issue