Skip to content

Commit

Permalink
chore: standardized use of isSearchModalOpen from vuex store rather t…
Browse files Browse the repository at this point in the history
…han local variables
  • Loading branch information
Bobinstein committed Apr 22, 2024
1 parent 2e9fa85 commit 2fb2cc8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/src/.vuepress/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export default new Vuex.Store({
},
mutations: {
openSearchModal(state) {
// console.log("opening modal")
state.isSearchModalOpen = true;
},
closeSearchModal(state) {
// console.log("closing modal")
state.isSearchModalOpen = false;
},
toggleLightMode(state) {
Expand Down
10 changes: 7 additions & 3 deletions docs/src/.vuepress/theme/components/SearchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export default {
return this.$site.themeConfig.searchPlaceholder || "";
},
isModalOpen() {
return this.$store.state.isSearchModalOpen;
},
showSuggestions() {
return this.focused && this.suggestions && this.suggestions.length;
},
Expand Down Expand Up @@ -185,7 +189,7 @@ export default {
onEscapeKey(event) {
if (event.key === "Escape" || event.keyCode === 27) {
this.$emit("close-modal");
this.$store.commit("closeSearchModal");
}
},
Expand All @@ -211,7 +215,7 @@ export default {
}, 200);
},
openModal() {
this.$emit("open-search-modal");
this.$store.commit("openSearchModal");
},
getPageLocalePath(page) {
Expand Down Expand Up @@ -271,7 +275,7 @@ export default {
this.$router.push(this.suggestions[i].path);
this.query = "";
this.focusIndex = 0;
this.$emit("close-modal");
this.$store.commit("closeSearchModal");
},
focus(i) {
Expand Down
6 changes: 1 addition & 5 deletions docs/src/.vuepress/theme/layouts/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export default {
data() {
return {
isSidebarOpen: false,
showSearchModal: false,
};
},
Expand Down Expand Up @@ -155,7 +154,7 @@ export default {
event.preventDefault(); // Prevent default behavior
// Check if modal is already open and toggle accordingly
if (this.showSearchModal) {
if (this.isSearchModalOpen) {
this.closeSearchModal();
} else {
this.openSearchModal();
Expand All @@ -167,11 +166,8 @@ export default {
},
openSearchModal() {
this.$store.commit('openSearchModal');
this.showSearchModal = true;
},
closeSearchModal() {
console.log("close modal")
this.showSearchModal = false;
this.$store.commit('closeSearchModal');
},
Expand Down

0 comments on commit 2fb2cc8

Please sign in to comment.