AddMemoryModal.svelte 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. const dispatch = createEventDispatcher();
  7. export let show;
  8. const i18n = getContext('i18n');
  9. let loading = false;
  10. let content = '';
  11. const submitHandler = async () => {
  12. loading = true;
  13. const res = await addNewMemory(localStorage.token, content).catch((error) => {
  14. toast.error(`${error}`);
  15. return null;
  16. });
  17. if (res) {
  18. console.log(res);
  19. toast.success($i18n.t('Memory added successfully'));
  20. content = '';
  21. show = false;
  22. dispatch('save');
  23. }
  24. loading = false;
  25. };
  26. </script>
  27. <Modal bind:show size="sm">
  28. <div>
  29. <div class=" flex justify-between dark:text-gray-300 px-5 pt-4 pb-2">
  30. <div class=" text-lg font-medium self-center">
  31. {$i18n.t('Add Memory')}
  32. </div>
  33. <button
  34. class="self-center"
  35. on:click={() => {
  36. show = false;
  37. }}
  38. >
  39. <svg
  40. xmlns="http://www.w3.org/2000/svg"
  41. viewBox="0 0 20 20"
  42. fill="currentColor"
  43. class="w-5 h-5"
  44. >
  45. <path
  46. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  47. />
  48. </svg>
  49. </button>
  50. </div>
  51. <div class="flex flex-col md:flex-row w-full px-5 pb-4 md:space-x-4 dark:text-gray-200">
  52. <div class=" flex flex-col w-full sm:flex-row sm:justify-center sm:space-x-6">
  53. <form
  54. class="flex flex-col w-full"
  55. on:submit|preventDefault={() => {
  56. submitHandler();
  57. }}
  58. >
  59. <div class="">
  60. <textarea
  61. bind:value={content}
  62. class=" bg-transparent w-full text-sm resize-none rounded-xl p-3 outline outline-1 outline-gray-100 dark:outline-gray-800"
  63. rows="3"
  64. placeholder={$i18n.t('Enter a detail about yourself for your LLMs to recall')}
  65. />
  66. <div class="text-xs text-gray-500">
  67. ⓘ {$i18n.t('Refer to yourself as "User" (e.g., "User is learning Spanish")')}
  68. </div>
  69. </div>
  70. <div class="flex justify-end pt-1 text-sm font-medium">
  71. <button
  72. 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
  73. ? ' cursor-not-allowed'
  74. : ''}"
  75. type="submit"
  76. disabled={loading}
  77. >
  78. {$i18n.t('Add')}
  79. {#if loading}
  80. <div class="ml-2 self-center">
  81. <svg
  82. class=" w-4 h-4"
  83. viewBox="0 0 24 24"
  84. fill="currentColor"
  85. xmlns="http://www.w3.org/2000/svg"
  86. ><style>
  87. .spinner_ajPY {
  88. transform-origin: center;
  89. animation: spinner_AtaB 0.75s infinite linear;
  90. }
  91. @keyframes spinner_AtaB {
  92. 100% {
  93. transform: rotate(360deg);
  94. }
  95. }
  96. </style><path
  97. d="M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"
  98. opacity=".25"
  99. /><path
  100. d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z"
  101. class="spinner_ajPY"
  102. /></svg
  103. >
  104. </div>
  105. {/if}
  106. </button>
  107. </div>
  108. </form>
  109. </div>
  110. </div>
  111. </div>
  112. </Modal>