[feat] added copy to bot preset

This commit is contained in:
kwaroran
2023-05-24 09:50:29 +09:00
parent db19f15cb0
commit bd138a1215
2 changed files with 27 additions and 4 deletions

View File

@@ -1,8 +1,8 @@
<script> <script>
import { alertConfirm, alertError } from "../../ts/alert"; import { alertConfirm, alertError } from "../../ts/alert";
import { language } from "../../lang"; import { language } from "../../lang";
import { DataBase, changeToPreset, presetTemplate } from "../../ts/database"; import { DataBase, changeToPreset, copyPreset, presetTemplate } from "../../ts/database";
import { EditIcon, PlusIcon, TrashIcon, XIcon } from "lucide-svelte"; import { CopyIcon, EditIcon, PlusIcon, TrashIcon, XIcon } from "lucide-svelte";
let editMode = false let editMode = false
export let close = () => {} export let close = () => {}
@@ -10,7 +10,7 @@
</script> </script>
<div class="absolute w-full h-full z-40 bg-black bg-opacity-50 flex justify-center items-center"> <div class="absolute w-full h-full z-40 bg-black bg-opacity-50 flex justify-center items-center">
<div class="bg-darkbg p-4 break-any rounded-md flex flex-col max-w-3xl w-96"> <div class="bg-darkbg p-4 break-any rounded-md flex flex-col max-w-3xl w-96 max-h-full overflow-y-auto">
<div class="flex items-center text-neutral-200 mb-4"> <div class="flex items-center text-neutral-200 mb-4">
<h2 class="mt-0 mb-0">{language.presets}</h2> <h2 class="mt-0 mb-0">{language.presets}</h2>
<div class="flex-grow flex justify-end"> <div class="flex-grow flex justify-end">
@@ -35,6 +35,12 @@
<span>{presets.name}</span> <span>{presets.name}</span>
{/if} {/if}
<div class="flex-grow flex justify-end"> <div class="flex-grow flex justify-end">
<button class="text-gray-500 hover:text-green-500 cursor-pointer mr-2" on:click={(e) => {
e.stopPropagation()
copyPreset(i)
}}>
<CopyIcon size={18}/>
</button>
<button class="text-gray-500 hover:text-green-500 cursor-pointer" on:click={async (e) => { <button class="text-gray-500 hover:text-green-500 cursor-pointer" on:click={async (e) => {
e.stopPropagation() e.stopPropagation()
if($DataBase.botPresets.length === 1){ if($DataBase.botPresets.length === 1){

View File

@@ -581,7 +581,7 @@ export function updateTextTheme(){
} }
} }
export function changeToPreset(id =0){ export function saveCurrentPreset(){
let db = get(DataBase) let db = get(DataBase)
let pres = db.botPresets let pres = db.botPresets
pres[db.botPresetsId] = { pres[db.botPresetsId] = {
@@ -607,6 +607,23 @@ export function changeToPreset(id =0){
bias: db.bias bias: db.bias
} }
db.botPresets = pres db.botPresets = pres
DataBase.set(db)
}
export function copyPreset(id:number){
saveCurrentPreset()
let db = get(DataBase)
let pres = db.botPresets
const newPres = cloneDeep(pres[id])
newPres.name += " Copy"
db.botPresets.push(newPres)
DataBase.set(db)
}
export function changeToPreset(id =0){
saveCurrentPreset()
let db = get(DataBase)
let pres = db.botPresets
const newPres = pres[id] const newPres = pres[id]
db.botPresetsId = id db.botPresetsId = id
db.apiType = newPres.apiType ?? db.apiType db.apiType = newPres.apiType ?? db.apiType