Skip to content

Commit 0b9bb95

Browse files
committed
feat: Implement page switching
- When the user clicks on a "View Guide" button in the Search Page, the app switches to the Guide Page and displays the contents of the guide. - When the user clicks on the "Close Guide" button in the Guide Page, the app switches back to the Search Page. Note: I must explicitly close component tags (<page-guide></page-guide>) because using self-closing tags (<page-guide />) breaks v-if logic. For more information on this issue, see: - https://vuejs.org/v2/style-guide/#Self-closing-components-strongly-recommended - vuejs/eslint-plugin-vue#29
1 parent afab8c0 commit 0b9bb95

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

index.html

+10-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@
2121
<body>
2222
<div id="app">
2323
<h1 class="logo">RiftGuide</h1>
24-
<page-guide :guide="currentGuide" />
24+
<page-search
25+
v-if="currentPage === 'search'"
26+
:guides="guides"
27+
@guide-open="openPageGuide($event)"
28+
></page-search>
29+
<page-guide
30+
v-if="currentPage === 'guide'"
31+
:guide="currentGuide"
32+
@guide-close="openPageSearch"
33+
/></page-guide>
2534
</div>
2635

2736
<template id="template-page-guide">

js/app.js

+20
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ const vm = new Vue({
77
el: "#app",
88
data: {
99
currentGuide: guides[0],
10+
currentPage: "search",
1011
guides: guides,
1112
},
13+
methods: {
14+
/**
15+
* Switches to the Guide Page, opening the guide with the given ID.
16+
* @param {string} guideId
17+
*/
18+
openPageGuide(guideId) {
19+
const guideToView = this.guides.find((guide) => guide.id === guideId);
20+
if (!guideToView)
21+
throw new Error(`Cannot find guide with ID: '${guideId}'`);
22+
this.currentGuide = guideToView;
23+
this.currentPage = "guide";
24+
},
25+
/**
26+
* Switches to the Search Page.
27+
*/
28+
openPageSearch() {
29+
this.currentPage = "search";
30+
},
31+
},
1232
});

0 commit comments

Comments
 (0)