QoL improvements + Bug fixes

This commit is contained in:
rxdn 2022-06-05 01:53:04 +01:00
parent 1b81a58cb6
commit 5507c4330e
8 changed files with 63 additions and 53 deletions

View File

@ -38,7 +38,7 @@ type panelBody struct {
ImageUrl *string `json:"image_url,omitempty"` ImageUrl *string `json:"image_url,omitempty"`
ThumbnailUrl *string `json:"thumbnail_url,omitempty"` ThumbnailUrl *string `json:"thumbnail_url,omitempty"`
ButtonStyle component.ButtonStyle `json:"button_style,string"` ButtonStyle component.ButtonStyle `json:"button_style,string"`
FormId int `json:"form_id"` FormId *int `json:"form_id"`
} }
func (p *panelBody) IntoPanelMessageData(customId string, isPremium bool) panelMessageData { func (p *panelBody) IntoPanelMessageData(customId string, isPremium bool) panelMessageData {
@ -139,11 +139,6 @@ func CreatePanel(ctx *gin.Context) {
return return
} }
var formId *int
if data.FormId != 0 { // Already validated
formId = &data.FormId
}
// Store in DB // Store in DB
panel := database.Panel{ panel := database.Panel{
MessageId: msgId, MessageId: msgId,
@ -160,7 +155,7 @@ func CreatePanel(ctx *gin.Context) {
ImageUrl: data.ImageUrl, ImageUrl: data.ImageUrl,
ThumbnailUrl: data.ThumbnailUrl, ThumbnailUrl: data.ThumbnailUrl,
ButtonStyle: int(data.ButtonStyle), ButtonStyle: int(data.ButtonStyle),
FormId: formId, FormId: data.FormId,
} }
panelId, err := dbclient.Client.Panel.Create(panel) panelId, err := dbclient.Client.Panel.Create(panel)
@ -405,10 +400,10 @@ func (p *panelBody) verifyButtonStyle() bool {
} }
func (p *panelBody) verifyFormId(guildId uint64) (bool, error) { func (p *panelBody) verifyFormId(guildId uint64) (bool, error) {
if p.FormId == 0 { // TODO: Use nil if p.FormId == nil {
return true, nil return true, nil
} else { } else {
form, ok, err := dbclient.Client.Forms.Get(p.FormId) form, ok, err := dbclient.Client.Forms.Get(*p.FormId)
if err != nil { if err != nil {
return false, err return false, err
} }

View File

@ -142,12 +142,6 @@ func UpdatePanel(ctx *gin.Context) {
} }
} }
// Already validated
var formId *int
if data.FormId != 0 {
formId = &data.FormId
}
// Store in DB // Store in DB
panel := database.Panel{ panel := database.Panel{
PanelId: panelId, PanelId: panelId,
@ -165,7 +159,7 @@ func UpdatePanel(ctx *gin.Context) {
ImageUrl: data.ImageUrl, ImageUrl: data.ImageUrl,
ThumbnailUrl: data.ThumbnailUrl, ThumbnailUrl: data.ThumbnailUrl,
ButtonStyle: int(data.ButtonStyle), ButtonStyle: int(data.ButtonStyle),
FormId: formId, FormId: data.FormId,
} }
if err = dbclient.Client.Panel.Update(panel); err != nil { if err = dbclient.Client.Panel.Update(panel); err != nil {

View File

@ -10,7 +10,7 @@
import {onMount} from "svelte"; import {onMount} from "svelte";
export let label; export let label;
export let panels = []; export let panels;
export let selected; export let selected;
export let isMulti = true; export let isMulti = true;
@ -46,7 +46,7 @@
function applyOverrides() { function applyOverrides() {
if (isMulti) { if (isMulti) {
selected = []; //selected = [];
selectedRaw = panels.filter((p) => selected.includes(p.panel_id)); selectedRaw = panels.filter((p) => selected.includes(p.panel_id));
} else { } else {
if (selectedRaw) { if (selectedRaw) {

View File

@ -16,7 +16,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-3-4"> <div class="col-3-4">
<PanelDropdown label="Panels" bind:panels bind:selected={data.panels} /> <PanelDropdown label="Panels" {panels} bind:selected={data.panels} />
</div> </div>
<div class="col-1-4"> <div class="col-1-4">
@ -55,7 +55,8 @@
import Checkbox from "../form/Checkbox.svelte"; import Checkbox from "../form/Checkbox.svelte";
import Button from "../Button.svelte"; import Button from "../Button.svelte";
export let data = {}; export let data;
$: data, console.log(data);
export let guildId; export let guildId;
export let channels = []; export let channels = [];
@ -63,13 +64,14 @@
export let seedDefault = true; export let seedDefault = true;
if (seedDefault) { if (seedDefault) {
data = { data = {
colour: 0x7289da, colour: 0x7289da,
channels: channels[0].id, channels: channels[0].id,
panels: [], panels: [],
} }
} }
let mounted = false;
let advancedSettings = false; let advancedSettings = false;
let overflowShow = false; let overflowShow = false;
@ -95,9 +97,9 @@
} }
onMount(() => { onMount(() => {
if (!seedDefault) { if (!seedDefault) {
applyOverrides(); applyOverrides();
} }
}) })
</script> </script>

View File

@ -4,7 +4,7 @@
<span slot="title">Edit Multi-Panel</span> <span slot="title">Edit Multi-Panel</span>
<div slot="body" class="body-wrapper"> <div slot="body" class="body-wrapper">
<MultiPanelCreationForm {guildId} {channels} {panels} bind:data seedDefault={false}/> <MultiPanelCreationForm {guildId} {channels} {panels} bind:data seedDefault={false} />
</div> </div>
<div slot="footer"> <div slot="footer">
@ -20,6 +20,8 @@
<div class="modal-backdrop" transition:fade> <div class="modal-backdrop" transition:fade>
</div> </div>
<svelte:window on:keydown={handleKeydown}/>
<script> <script>
import {createEventDispatcher} from 'svelte'; import {createEventDispatcher} from 'svelte';
import {fade} from 'svelte/transition' import {fade} from 'svelte/transition'
@ -42,6 +44,12 @@
function dispatchConfirm() { function dispatchConfirm() {
dispatch('confirm', data); dispatch('confirm', data);
} }
function handleKeydown(e) {
if (e.key === "Escape") {
dispatchClose();
}
}
</script> </script>
<style> <style>

View File

@ -23,7 +23,7 @@
</Dropdown> </Dropdown>
<Dropdown col4=true label="Form" bind:value={data.form_id}> <Dropdown col4=true label="Form" bind:value={data.form_id}>
<option value=0>None</option> <option value=null>None</option>
{#each forms as form} {#each forms as form}
<option value={form.form_id}>{form.title}</option> <option value={form.form_id}>{form.title}</option>
{/each} {/each}
@ -89,21 +89,7 @@
let tempColour = '#2ECC71'; let tempColour = '#2ECC71';
export let data; export let data = {};
if (seedDefault) {
data = {
//title: 'Open a ticket!',
//content: 'By clicking the button, a ticket will be opened for you.',
colour: 0x2ECC71,
emote: '📩',
welcome_message: null,
mentions: [],
default_team: true,
teams: [],
button_style: "1",
form_id: 0,
};
}
export let channels = []; export let channels = [];
export let roles = []; export let roles = [];
@ -196,8 +182,20 @@
updateTeamsItems(); updateTeamsItems();
if (seedDefault) { if (seedDefault) {
data.channel_id = channels.find((c) => c.type === 0).id; data = {
data.category_id = channels.find((c) => c.type === 4).id; //title: 'Open a ticket!',
//content: 'By clicking the button, a ticket will be opened for you.',
colour: 0x2ECC71,
emote: '📩',
welcome_message: null,
mentions: [],
default_team: true,
teams: [],
button_style: "1",
form_id: "null",
channel_id: channels.find((c) => c.type === 0).id,
category_id: channels.find((c) => c.type === 4).id
};
} else { } else {
applyOverrides(); applyOverrides();
} }

View File

@ -20,6 +20,8 @@
<div class="modal-backdrop" transition:fade> <div class="modal-backdrop" transition:fade>
</div> </div>
<svelte:window on:keydown={handleKeydown}/>
<script> <script>
import {createEventDispatcher} from 'svelte'; import {createEventDispatcher} from 'svelte';
import {fade} from 'svelte/transition' import {fade} from 'svelte/transition'
@ -42,14 +44,21 @@
// Dispatch with data // Dispatch with data
function dispatchConfirm() { function dispatchConfirm() {
let mapped = {...panel, form_id: parseInt(panel.form_id)}; let form_id = (panel.form_id === null || panel.form_id === "null") ? null : parseInt(panel.form_id);
let mapped = {...panel, form_id: form_id};
dispatch('confirm', mapped); dispatch('confirm', mapped);
} }
function handleKeydown(e) {
if (e.key === "Escape") {
dispatchClose();
}
}
</script> </script>
<style> <style>
.modal { .modal {
position: fixed; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; width: 100%;

View File

@ -108,10 +108,10 @@
{#if !$loadingScreen} {#if !$loadingScreen}
<div style="margin-top: 10px"> <div style="margin-top: 10px">
<MultiPanelCreationForm {guildId} {channels} bind:panels bind:data={multiPanelCreateData}/> <!--<MultiPanelCreationForm {guildId} {channels} bind:panels bind:data={multiPanelCreateData}/>
<div style="display: flex; justify-content: center; margin-top: 2%"> <div style="display: flex; justify-content: center; margin-top: 2%">
<Button icon="fas fa-paper-plane" fullWidth={true} on:click={createMultiPanel}>Submit</Button> <Button icon="fas fa-paper-plane" fullWidth={true} on:click={createMultiPanel}>Submit</Button>
</div> </div>-->
</div> </div>
{/if} {/if}
</div> </div>
@ -162,6 +162,7 @@
} }
function openMultiEditModal(id) { function openMultiEditModal(id) {
console.log(multiPanels)
multiPanelEditData = multiPanels.find((mp) => mp.id === id); multiPanelEditData = multiPanels.find((mp) => mp.id === id);
multiEditModal = true; multiEditModal = true;
} }
@ -287,8 +288,11 @@
return; return;
} }
// convert button_style to string // convert button_style and form_id to string
panels = res.data.map((p) => Object.assign({}, p, {button_style: p.button_style.toString()})); panels = res.data.map((p) => Object.assign({}, p, {
button_style: p.button_style.toString(),
form_id: p.form_id === null ? "null" : p.form_id
}));
} }
async function loadMultiPanels() { async function loadMultiPanels() {