General.svelte 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <script lang="ts">
  2. import { getDocs } from '$lib/apis/documents';
  3. import { scanDocs } from '$lib/apis/rag';
  4. import { documents } from '$lib/stores';
  5. import { onMount } from 'svelte';
  6. import toast from 'svelte-french-toast';
  7. export let saveHandler: Function;
  8. let loading = false;
  9. const scanHandler = async () => {
  10. loading = true;
  11. const res = await scanDocs(localStorage.token);
  12. loading = false;
  13. if (res) {
  14. await documents.set(await getDocs(localStorage.token));
  15. toast.success('Scan complete!');
  16. }
  17. };
  18. onMount(async () => {});
  19. </script>
  20. <form
  21. class="flex flex-col h-full justify-between space-y-3 text-sm"
  22. on:submit|preventDefault={() => {
  23. // console.log('submit');
  24. saveHandler();
  25. }}
  26. >
  27. <div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-80">
  28. <div>
  29. <div class=" mb-2 text-sm font-medium">General Settings</div>
  30. <div class=" flex w-full justify-between">
  31. <div class=" self-center text-xs font-medium">Scan for documents from '/data/docs'</div>
  32. <button
  33. class=" self-center text-xs p-1 px-3 bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 rounded flex flex-row space-x-1 items-center {loading
  34. ? ' cursor-not-allowed'
  35. : ''}"
  36. on:click={() => {
  37. scanHandler();
  38. console.log('check');
  39. }}
  40. type="button"
  41. disabled={loading}
  42. >
  43. <div class="self-center font-medium">Scan</div>
  44. <!-- <svg
  45. xmlns="http://www.w3.org/2000/svg"
  46. viewBox="0 0 16 16"
  47. fill="currentColor"
  48. class="w-3 h-3"
  49. >
  50. <path
  51. fill-rule="evenodd"
  52. d="M13.836 2.477a.75.75 0 0 1 .75.75v3.182a.75.75 0 0 1-.75.75h-3.182a.75.75 0 0 1 0-1.5h1.37l-.84-.841a4.5 4.5 0 0 0-7.08.932.75.75 0 0 1-1.3-.75 6 6 0 0 1 9.44-1.242l.842.84V3.227a.75.75 0 0 1 .75-.75Zm-.911 7.5A.75.75 0 0 1 13.199 11a6 6 0 0 1-9.44 1.241l-.84-.84v1.371a.75.75 0 0 1-1.5 0V9.591a.75.75 0 0 1 .75-.75H5.35a.75.75 0 0 1 0 1.5H3.98l.841.841a4.5 4.5 0 0 0 7.08-.932.75.75 0 0 1 1.025-.273Z"
  53. clip-rule="evenodd"
  54. />
  55. </svg> -->
  56. {#if loading}
  57. <div class="ml-3 self-center">
  58. <svg
  59. class=" w-3 h-3"
  60. viewBox="0 0 24 24"
  61. fill="currentColor"
  62. xmlns="http://www.w3.org/2000/svg"
  63. ><style>
  64. .spinner_ajPY {
  65. transform-origin: center;
  66. animation: spinner_AtaB 0.75s infinite linear;
  67. }
  68. @keyframes spinner_AtaB {
  69. 100% {
  70. transform: rotate(360deg);
  71. }
  72. }
  73. </style><path
  74. 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"
  75. opacity=".25"
  76. /><path
  77. 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"
  78. class="spinner_ajPY"
  79. /></svg
  80. >
  81. </div>
  82. {/if}
  83. </button>
  84. </div>
  85. </div>
  86. </div>
  87. <!-- <div class="flex justify-end pt-3 text-sm font-medium">
  88. <button
  89. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  90. type="submit"
  91. >
  92. Save
  93. </button>
  94. </div> -->
  95. </form>