more fixes

This commit is contained in:
rushiiMachine 2024-06-24 22:56:30 -07:00
parent 18c0e1d57f
commit 09182add06
No known key found for this signature in database
GPG key ID: DCBE5952BB3B6420
3 changed files with 24 additions and 12 deletions

View file

@ -13,7 +13,7 @@ import { fetchTimezone, fetchTimezonesBulk, Snowflake } from "./api";
import settings, { TimezoneOverwrites } from "./settings"; import settings, { TimezoneOverwrites } from "./settings";
// TODO: cache invalidation // TODO: cache invalidation
const TimezoneCache = createStore("TimezoneCache", "TimezoneCache"); export const TimezoneCache = createStore("TimezoneCache", "TimezoneCache");
// A list of callbacks that will trigger on a completed debounced bulk fetch // A list of callbacks that will trigger on a completed debounced bulk fetch
type BulkFetchCallback = (timezone: string | null) => void; type BulkFetchCallback = (timezone: string | null) => void;

View file

@ -153,14 +153,13 @@ export function TimezoneOverrideModal(props: TimezoneOverrideModalProps) {
function saveOverwrite() { function saveOverwrite() {
if (availableTimezones === undefined) return; if (availableTimezones === undefined) return;
const overwrites: TimezoneOverwrites = settings.store.timezoneOverwrites ?? {}; const overwrites: TimezoneOverwrites = {
if (timezone === undefined) { [props.userId]: timezone === "NONE" ? null : timezone,
...settings.store.timezoneOverwrites,
};
if (timezone === undefined)
delete overwrites[props.userId]; delete overwrites[props.userId];
} else if (timezone === "NONE") {
overwrites[props.userId] = null;
} else {
overwrites[props.userId] = timezone;
}
settings.store.timezoneOverwrites = overwrites; settings.store.timezoneOverwrites = overwrites;
props.modalProps.onClose(); props.modalProps.onClose();
@ -176,14 +175,19 @@ export function TimezoneOverrideModal(props: TimezoneOverrideModalProps) {
<ModalContent className="vc-timezone-modal-content"> <ModalContent className="vc-timezone-modal-content">
<Text variant="text-md/normal"> <Text variant="text-md/normal">
This override will only be visible locally. This override will only be visible locally and to any synchronized clients via Vencord Cloud.
<br />
<br /> <br />
To set your own Timezone for other users to see, To set your own Timezone for other users to see,
click <Link onClick={/* TODO */ _ => _}>here</Link> to click <Link onClick={/* TODO */ _ => _}>here</Link> to
authorize TimezoneDB. authorize the public TimezoneDB API.
</Text> </Text>
<section className={classes(Margins.bottom16, Margins.top16)}> <Forms.FormTitle tag="h3" className={Margins.top16}>
Set Timezone
</Forms.FormTitle>
<section className={classes(Margins.bottom8, Margins.top8)}>
<SearchableSelect <SearchableSelect
options={availableTimezones ?? []} options={availableTimezones ?? []}
value={availableTimezones?.find(opt => opt.value === timezone)} value={availableTimezones?.find(opt => opt.value === timezone)}

View file

@ -22,9 +22,13 @@ import { IPluginOptionComponentProps, OptionType } from "@utils/types";
import { Text } from "@webpack/common"; import { Text } from "@webpack/common";
import { Snowflake } from "./api"; import { Snowflake } from "./api";
import { DataStore } from "@api/index";
import { TimezoneCache } from "./cache";
export type TimezoneOverwrites = Record<Snowflake, string | null>; export type TimezoneOverwrites = Record<Snowflake, string | null>;
const DEFAULT_API = "https://timezonedb.catvibers.me/api";
const settings = definePluginSettings({ const settings = definePluginSettings({
enableApi: { enableApi: {
type: OptionType.BOOLEAN, type: OptionType.BOOLEAN,
@ -34,7 +38,11 @@ const settings = definePluginSettings({
apiUrl: { apiUrl: {
type: OptionType.STRING, type: OptionType.STRING,
description: "The TimezoneDB API instance to fetch from", description: "The TimezoneDB API instance to fetch from",
default: "https://timezonedb.catvibers.me/api", default: DEFAULT_API,
placeholder: DEFAULT_API,
onChange(_: any) {
DataStore.clear(TimezoneCache).catch(_ => _)
}
}, },
displayInChat: { displayInChat: {
type: OptionType.BOOLEAN, type: OptionType.BOOLEAN,