show rules on first visit

This commit is contained in:
Ilion Beyst 2022-04-23 11:28:40 +02:00
parent 6a39dc214a
commit 8cda16d1c9
2 changed files with 9 additions and 2 deletions

View file

@ -2,7 +2,7 @@ import defaultBotCode from "../assets/bot_template.txt?raw";
const BOT_CODE_KEY = "bot_code"; const BOT_CODE_KEY = "bot_code";
export function getBotCode() { export function getBotCode(): string {
let botCode = localStorage.getItem(BOT_CODE_KEY); let botCode = localStorage.getItem(BOT_CODE_KEY);
if (!botCode) { if (!botCode) {
botCode = defaultBotCode; botCode = defaultBotCode;
@ -10,6 +10,10 @@ export function getBotCode() {
return botCode; return botCode;
} }
export function hasBotCode(): boolean {
return !!localStorage.getItem(BOT_CODE_KEY);
}
export function saveBotCode(botCode: string) { export function saveBotCode(botCode: string) {
localStorage.setItem(BOT_CODE_KEY, botCode); localStorage.setItem(BOT_CODE_KEY, botCode);
} }

View file

@ -8,7 +8,7 @@
import type { Ace } from "ace-builds"; import type { Ace } from "ace-builds";
import ace from "ace-builds/src-noconflict/ace?client"; import ace from "ace-builds/src-noconflict/ace?client";
import * as AcePythonMode from "ace-builds/src-noconflict/mode-python?client"; import * as AcePythonMode from "ace-builds/src-noconflict/mode-python?client";
import { getBotCode, saveBotCode } from "$lib/bot_code"; import { getBotCode, saveBotCode, hasBotCode } from "$lib/bot_code";
import { debounce } from "$lib/utils"; import { debounce } from "$lib/utils";
import SubmitPane from "$lib/components/SubmitPane.svelte"; import SubmitPane from "$lib/components/SubmitPane.svelte";
import OutputPane from "$lib/components/OutputPane.svelte"; import OutputPane from "$lib/components/OutputPane.svelte";
@ -29,6 +29,9 @@
let editSession: Ace.EditSession; let editSession: Ace.EditSession;
onMount(() => { onMount(() => {
if (!hasBotCode()) {
viewMode = ViewMode.Rules;
}
init_editor(); init_editor();
}); });