AddMemoryModal.svelte 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <script>
  2. import { createEventDispatcher, getContext } from 'svelte';
  3. import Modal from '$lib/components/common/Modal.svelte';
  4. import { addNewMemory, updateMemoryById } from '$lib/apis/memories';
  5. import { toast } from 'svelte-sonner';
  6. import Spinner from '$lib/components/common/Spinner.svelte';
  7. import XMark from '$lib/components/icons/XMark.svelte';
  8. const dispatch = createEventDispatcher();
  9. export let show;
  10. const i18n = getContext('i18n');
  11. let loading = false;
  12. let content = '';
  13. const submitHandler = async () => {
  14. loading = true;
  15. const res = await addNewMemory(localStorage.token, content).catch((error) => {
  16. toast.error(`${error}`);
  17. return null;
  18. });
  19. if (res) {
  20. console.log(res);
  21. toast.success($i18n.t('Memory added successfully'));
  22. content = '';
  23. show = false;
  24. dispatch('save');
  25. }
  26. loading = false;
  27. };
  28. </script>
  29. <Modal bind:show size="sm">
  30. <div>
  31. <div class=" flex justify-between dark:text-gray-300 px-5 pt-4 pb-2">
  32. <div class=" text-lg font-medium self-center">
  33. {$i18n.t('Add Memory')}
  34. </div>
  35. <button
  36. class="self-center"
  37. on:click={() => {
  38. show = false;
  39. }}
  40. >
  41. <XMark className={'size-5'} />
  42. </button>
  43. </div>
  44. <div class="flex flex-col md:flex-row w-full px-5 pb-4 md:space-x-4 dark:text-gray-200">
  45. <div class=" flex flex-col w-full sm:flex-row sm:justify-center sm:space-x-6">
  46. <form
  47. class="flex flex-col w-full"
  48. on:submit|preventDefault={() => {
  49. submitHandler();
  50. }}
  51. >
  52. <div class="">
  53. <textarea
  54. bind:value={content}
  55. class=" bg-transparent w-full text-sm rounded-xl p-3 outline outline-1 outline-gray-100 dark:outline-gray-800"
  56. rows="6"
  57. style="resize: vertical;"
  58. placeholder={$i18n.t('Enter a detail about yourself for your LLMs to recall')}
  59. />
  60. <div class="text-xs text-gray-500">
  61. ⓘ {$i18n.t('Refer to yourself as "User" (e.g., "User is learning Spanish")')}
  62. </div>
  63. </div>
  64. <div class="flex justify-end pt-1 text-sm font-medium">
  65. <button
  66. class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-3xl flex flex-row space-x-1 items-center {loading
  67. ? ' cursor-not-allowed'
  68. : ''}"
  69. type="submit"
  70. disabled={loading}
  71. >
  72. {$i18n.t('Add')}
  73. {#if loading}
  74. <div class="ml-2 self-center">
  75. <Spinner />
  76. </div>
  77. {/if}
  78. </button>
  79. </div>
  80. </form>
  81. </div>
  82. </div>
  83. </div>
  84. </Modal>