CreateCollection.svelte 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <script>
  2. import { goto } from '$app/navigation';
  3. import { getContext } from 'svelte';
  4. const i18n = getContext('i18n');
  5. import { createNewKnowledge, getKnowledgeItems } from '$lib/apis/knowledge';
  6. import { toast } from 'svelte-sonner';
  7. import { knowledge } from '$lib/stores';
  8. let loading = false;
  9. let name = '';
  10. let description = '';
  11. const submitHandler = async () => {
  12. loading = true;
  13. const res = await createNewKnowledge(localStorage.token, name, description).catch((e) => {
  14. toast.error(e);
  15. });
  16. if (res) {
  17. toast.success($i18n.t('Knowledge created successfully.'));
  18. knowledge.set(await getKnowledgeItems(localStorage.token));
  19. goto(`/workspace/knowledge/${res.id}`);
  20. }
  21. loading = false;
  22. };
  23. </script>
  24. <div class="w-full max-h-full">
  25. <button
  26. class="flex space-x-1"
  27. on:click={() => {
  28. goto('/workspace/knowledge');
  29. }}
  30. >
  31. <div class=" self-center">
  32. <svg
  33. xmlns="http://www.w3.org/2000/svg"
  34. viewBox="0 0 20 20"
  35. fill="currentColor"
  36. class="w-4 h-4"
  37. >
  38. <path
  39. fill-rule="evenodd"
  40. d="M17 10a.75.75 0 01-.75.75H5.612l4.158 3.96a.75.75 0 11-1.04 1.08l-5.5-5.25a.75.75 0 010-1.08l5.5-5.25a.75.75 0 111.04 1.08L5.612 9.25H16.25A.75.75 0 0117 10z"
  41. clip-rule="evenodd"
  42. />
  43. </svg>
  44. </div>
  45. <div class=" self-center font-medium text-sm">{$i18n.t('Back')}</div>
  46. </button>
  47. <form
  48. class="flex flex-col max-w-lg mx-auto mt-10 mb-10"
  49. on:submit|preventDefault={() => {
  50. submitHandler();
  51. }}
  52. >
  53. <div class=" w-full flex flex-col justify-center">
  54. <div class=" text-2xl font-medium font-primary mb-2.5">Create a knowledge base</div>
  55. <div class="w-full flex flex-col gap-2.5">
  56. <div class="w-full">
  57. <div class=" text-sm mb-2">What are you working on?</div>
  58. <div class="w-full mt-1">
  59. <input
  60. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  61. type="text"
  62. bind:value={name}
  63. placeholder={`Name your knowledge base`}
  64. required
  65. />
  66. </div>
  67. </div>
  68. <div>
  69. <div class="text-sm mb-2">What are you trying to achieve?</div>
  70. <div class=" w-full mt-1">
  71. <textarea
  72. class="w-full resize-none rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  73. rows="4"
  74. bind:value={description}
  75. placeholder={`Describe your knowledge base and objectives`}
  76. required
  77. />
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. <div class="flex justify-end mt-2">
  83. <div>
  84. <button
  85. class=" text-sm px-4 py-2 transition rounded-lg {loading
  86. ? ' cursor-not-allowed bg-gray-100 dark:bg-gray-800'
  87. : ' bg-gray-50 hover:bg-gray-100 dark:bg-gray-850 dark:hover:bg-gray-800'} flex"
  88. type="submit"
  89. disabled={loading}
  90. >
  91. <div class=" self-center font-medium">{$i18n.t('Create Knowledge')}</div>
  92. {#if loading}
  93. <div class="ml-1.5 self-center">
  94. <svg
  95. class=" w-4 h-4"
  96. viewBox="0 0 24 24"
  97. fill="currentColor"
  98. xmlns="http://www.w3.org/2000/svg"
  99. ><style>
  100. .spinner_ajPY {
  101. transform-origin: center;
  102. animation: spinner_AtaB 0.75s infinite linear;
  103. }
  104. @keyframes spinner_AtaB {
  105. 100% {
  106. transform: rotate(360deg);
  107. }
  108. }
  109. </style><path
  110. 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"
  111. opacity=".25"
  112. /><path
  113. 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"
  114. class="spinner_ajPY"
  115. /></svg
  116. >
  117. </div>
  118. {/if}
  119. </button>
  120. </div>
  121. </div>
  122. </form>
  123. </div>