Fix DM reminders trying to load guild data

This commit is contained in:
jude 2024-06-06 16:56:19 +01:00
parent 5e82a687f9
commit 8881ef0f85
8 changed files with 42 additions and 11 deletions

2
Cargo.lock generated
View File

@ -2431,7 +2431,7 @@ checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56"
[[package]] [[package]]
name = "reminder-rs" name = "reminder-rs"
version = "1.7.19" version = "1.7.20"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"chrono", "chrono",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "reminder-rs" name = "reminder-rs"
version = "1.7.19" version = "1.7.20"
authors = ["Jude Southworth <judesouthworth@pm.me>"] authors = ["Jude Southworth <judesouthworth@pm.me>"]
edition = "2021" edition = "2021"
license = "AGPL-3.0 only" license = "AGPL-3.0 only"

View File

@ -7,6 +7,10 @@ import { useGuild } from "./useGuild";
export const Mentions = ({ input }) => { export const Mentions = ({ input }) => {
const guild = useGuild(); const guild = useGuild();
return <>{guild && <_Mentions guild={guild} input={input} />}</>;
};
const _Mentions = ({ guild, input }) => {
const { data: roles } = useQuery(fetchGuildRoles(guild)); const { data: roles } = useQuery(fetchGuildRoles(guild));
const { data: channels } = useQuery(fetchGuildChannels(guild)); const { data: channels } = useQuery(fetchGuildChannels(guild));
const { data: emojis } = useQuery(fetchGuildEmojis(guild)); const { data: emojis } = useQuery(fetchGuildEmojis(guild));

View File

@ -45,6 +45,37 @@ function defaultReminder(): Reminder {
export const CreateReminder = () => { export const CreateReminder = () => {
const guild = useGuild(); const guild = useGuild();
if (guild) {
return <_Guild guild={guild} />;
} else {
return <_User />;
}
};
const _User = () => {
const [reminder, setReminder] = useState(defaultReminder());
const [collapsed, setCollapsed] = useState(false);
return (
<ReminderContext.Provider value={[reminder, setReminder]}>
<div class={collapsed ? "reminderContent is-collapsed" : "reminderContent"}>
<TopBar
isCreating={true}
toggleCollapsed={() => {
setCollapsed(!collapsed);
}}
/>
<div class="columns reminder-settings">
<Message />
<Settings />
</div>
<CreateButtonRow />
</div>
</ReminderContext.Provider>
);
};
const _Guild = ({ guild }) => {
const [reminder, setReminder] = useState(defaultReminder()); const [reminder, setReminder] = useState(defaultReminder());
const [collapsed, setCollapsed] = useState(false); const [collapsed, setCollapsed] = useState(false);

View File

@ -53,7 +53,7 @@ export const TimezonePicker = () => {
const TimezoneModal = ({ setModalOpen }) => { const TimezoneModal = ({ setModalOpen }) => {
const browserTimezone = DateTime.now().zoneName; const browserTimezone = DateTime.now().zoneName;
const [selectedZone, setSelectedZone] = useTimezone(); const [selectedZone] = useTimezone();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const { isLoading, isError, data } = useQuery(fetchUserInfo()); const { isLoading, isError, data } = useQuery(fetchUserInfo());

View File

@ -11,12 +11,7 @@ enum Sort {
} }
export const UserReminders = () => { export const UserReminders = () => {
const { const { isSuccess, isFetching, isFetched, data: reminders } = useQuery(fetchUserReminders());
isSuccess,
isFetching,
isFetched,
data: guildReminders,
} = useQuery(fetchUserReminders());
const [collapsed, setCollapsed] = useState(false); const [collapsed, setCollapsed] = useState(false);
const [sort, setSort] = useState(Sort.Time); const [sort, setSort] = useState(Sort.Time);
@ -85,7 +80,7 @@ export const UserReminders = () => {
<div id={"guildReminders"} className={isFetching ? "loading" : ""}> <div id={"guildReminders"} className={isFetching ? "loading" : ""}>
{isSuccess && {isSuccess &&
guildReminders reminders
.sort((r1, r2) => { .sort((r1, r2) => {
if (sort === Sort.Time) { if (sort === Sort.Time) {
return r1.utc_time > r2.utc_time ? 1 : -1; return r1.utc_time > r2.utc_time ? 1 : -1;

View File

@ -52,6 +52,7 @@ async fn _initialize(ctx: Context, pool: impl Executor<'_, Database = Database>
for reminder in reminders { for reminder in reminders {
reminder.send(pool, ctx.clone()).await; reminder.send(pool, ctx.clone()).await;
let _ = sd_notify::notify(false, &[NotifyState::Watchdog]);
} }
} }

View File

@ -9,7 +9,7 @@ WorkingDirectory=/etc/reminder-rs
Restart=always Restart=always
RestartSec=10 RestartSec=10
Environment="reminder_rs=warn,postman=warn" Environment="reminder_rs=warn,postman=warn"
WatchdogSec=600 WatchdogSec=120
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target