persist saved bot name
This commit is contained in:
parent
c43839f471
commit
41f1679ef4
2 changed files with 13 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
import defaultBotCode from "../assets/bot_template.txt?raw";
|
import defaultBotCode from "../assets/bot_template.txt?raw";
|
||||||
|
|
||||||
const BOT_CODE_KEY = "bot_code";
|
const BOT_CODE_KEY = "bot_code";
|
||||||
|
const BOT_NAME_KEY = "bot_name";
|
||||||
|
|
||||||
export function getBotCode(): string {
|
export function getBotCode(): string {
|
||||||
let botCode = localStorage.getItem(BOT_CODE_KEY);
|
let botCode = localStorage.getItem(BOT_CODE_KEY);
|
||||||
|
@ -17,3 +18,11 @@ export function hasBotCode(): boolean {
|
||||||
export function saveBotCode(botCode: string) {
|
export function saveBotCode(botCode: string) {
|
||||||
localStorage.setItem(BOT_CODE_KEY, botCode);
|
localStorage.setItem(BOT_CODE_KEY, botCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getBotName(): string | null {
|
||||||
|
return localStorage.getItem(BOT_NAME_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveBotName(name: string) {
|
||||||
|
localStorage.setItem(BOT_NAME_KEY, name);
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { get_session_token } from "$lib/auth";
|
import { get_session_token } from "$lib/auth";
|
||||||
|
import { getBotName, saveBotName } from "$lib/bot_code";
|
||||||
|
|
||||||
import { currentUser } from "$lib/stores/current_user";
|
import { currentUser } from "$lib/stores/current_user";
|
||||||
import { createEventDispatcher, onMount } from "svelte";
|
import { createEventDispatcher, onMount } from "svelte";
|
||||||
|
@ -14,6 +15,8 @@
|
||||||
let saveErrors: string[] = [];
|
let saveErrors: string[] = [];
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
botName = getBotName();
|
||||||
|
|
||||||
const res = await fetch("/api/bots", {
|
const res = await fetch("/api/bots", {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@ -68,6 +71,7 @@
|
||||||
let responseData = await response.json();
|
let responseData = await response.json();
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
dispatch("botSaved", responseData);
|
dispatch("botSaved", responseData);
|
||||||
|
saveBotName(botName);
|
||||||
// clear errors
|
// clear errors
|
||||||
saveErrors = [];
|
saveErrors = [];
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue