mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-24 15:35:11 +00:00
rename overwrites to overrides
This commit is contained in:
parent
35e937678b
commit
6768e22e53
3 changed files with 23 additions and 23 deletions
|
@ -10,7 +10,7 @@ import { debounce } from "@shared/debounce";
|
||||||
import { Logger } from "@utils/Logger";
|
import { Logger } from "@utils/Logger";
|
||||||
|
|
||||||
import { fetchTimezone, fetchTimezonesBulk, Snowflake } from "./api";
|
import { fetchTimezone, fetchTimezonesBulk, Snowflake } from "./api";
|
||||||
import settings, { TimezoneOverwrites } from "./settings";
|
import settings, { TimezoneOverrides } from "./settings";
|
||||||
|
|
||||||
// TODO: cache invalidation
|
// TODO: cache invalidation
|
||||||
export const TimezoneCache = createStore("TimezoneCache", "TimezoneCache");
|
export const TimezoneCache = createStore("TimezoneCache", "TimezoneCache");
|
||||||
|
@ -54,9 +54,9 @@ export async function getUserTimezone(
|
||||||
immediate: boolean = false,
|
immediate: boolean = false,
|
||||||
force: boolean = false,
|
force: boolean = false,
|
||||||
): Promise<string | null> {
|
): Promise<string | null> {
|
||||||
const overwrites: TimezoneOverwrites = settings.store.timezoneOverwrites ?? {};
|
const overrides: TimezoneOverrides = settings.store.timezoneOverrides ?? {};
|
||||||
const overwrite = overwrites[userId];
|
const override = overrides[userId];
|
||||||
if (overwrite !== undefined) return overwrite;
|
if (override !== undefined) return override;
|
||||||
if (!settings.store.enableApi) return null;
|
if (!settings.store.enableApi) return null;
|
||||||
|
|
||||||
if (!force) {
|
if (!force) {
|
||||||
|
|
|
@ -24,7 +24,7 @@ import { SelectOption } from "@webpack/types";
|
||||||
|
|
||||||
import { Snowflake } from "./api";
|
import { Snowflake } from "./api";
|
||||||
import { getUserTimezone } from "./cache";
|
import { getUserTimezone } from "./cache";
|
||||||
import settings, { TimezoneOverwrites } from "./settings";
|
import settings, { TimezoneOverrides } from "./settings";
|
||||||
import { formatTimestamp, getTimezonesLazy } from "./utils";
|
import { formatTimestamp, getTimezonesLazy } from "./utils";
|
||||||
|
|
||||||
// Based on Syncxv's vc-timezones user plugin //
|
// Based on Syncxv's vc-timezones user plugin //
|
||||||
|
@ -99,7 +99,7 @@ function LocalTimestampInner(props: LocalTimestampProps): JSX.Element | null {
|
||||||
className={classes}
|
className={classes}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
toolTipProps.onClick();
|
toolTipProps.onClick();
|
||||||
openTimezoneOverwriteModal(props.userId);
|
openTimezoneOverrideModal(props.userId);
|
||||||
}}>
|
}}>
|
||||||
{shortTimeFormatted}
|
{shortTimeFormatted}
|
||||||
</span>
|
</span>
|
||||||
|
@ -113,7 +113,7 @@ interface TimezoneOverrideModalProps {
|
||||||
modalProps: ModalProps,
|
modalProps: ModalProps,
|
||||||
}
|
}
|
||||||
|
|
||||||
function TimezoneOverrideModal(props: TimezoneOverrideModalProps) {
|
function SetTimezoneOverrideModal(props: TimezoneOverrideModalProps) {
|
||||||
const [availableTimezones, setAvailableTimezones] = useState<SelectOption[]>();
|
const [availableTimezones, setAvailableTimezones] = useState<SelectOption[]>();
|
||||||
const [timezone, setTimezone] = useState<string | "NONE" | undefined>();
|
const [timezone, setTimezone] = useState<string | "NONE" | undefined>();
|
||||||
|
|
||||||
|
@ -140,22 +140,22 @@ function TimezoneOverrideModal(props: TimezoneOverrideModalProps) {
|
||||||
setAvailableTimezones(options);
|
setAvailableTimezones(options);
|
||||||
});
|
});
|
||||||
|
|
||||||
const overwrites: TimezoneOverwrites = settings.store.timezoneOverwrites ?? {};
|
const overrides: TimezoneOverrides = settings.store.timezoneOverrides ?? {};
|
||||||
const overwrite = overwrites[props.userId];
|
const override = overrides[props.userId];
|
||||||
setTimezone(overwrite === null ? "NONE" : overwrite);
|
setTimezone(override === null ? "NONE" : override);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function saveOverwrite() {
|
function saveOverride() {
|
||||||
if (availableTimezones === undefined) return;
|
if (availableTimezones === undefined) return;
|
||||||
|
|
||||||
const overwrites: TimezoneOverwrites = {
|
const overrides: TimezoneOverrides = {
|
||||||
[props.userId]: timezone === "NONE" ? null : timezone,
|
[props.userId]: timezone === "NONE" ? null : timezone,
|
||||||
...settings.store.timezoneOverwrites,
|
...settings.store.timezoneOverrides,
|
||||||
};
|
};
|
||||||
if (timezone === undefined)
|
if (timezone === undefined)
|
||||||
delete overwrites[props.userId];
|
delete overrides[props.userId];
|
||||||
|
|
||||||
settings.store.timezoneOverwrites = overwrites;
|
settings.store.timezoneOverrides = overrides;
|
||||||
|
|
||||||
props.modalProps.onClose();
|
props.modalProps.onClose();
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ function TimezoneOverrideModal(props: TimezoneOverrideModalProps) {
|
||||||
<Button
|
<Button
|
||||||
color={Button.Colors.BRAND}
|
color={Button.Colors.BRAND}
|
||||||
disabled={availableTimezones === undefined}
|
disabled={availableTimezones === undefined}
|
||||||
onClick={saveOverwrite}>
|
onClick={saveOverride}>
|
||||||
Save
|
Save
|
||||||
</Button>
|
</Button>
|
||||||
<Button color={Button.Colors.RED} onClick={props.modalProps.onClose}>
|
<Button color={Button.Colors.RED} onClick={props.modalProps.onClose}>
|
||||||
|
@ -208,10 +208,10 @@ function TimezoneOverrideModal(props: TimezoneOverrideModalProps) {
|
||||||
</ModalRoot>;
|
</ModalRoot>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function openTimezoneOverwriteModal(userId: string) {
|
export function openTimezoneOverrideModal(userId: string) {
|
||||||
openModal(modalProps => <>
|
openModal(modalProps => <>
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<TimezoneOverrideModal userId={userId} modalProps={modalProps} />
|
<SetTimezoneOverrideModal userId={userId} modalProps={modalProps} />
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
</>);
|
</>);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ import { Text } from "@webpack/common";
|
||||||
import { Snowflake } from "./api";
|
import { Snowflake } from "./api";
|
||||||
import { TimezoneCache } from "./cache";
|
import { TimezoneCache } from "./cache";
|
||||||
|
|
||||||
export type TimezoneOverwrites = Record<Snowflake, string | null>;
|
export type TimezoneOverrides = Record<Snowflake, string | null>;
|
||||||
|
|
||||||
const DEFAULT_API = "https://timezonedb.catvibers.me/api";
|
const DEFAULT_API = "https://timezonedb.catvibers.me/api";
|
||||||
|
|
||||||
|
@ -54,11 +54,11 @@ const settings = definePluginSettings({
|
||||||
description: "Show local time in user profiles",
|
description: "Show local time in user profiles",
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
timezoneOverwrites: {
|
timezoneOverrides: {
|
||||||
type: OptionType.COMPONENT,
|
type: OptionType.COMPONENT,
|
||||||
description: "Local overwrites for users' timezones",
|
description: "Local overrides for users' timezones",
|
||||||
component: props => <>
|
component: props => <>
|
||||||
<TimezoneOverwritesSetting
|
<TimezoneOverridesSetting
|
||||||
setValue={props.setValue}
|
setValue={props.setValue}
|
||||||
setError={props.setError}
|
setError={props.setError}
|
||||||
option={props.option} />
|
option={props.option} />
|
||||||
|
@ -84,6 +84,6 @@ export function SettingsComponent(): JSX.Element {
|
||||||
</>;
|
</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function TimezoneOverwritesSetting(props: IPluginOptionComponentProps): JSX.Element {
|
function TimezoneOverridesSetting(props: IPluginOptionComponentProps): JSX.Element {
|
||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue