working on editing reminders

This commit is contained in:
jude 2022-03-20 00:10:19 +00:00
parent a56f84f659
commit 3b6e02e16e
4 changed files with 81 additions and 4 deletions

View File

@ -19,7 +19,8 @@ use crate::{
MAX_URL_LENGTH, MAX_USERNAME_LENGTH, MIN_INTERVAL,
},
routes::dashboard::{
create_database_channel, generate_uid, name_default, DeleteReminder, Reminder,
create_database_channel, generate_uid, name_default, DeleteReminder, PatchReminder,
Reminder,
},
};
@ -351,11 +352,17 @@ WHERE
#[patch("/api/guild/<id>/reminders", data = "<reminder>")]
pub async fn edit_reminder(
id: u64,
reminder: Json<Reminder>,
reminder: Json<PatchReminder>,
serenity_context: &State<Context>,
pool: &State<Pool<MySql>>,
) -> JsonValue {
json!({"error": "Not implemented"})
if let Some(enabled) = reminder.enabled {
sqlx::query!("UPDATE reminders SET enabled = ? WHERE uid = ?", enabled, reminder.uid)
.execute(pool.inner())
.await;
}
json!({})
}
#[delete("/api/guild/<id>/reminders", data = "<reminder>")]

View File

@ -16,6 +16,8 @@ use crate::{
pub mod guild;
pub mod user;
type Unset<T> = Option<T>;
fn name_default() -> String {
"Reminder".to_string()
}
@ -52,6 +54,57 @@ pub struct Reminder {
utc_time: NaiveDateTime,
}
#[derive(Deserialize)]
pub struct PatchReminder {
uid: String,
#[serde(default)]
attachment: Unset<Option<Vec<u8>>>,
#[serde(default)]
attachment_name: Unset<Option<String>>,
#[serde(default)]
avatar: Unset<Option<String>>,
#[serde(default)]
content: Unset<String>,
#[serde(default)]
embed_author: Unset<String>,
#[serde(default)]
embed_author_url: Unset<Option<String>>,
#[serde(default)]
embed_color: Unset<u32>,
#[serde(default)]
embed_description: Unset<String>,
#[serde(default)]
embed_footer: Unset<String>,
#[serde(default)]
embed_footer_url: Unset<Option<String>>,
#[serde(default)]
embed_image_url: Unset<Option<String>>,
#[serde(default)]
embed_thumbnail_url: Unset<Option<String>>,
#[serde(default)]
embed_title: Unset<String>,
#[serde(default)]
enabled: Unset<bool>,
#[serde(default)]
expires: Unset<Option<NaiveDateTime>>,
#[serde(default)]
interval_seconds: Unset<Option<u32>>,
#[serde(default)]
interval_months: Unset<Option<u32>>,
#[serde(default)]
name: Unset<String>,
#[serde(default)]
pin: Unset<bool>,
#[serde(default)]
restartable: Unset<bool>,
#[serde(default)]
tts: Unset<bool>,
#[serde(default)]
username: Unset<Option<String>>,
#[serde(default)]
utc_time: Unset<NaiveDateTime>,
}
pub fn generate_uid() -> String {
let mut generator: OsRng = Default::default();

View File

@ -138,6 +138,8 @@ async function fetch_reminders(guild_id) {
for (let reminder of data) {
let newFrame = $template.content.cloneNode(true);
newFrame.querySelector('.reminderContent').dataset.uid = reminder['uid'];
// populate channels
set_channels(newFrame.querySelector('select.channel-selector'))
@ -155,6 +157,21 @@ async function fetch_reminders(guild_id) {
}
}
let guild = document.querySelector('.guildList a.is-active').dataset['guild'];
let $enableBtn = newFrame.querySelector('.disable-enable');
$enableBtn.textContent = reminder['enabled'] ? 'Disable' : 'Enable';
$enableBtn.addEventListener('click', () => {
fetch(`/dashboard/api/guild/${guild}/reminders`, {
method: 'PATCH',
body: JSON.stringify({
uid: reminder['uid'],
enabled: false
})
})
})
let timeInput = newFrame.querySelector('input[name="time"]');
let localTime = luxon.DateTime.fromISO(reminder["utc_time"]).setZone(timezone);
timeInput.value = localTime.toFormat("yyyy-LL-dd'T'HH:mm:ss");

View File

@ -204,7 +204,7 @@
<button class="button is-primary" disabled>
Saved!
</button>
<button class="button is-warning">
<button class="button is-warning disable-enable">
Disable
</button>
<button class="button is-danger">