Skip to content

Commit 8a55013

Browse files
committed
fix: force full re-render of preview when values change (closes #8)
1 parent 486cb85 commit 8a55013

File tree

1 file changed

+85
-78
lines changed
  • src/routes/settings/[guild]/categories/[category]

1 file changed

+85
-78
lines changed

src/routes/settings/[guild]/categories/[category]/+page.svelte

Lines changed: 85 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -352,86 +352,93 @@
352352
bind:value={category.openingMessage}
353353
/>
354354
</label>
355-
{#if category.openingMessage}
356-
<p class="text-sm font-semibold mt-2 mb-1">Preview</p>
357-
<discord-messages
358-
no-background={true}
359-
light-theme={data.theme !== 'dark'}
360-
class="bloc w-full border-0"
361-
>
362-
<discord-message
363-
author={data.client.username}
364-
avatar={data.client.avatar}
365-
bot={true}
366-
timestamp={`Today at ${new Date().toLocaleTimeString('default', {
367-
hour: 'numeric',
368-
minute: 'numeric'
369-
})}`}
370-
class="py-2"
371-
highlight
372-
>
373-
{#if category.pingRoles?.length > 0}
374-
{#each category.pingRoles as id, index}
375-
{@const role = getRole(id)}
376-
{#if role}
377-
{#if index > 0}
378-
{' '}
379-
{/if}
380-
<discord-mention color={role?._hexColor} type="role">
381-
{role?.name}
382-
</discord-mention>
383-
{/if}
384-
{/each}
385-
, <br />
386-
{/if}
387-
<discord-mention highlight>{data.user.username}</discord-mention>
388-
has created a new ticket
389-
<discord-embed
390-
slot="embeds"
391-
color={data.settings.primaryColour}
392-
author-image={`https://cdn.discordapp.com/avatars/${data.user.id}/${data.user.avatar}.webp`}
393-
author-name={data.user.username}
394-
image={category.image}
355+
{#key category.pingRoles}
356+
{#key category.requireTopic}
357+
{#if category.openingMessage}
358+
<p class="text-sm font-semibold mt-2 mb-1">Preview</p>
359+
<discord-messages
360+
no-background={true}
361+
light-theme={data.theme !== 'dark'}
362+
class="bloc w-full border-0"
395363
>
396-
<discord-embed-description slot="description">
397-
{@html marked
398-
.parse(category.openingMessage)
399-
.replace(
400-
/{+\s?(user)?name\s?}+/gi,
401-
`<discord-mention>${data.user.username}</discord-mention>`
402-
)
403-
.replace(/{+\s?avgResponseTime\s?}+/gi, data.guild.stats.avgResponseTime)
404-
.replace(/{+\s?avgResolutionTime\s?}+/gi, data.guild.stats.avgResolutionTime)}
405-
</discord-embed-description>
406-
{#if category.requireTopic}
407-
<discord-embed-fields slot="fields">
408-
<discord-embed-field field-title="Topic">
409-
This is a pretty good preview
410-
</discord-embed-field>
411-
</discord-embed-fields>
412-
{/if}
413-
{#if data.settings.footer}
414-
<discord-embed-footer slot="footer" footer-image={data.client.avatar}>
415-
{data.settings.footer}
416-
</discord-embed-footer>
417-
{/if}
418-
</discord-embed>
419-
<discord-attachments slot="components">
420-
<discord-action-row>
421-
{#if category.requireTopic || category.questions.length > 0}
422-
<discord-button type="secondary">✏️ Edit</discord-button>
423-
{/if}
424-
{#if category.claiming && data.settings.claimButton}
425-
<discord-button type="secondary">🙌 Claim</discord-button>
426-
{/if}
427-
{#if data.settings.closeButton}
428-
<discord-button type="destructive">✖️ Close</discord-button>
364+
<discord-message
365+
author={data.client.username}
366+
avatar={data.client.avatar}
367+
bot={true}
368+
timestamp={`Today at ${new Date().toLocaleTimeString('default', {
369+
hour: 'numeric',
370+
minute: 'numeric'
371+
})}`}
372+
class="py-2"
373+
highlight
374+
>
375+
{#if category.pingRoles?.length > 0}
376+
{#each category.pingRoles as id, index}
377+
{@const role = getRole(id)}
378+
{#if role}
379+
{#if index > 0}
380+
{' '}
381+
{/if}
382+
<discord-mention color={role?._hexColor} type="role">
383+
{role?.name}
384+
</discord-mention>
385+
{/if}
386+
{/each}
387+
, <br />
429388
{/if}
430-
</discord-action-row>
431-
</discord-attachments>
432-
</discord-message>
433-
</discord-messages>
434-
{/if}
389+
<discord-mention highlight>{data.user.username}</discord-mention>
390+
has created a new ticket
391+
<discord-embed
392+
slot="embeds"
393+
color={data.settings.primaryColour}
394+
author-image={`https://cdn.discordapp.com/avatars/${data.user.id}/${data.user.avatar}.webp`}
395+
author-name={data.user.username}
396+
image={category.image}
397+
>
398+
<discord-embed-description slot="description">
399+
{@html marked
400+
.parse(category.openingMessage)
401+
.replace(
402+
/{+\s?(user)?name\s?}+/gi,
403+
`<discord-mention>${data.user.username}</discord-mention>`
404+
)
405+
.replace(/{+\s?avgResponseTime\s?}+/gi, data.guild.stats.avgResponseTime)
406+
.replace(
407+
/{+\s?avgResolutionTime\s?}+/gi,
408+
data.guild.stats.avgResolutionTime
409+
)}
410+
</discord-embed-description>
411+
{#if category.requireTopic}
412+
<discord-embed-fields slot="fields">
413+
<discord-embed-field field-title="Topic">
414+
This is a pretty good preview
415+
</discord-embed-field>
416+
</discord-embed-fields>
417+
{/if}
418+
{#if data.settings.footer}
419+
<discord-embed-footer slot="footer" footer-image={data.client.avatar}>
420+
{data.settings.footer}
421+
</discord-embed-footer>
422+
{/if}
423+
</discord-embed>
424+
<discord-attachments slot="components">
425+
<discord-action-row>
426+
{#if category.requireTopic || category.questions.length > 0}
427+
<discord-button type="secondary">✏️ Edit</discord-button>
428+
{/if}
429+
{#if category.claiming && data.settings.claimButton}
430+
<discord-button type="secondary">🙌 Claim</discord-button>
431+
{/if}
432+
{#if data.settings.closeButton}
433+
<discord-button type="destructive">✖️ Close</discord-button>
434+
{/if}
435+
</discord-action-row>
436+
</discord-attachments>
437+
</discord-message>
438+
</discord-messages>
439+
{/if}
440+
{/key}
441+
{/key}
435442
</div>
436443
<div>
437444
<label class="font-medium">

0 commit comments

Comments
 (0)