ChangelogModal.svelte 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <script lang="ts">
  2. import DOMPurify from 'dompurify';
  3. import { onMount, getContext } from 'svelte';
  4. import { Confetti } from 'svelte-confetti';
  5. import { WEBUI_NAME, config, settings } from '$lib/stores';
  6. import { WEBUI_VERSION } from '$lib/constants';
  7. import { getChangelog } from '$lib/apis';
  8. import Modal from './common/Modal.svelte';
  9. import { updateUserSettings } from '$lib/apis/users';
  10. import XMark from '$lib/components/icons/XMark.svelte';
  11. const i18n = getContext('i18n');
  12. export let show = false;
  13. let changelog = null;
  14. const init = async () => {
  15. changelog = await getChangelog();
  16. };
  17. $: if (show) {
  18. init();
  19. }
  20. </script>
  21. <Modal bind:show size="xl">
  22. <div class="px-6 pt-5 dark:text-white text-black">
  23. <div class="flex justify-between items-start">
  24. <div class="text-xl font-medium">
  25. {$i18n.t("What's New in")}
  26. {$WEBUI_NAME}
  27. <Confetti x={[-1, -0.25]} y={[0, 0.5]} />
  28. </div>
  29. <button
  30. class="self-center"
  31. on:click={() => {
  32. localStorage.version = $config.version;
  33. show = false;
  34. }}
  35. aria-label={$i18n.t('Close')}
  36. >
  37. <XMark className={'size-5'}>
  38. <p class="sr-only">{$i18n.t('Close')}</p>
  39. </XMark>
  40. </button>
  41. </div>
  42. <div class="flex items-center mt-1">
  43. <div class="text-sm dark:text-gray-200">{$i18n.t('Release Notes')}</div>
  44. <div class="flex self-center w-[1px] h-6 mx-2.5 bg-gray-50/50 dark:bg-gray-850/50" />
  45. <div class="text-sm dark:text-gray-200">
  46. v{WEBUI_VERSION}
  47. </div>
  48. </div>
  49. </div>
  50. <div class=" w-full p-4 px-5 text-gray-700 dark:text-gray-100">
  51. <div class=" overflow-y-scroll max-h-[30rem] scrollbar-hidden">
  52. <div class="mb-3">
  53. {#if changelog}
  54. {#each Object.keys(changelog) as version}
  55. <div class=" mb-3 pr-2">
  56. <div class="font-semibold text-xl mb-1 dark:text-white">
  57. v{version} - {changelog[version].date}
  58. </div>
  59. <hr class="border-gray-50/50 dark:border-gray-850/50 my-2" />
  60. {#each Object.keys(changelog[version]).filter((section) => section !== 'date') as section}
  61. <div class="w-full">
  62. <div
  63. class="font-semibold uppercase text-xs {section === 'added'
  64. ? 'bg-blue-500/20 text-blue-700 dark:text-blue-200'
  65. : section === 'fixed'
  66. ? 'bg-green-500/20 text-green-700 dark:text-green-200'
  67. : section === 'changed'
  68. ? 'bg-yellow-500/20 text-yellow-700 dark:text-yellow-200'
  69. : section === 'removed'
  70. ? 'bg-red-500/20 text-red-700 dark:text-red-200'
  71. : ''} w-fit rounded-xl px-2 my-2.5"
  72. >
  73. {section}
  74. </div>
  75. <div class="my-2.5 px-1.5 markdown-prose-sm !list-none !w-full !max-w-none">
  76. {#each changelog[version][section] as entry}
  77. <div class="my-2">
  78. {@html DOMPurify.sanitize(entry?.raw)}
  79. </div>
  80. {/each}
  81. </div>
  82. </div>
  83. {/each}
  84. </div>
  85. {/each}
  86. {/if}
  87. </div>
  88. </div>
  89. <div class="flex justify-end pt-3 text-sm font-medium">
  90. <button
  91. on:click={async () => {
  92. localStorage.version = $config.version;
  93. await settings.set({ ...$settings, ...{ version: $config.version } });
  94. await updateUserSettings(localStorage.token, { ui: $settings });
  95. show = false;
  96. }}
  97. class="px-3.5 py-1.5 text-sm font-medium bg-black hover:bg-gray-900 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full"
  98. >
  99. <span class="relative">{$i18n.t("Okay, Let's Go!")}</span>
  100. </button>
  101. </div>
  102. </div>
  103. </Modal>