Skip to content

Commit e29774e

Browse files
committed
feat: rename template
1 parent 1b2ecce commit e29774e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/routes/templates/+page.svelte

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
return;
4040
}
4141
await api.updateTemplate(newName, data.content);
42+
loadTemplates();
4243
} catch (err) {
4344
console.error(err);
4445
alert(`복제 실행 중 오류 발생: ${err}`);
@@ -74,6 +75,28 @@
7475
alert(`새 템플릿 생성 중 오류 발생: ${err}`);
7576
}
7677
}
78+
79+
// 템플릿 이름변경
80+
async function renameTemplate(originalName) {
81+
const newName = prompt(
82+
"변경할 템플릿 이름을 입력하세요:",
83+
originalName,
84+
);
85+
if (!newName) return;
86+
if (templates.includes(newName)) {
87+
alert("이미 해당 이름의 템플릿이 존재합니다.");
88+
return;
89+
}
90+
try {
91+
const data = await api.fetchTemplate(originalName);
92+
await api.updateTemplate(newName, data.content);
93+
await api.deleteTemplate(originalName);
94+
loadTemplates();
95+
} catch (err) {
96+
console.error(err);
97+
alert(`이름 변경 중 오류 발생: ${err}`);
98+
}
99+
}
77100
</script>
78101

79102
<svelte:head>
@@ -104,6 +127,12 @@
104127
>
105128
{tpl}
106129
</a>
130+
<button
131+
on:click={() => renameTemplate(tpl)}
132+
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-1 px-2 rounded"
133+
>
134+
Rename
135+
</button>
107136
<button
108137
on:click={() => duplicateTemplate(tpl)}
109138
class="bg-yellow-500 hover:bg-yellow-700 text-white font-bold py-1 px-2 rounded"

0 commit comments

Comments
 (0)