diff --git a/Cargo.lock b/Cargo.lock index 5730115..b2c14d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2645,9 +2645,9 @@ dependencies = [ [[package]] name = "rocket_dyn_templates" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04bfc006e547e4f72b760ab861f5943b688aed8a82c4977b5500c98f5d17dbfa" +checksum = "5bbab919c9e67df3f7ac6624a32ef897df4cd61c0969f4d66f3ced0534660d7a" dependencies = [ "normpath", "notify", diff --git a/Cargo.toml b/Cargo.toml index 4bf6fdb..3bb31f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ secrecy = "0.8.0" futures = "0.3.30" prometheus = "0.13.3" rocket = { version = "0.5.0", features = ["tls", "secrets", "json"] } -rocket_dyn_templates = { version = "0.1.0", features = ["tera"] } +rocket_dyn_templates = { version = "0.2.0", features = ["tera"] } serenity = { version = "0.12", default-features = false, features = ["builder", "cache", "client", "gateway", "http", "model", "utils", "rustls_backend"] } oauth2 = "4" csv = "1.2" diff --git a/migrations/20210603000000_initial.sql b/migrations/20210603000000_initial.sql index e1527dc..aca6864 100644 --- a/migrations/20210603000000_initial.sql +++ b/migrations/20210603000000_initial.sql @@ -136,9 +136,9 @@ CREATE TABLE reminders ( set_by INT UNSIGNED, PRIMARY KEY (id), - FOREIGN KEY (message_id) REFERENCES messages(id) ON DELETE RESTRICT, - FOREIGN KEY (channel_id) REFERENCES channels(id) ON DELETE CASCADE, - FOREIGN KEY (set_by) REFERENCES users(id) ON DELETE SET NULL + CONSTRAINT `reminder_message_fk` FOREIGN KEY (message_id) REFERENCES messages(id) ON DELETE RESTRICT, + CONSTRAINT `reminder_channel_fk` FOREIGN KEY (channel_id) REFERENCES channels(id) ON DELETE CASCADE, + CONSTRAINT `reminder_user_fk` FOREIGN KEY (set_by) REFERENCES users(id) ON DELETE SET NULL ); CREATE TRIGGER message_cleanup AFTER DELETE ON reminders @@ -157,9 +157,9 @@ CREATE TABLE todos ( value VARCHAR(2000) NOT NULL, PRIMARY KEY (id), - FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL, - FOREIGN KEY (guild_id) REFERENCES guilds(id) ON DELETE CASCADE, - FOREIGN KEY (channel_id) REFERENCES channels(id) ON DELETE SET NULL + CONSTRAINT todos_ibfk_5 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL, + CONSTRAINT todos_ibfk_4 FOREIGN KEY (guild_id) REFERENCES guilds(id) ON DELETE CASCADE, + CONSTRAINT todos_ibfk_3 FOREIGN KEY (channel_id) REFERENCES channels(id) ON DELETE SET NULL ); CREATE TABLE command_restrictions ( diff --git a/migrations/20210623000000_reminder_message_embed.sql b/migrations/20210623000000_reminder_message_embed.sql index e6b83cb..3293f36 100644 --- a/migrations/20210623000000_reminder_message_embed.sql +++ b/migrations/20210623000000_reminder_message_embed.sql @@ -46,7 +46,7 @@ CREATE TABLE reminders_new ( PRIMARY KEY (id), FOREIGN KEY (`channel_id`) REFERENCES channels (`id`) ON DELETE CASCADE, - FOREIGN KEY (`set_by`) REFERENCES users (`id`) ON DELETE SET NULL + CONSTRAINT `reminders_ibfk_2` FOREIGN KEY (`set_by`) REFERENCES `users` (`id`) ON DELETE SET NULL # disallow having a reminder as restartable if it has no interval -- , CONSTRAINT restartable_interval_mutex CHECK (`restartable` = 0 OR `interval` IS NULL) diff --git a/migrations/20240630150936_dashboard_preferences.sql b/migrations/20240630150936_dashboard_preferences.sql index 2069663..4e33e69 100644 --- a/migrations/20240630150936_dashboard_preferences.sql +++ b/migrations/20240630150936_dashboard_preferences.sql @@ -1,3 +1,7 @@ +-- Tables no longer needed as old dashboard is decomm. +DROP TABLE guild_users; +DROP TABLE events; + ALTER TABLE users ADD COLUMN `reset_inputs_on_create` BOOLEAN NOT NULL DEFAULT 0; ALTER TABLE users ADD COLUMN `use_browser_timezone` BOOLEAN NOT NULL DEFAULT 1; ALTER TABLE users ADD COLUMN `dashboard_color_scheme` ENUM('system', 'light', 'dark') NOT NULL DEFAULT 'system'; @@ -7,4 +11,14 @@ ALTER TABLE users DROP COLUMN `patreon`; ALTER TABLE users DROP COLUMN `name`; ALTER TABLE users DROP PRIMARY KEY, ADD PRIMARY KEY (`user`); + +ALTER TABLE todos DROP CONSTRAINT todos_ibfk_5, MODIFY COLUMN user_id BIGINT UNSIGNED; +UPDATE todos SET user_id = (SELECT user FROM users WHERE id = user_id); +ALTER TABLE todos ADD CONSTRAINT todos_user_fk FOREIGN KEY (user_id) REFERENCES users(user); + +ALTER TABLE reminders DROP CONSTRAINT reminders_ibfk_2, MODIFY COLUMN set_by BIGINT UNSIGNED; +UPDATE reminders SET set_by = (SELECT user FROM users WHERE id = set_by); +ALTER TABLE reminders ADD CONSTRAINT reminder_user_fk FOREIGN KEY (set_by) REFERENCES users(user); + +ALTER TABLE users DROP COLUMN `id`; ALTER TABLE users RENAME COLUMN `user` TO `id`; diff --git a/reminder-dashboard/index.html b/reminder-dashboard/index.html index f3703ab..7443c6e 100644 --- a/reminder-dashboard/index.html +++ b/reminder-dashboard/index.html @@ -22,7 +22,6 @@ Reminder Bot | Dashboard - diff --git a/reminder-dashboard/src/api.ts b/reminder-dashboard/src/api.ts index defe690..850ba2b 100644 --- a/reminder-dashboard/src/api.ts +++ b/reminder-dashboard/src/api.ts @@ -1,10 +1,27 @@ import axios from "axios"; +enum ColorScheme { + System = "system", + Dark = "dark", + Light = "light", +} + type UserInfo = { name: string; patreon: boolean; - timezone: string | null; - reset_inputs_on_create: boolean; + preferences: { + timezone: string | null; + reset_inputs_on_create: boolean; + dashboard_color_scheme: ColorScheme; + use_browser_timezone: boolean; + }; +}; + +type UpdateUserInfo = { + timezone?: string; + reset_inputs_on_create?: boolean; + dashboard_color_scheme?: ColorScheme; + use_browser_timezone?: boolean; }; export type GuildInfo = { @@ -110,7 +127,7 @@ export const fetchUserInfo = () => ({ }); export const patchUserInfo = () => ({ - mutationFn: (timezone: string) => axios.patch(`/dashboard/api/user`, { timezone }), + mutationFn: (userInfo: UpdateUserInfo) => axios.patch(`/dashboard/api/user`, userInfo), }); export const fetchUserGuilds = () => ({ diff --git a/reminder-dashboard/src/components/App/TimezoneProvider.tsx b/reminder-dashboard/src/components/App/TimezoneProvider.tsx index a67c77a..4e6b219 100644 --- a/reminder-dashboard/src/components/App/TimezoneProvider.tsx +++ b/reminder-dashboard/src/components/App/TimezoneProvider.tsx @@ -1,15 +1,27 @@ import { createContext } from "preact"; import { useContext } from "preact/compat"; -import { useState } from "preact/hooks"; +import { useEffect, useState } from "preact/hooks"; import { DateTime } from "luxon"; +import { fetchUserInfo } from "../../api"; +import { useQuery } from "react-query"; type TTimezoneContext = [string, (tz: string) => void]; const TimezoneContext = createContext(["UTC", () => {}] as TTimezoneContext); export const TimezoneProvider = ({ children }) => { + const { data } = useQuery({ ...fetchUserInfo() }); + const [timezone, setTimezone] = useState(DateTime.now().zoneName); + useEffect(() => { + setTimezone( + data === undefined || data.preferences.use_browser_timezone + ? DateTime.now().zoneName + : data.preferences.timezone, + ); + }, [data]); + return ( {children} diff --git a/reminder-dashboard/src/components/App/index.tsx b/reminder-dashboard/src/components/App/index.tsx index 8dfe394..240c06f 100644 --- a/reminder-dashboard/src/components/App/index.tsx +++ b/reminder-dashboard/src/components/App/index.tsx @@ -13,14 +13,14 @@ export function App() { const queryClient = new QueryClient(); let scheme = "light"; - if (window.matchMedia("(prefers-color-scheme: dark)").matches) { - scheme = "dark"; - } + // if (window.matchMedia("(prefers-color-scheme: dark)").matches) { + // scheme = "dark"; + // } return ( - - - + + +
@@ -52,8 +52,8 @@ export function App() {
-
-
-
+ + + ); } diff --git a/reminder-dashboard/src/components/Reminder/Settings.tsx b/reminder-dashboard/src/components/Reminder/Settings.tsx index 463c300..d85a6ee 100644 --- a/reminder-dashboard/src/components/Reminder/Settings.tsx +++ b/reminder-dashboard/src/components/Reminder/Settings.tsx @@ -11,7 +11,7 @@ import { useGuild } from "../App/useGuild"; export const Settings = () => { const guild = useGuild(); - const { isSuccess: userFetched, data: userInfo } = useQuery(fetchUserInfo()); + const { isSuccess: userFetched, data: userInfo } = useQuery({ ...fetchUserInfo() }); const [reminder, setReminder] = useReminder(); diff --git a/reminder-dashboard/src/components/Reminder/styles.scss b/reminder-dashboard/src/components/Reminder/styles.scss index 5c5e051..68c2ebf 100644 --- a/reminder-dashboard/src/components/Reminder/styles.scss +++ b/reminder-dashboard/src/components/Reminder/styles.scss @@ -26,3 +26,11 @@ textarea.autoresize { resize: vertical !important; } + +div.reminderContent { + margin-top: 10px; + margin-bottom: 10px; + padding: 14px; + background-color: #f5f5f5; + border-radius: 8px; +} diff --git a/reminder-dashboard/src/components/Sidebar/index.tsx b/reminder-dashboard/src/components/Sidebar/index.tsx index acfa4e1..794c610 100644 --- a/reminder-dashboard/src/components/Sidebar/index.tsx +++ b/reminder-dashboard/src/components/Sidebar/index.tsx @@ -24,7 +24,7 @@ const SidebarContent = ({ guilds }: ContentProps) => { -