Skip to content

Commit 3a1d8b8

Browse files
fix: Remove remaining stateful mutations
1 parent 2cc340d commit 3a1d8b8

File tree

1 file changed

+15
-9
lines changed
  • EssentialCSharp.Web/wwwroot/js

1 file changed

+15
-9
lines changed

EssentialCSharp.Web/wwwroot/js/site.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
markRaw,
77
watch,
88
computed,
9-
watchEffect
109
} from "vue";
1110
import { useWindowSize } from "vue-window-size";
1211

@@ -240,7 +239,6 @@ const app = createApp({
240239

241240
const filteredTocData = computed(() => {
242241
if (!searchQuery.value) {
243-
expandedTocs.clear();
244242
return tocData;
245243
}
246244
const query = normalizeString(searchQuery.value);
@@ -256,15 +254,23 @@ const app = createApp({
256254
return matches;
257255
}
258256

259-
watchEffect(() => {
260-
expandedTocs.clear();
261-
const query = normalizeString(searchQuery.value);
262-
tocData.forEach(item => {
263-
if (filterItem(item, query)) {
257+
watch(searchQuery, (newQuery) => {
258+
if (!newQuery) {
259+
expandedTocs.clear();
260+
// If a search query is removed, open the TOC for the current page.
261+
for (const item of currentPage) {
264262
expandedTocs.add(item.key);
265-
console.log("Added ", item.key);
266263
}
267-
});
264+
}
265+
else {
266+
expandedTocs.clear();
267+
const query = normalizeString(newQuery);
268+
tocData.forEach(item => {
269+
if (filterItem(item, query)) {
270+
expandedTocs.add(item.key);
271+
}
272+
});
273+
}
268274
});
269275

270276
function normalizeString(str) {

0 commit comments

Comments
 (0)