"src/lib/components/layout/Sidebar/ChatMenu.svelte" did not exist on "099b1d066bd593b3119fb7b0e850627b95548711"
Tools.svelte 2.05 KB
Newer Older
Timothy J. Baek's avatar
Timothy J. Baek committed
1
2
3
4
5
6
7
8
9
<script>
	import { getContext } from 'svelte';

	const i18n = getContext('i18n');

	import CodeEditor from './Tools/CodeEditor.svelte';

	let loading = false;

Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
10
	let name = '';
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
11
12
13
14
15
	let id = '';

	$: if (name) {
		id = name.replace(/\s+/g, '_').toLowerCase();
	}
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
16

Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
17
18
	let codeEditor;

Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
19
	const saveHandler = async () => {
Timothy J. Baek's avatar
Timothy J. Baek committed
20
		loading = true;
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
21
		// Call the API to save the toolkit
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
22

Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
23
24
25
26
		console.log('saveHandler');
	};

	const submitHandler = async () => {
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
27
		if (codeEditor) {
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
28
29
30
31
32
33
			const res = await codeEditor.formatHandler();

			if (res) {
				console.log('Code formatted successfully');
				saveHandler();
			}
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
34
		}
Timothy J. Baek's avatar
Timothy J. Baek committed
35
36
37
38
39
40
	};
</script>

<div class=" flex flex-col justify-between w-full overflow-y-auto h-full">
	<div class="mx-auto w-full md:px-0 h-full">
		<div class=" flex flex-col max-h-[100dvh] h-full">
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
41
42
43
44
			<div class="">
				<div class="flex justify-between items-center">
					<div class=" text-lg font-semibold self-center">{$i18n.t('Tools')}</div>
				</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
45
			</div>
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
46
47
48
49

			<hr class="  dark:border-gray-850 my-2" />

			<div class="flex flex-col flex-1 overflow-auto h-0 rounded-lg">
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
50
				<div class="w-full flex gap-2 mb-2">
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
51
52
					<!-- Toolkit Name Input -->
					<input
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
53
						class="w-full px-3 py-2 text-sm font-medium bg-gray-50 dark:bg-gray-850 dark:text-gray-200 rounded-lg outline-none"
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
54
						type="text"
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
55
						placeholder="Toolkit Name (e.g. My ToolKit)"
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
56
						bind:value={name}
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
57
58
59
60
61
62
63
64
65
						required
					/>

					<input
						class="w-full px-3 py-2 text-sm font-medium bg-gray-50 dark:bg-gray-850 dark:text-gray-200 rounded-lg outline-none"
						type="text"
						placeholder="Toolkit ID (e.g. my_toolkit)"
						bind:value={id}
						required
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
66
67
68
69
					/>
				</div>

				<div class="mb-2 flex-1 overflow-auto h-0 rounded-lg">
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
70
					<CodeEditor bind:this={codeEditor} {saveHandler} />
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
71
72
73
74
75
76
77
78
79
80
81
82
				</div>

				<div class="pb-3 flex justify-end">
					<button
						class="px-3 py-1.5 text-sm font-medium bg-emerald-600 hover:bg-emerald-700 text-gray-50 transition rounded-lg"
						on:click={() => {
							submitHandler();
						}}
					>
						{$i18n.t('Save')}
					</button>
				</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
83
84
85
86
			</div>
		</div>
	</div>
</div>