Skip to content

Commit 8e2c3b4

Browse files
committed
fix: switching syntax doesn't work
1 parent 06dba0a commit 8e2c3b4

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

app/components/Topbar.vue

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@
55
<div>I want to preview</div>
66

77
<div>
8-
<div class="tooltip tooltip-left" data-tip="Switch syntax">
9-
<select
10-
:value="previewStore.syntax"
11-
class="select select-ghost text-base"
12-
@change="onSyntaxChange"
13-
>
14-
<option :value="Syntax.RST" selected>reStructuredText</option>
15-
<option :value="Syntax.MD">Markdown</option>
16-
</select>
17-
</div>
8+
<TopbarSyntaxSwitcher />
189
</div>
1910

2011
<div>
@@ -57,26 +48,4 @@
5748
</div>
5849
</template>
5950

60-
<script setup lang="ts">
61-
const previewStore = usePreviewStore();
62-
63-
// *** Warn/prevent before syntax switching ********************************************
64-
65-
let previousSyntax = previewStore.syntax;
66-
67-
function onSyntaxChange(event: Event) {
68-
const selectElement = event.target as HTMLSelectElement;
69-
const confirmed = window.confirm(
70-
"Switching a syntax will clear your content. Do you want to continue?",
71-
);
72-
if (confirmed) {
73-
// Switch syntax
74-
const newSyntax = Syntax[selectElement.value as keyof typeof Syntax];
75-
previewStore.syntax = newSyntax;
76-
previousSyntax = newSyntax;
77-
} else {
78-
// Prevent the change by resetting the value
79-
selectElement.value = previousSyntax;
80-
}
81-
}
82-
</script>
51+
<script setup lang="ts"></script>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<template>
2+
<div class="tooltip tooltip-left" data-tip="Switch syntax">
3+
<select
4+
:value="previewStore.syntax"
5+
class="select select-ghost text-base"
6+
@change="onSyntaxChange"
7+
>
8+
<option :value="Syntax.RST" selected>reStructuredText</option>
9+
<option :value="Syntax.MD">Markdown</option>
10+
</select>
11+
</div>
12+
</template>
13+
14+
<script setup lang="ts">
15+
const previewStore = usePreviewStore();
16+
17+
// *** Warn/prevent before syntax switching ********************************************
18+
19+
let previousSyntax = previewStore.syntax;
20+
21+
function onSyntaxChange(event: Event) {
22+
const selectElement = event.target as HTMLSelectElement;
23+
const confirmed = window.confirm(
24+
"Switching a syntax will clear your content. Do you want to continue?",
25+
);
26+
if (confirmed) {
27+
const newSyntax =
28+
Syntax[selectElement.value.toUpperCase() as keyof typeof Syntax];
29+
previewStore.syntax = newSyntax;
30+
previousSyntax = newSyntax;
31+
} else {
32+
// Prevent the change by resetting the value
33+
selectElement.value = previousSyntax;
34+
}
35+
}
36+
</script>

0 commit comments

Comments
 (0)