This commit is contained in:
Timothy Jaeryang Baek 2025-05-25 02:21:03 +04:00
parent 358ad8ef20
commit f9d374810d

View File

@ -504,9 +504,10 @@
let reader = new FileReader(); let reader = new FileReader();
reader.onload = async (event) => { reader.onload = async (event) => {
try {
let suggestions = JSON.parse(event.target.result); let suggestions = JSON.parse(event.target.result);
promptSuggestions = suggestions.map((s) => { suggestions = suggestions.map((s) => {
if (typeof s.title === 'string') { if (typeof s.title === 'string') {
s.title = [s.title, '']; s.title = [s.title, ''];
} else if (!Array.isArray(s.title)) { } else if (!Array.isArray(s.title)) {
@ -515,14 +516,23 @@
return s; return s;
}); });
promptSuggestions = [...promptSuggestions, ...suggestions];
} catch (error) {
toast.error($i18n.t('Invalid JSON file'));
return;
}
}; };
reader.readAsText(files[0]); reader.readAsText(files[0]);
e.target.value = ''; // Reset the input value
}} }}
/> />
<button <button
class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition" class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition"
type="button"
on:click={() => { on:click={() => {
const input = document.getElementById('prompt-suggestions-import-input'); const input = document.getElementById('prompt-suggestions-import-input');
if (input) { if (input) {
@ -553,6 +563,7 @@
{#if promptSuggestions.length} {#if promptSuggestions.length}
<button <button
class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition" class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition"
type="button"
on:click={async () => { on:click={async () => {
let blob = new Blob([JSON.stringify(promptSuggestions)], { let blob = new Blob([JSON.stringify(promptSuggestions)], {
type: 'application/json' type: 'application/json'