Skip to content

Commit

Permalink
GetAlbum UI shows error msg, add example input at SearchAlbum SearchA…
Browse files Browse the repository at this point in the history
…rtist UI
  • Loading branch information
yennanliu committed Oct 1, 2024
1 parent ff552fe commit e9cd5a5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- Album ID Form -->
<form class="album-form text-center">
<div class="form-group">
<p style="text-align: center;">Enter Album ID, example: 1VuIx4XMmSs1hGZk2uCzvO</p><br>
<label for="albumId" class="form-label">Enter Album ID</label>
<input
type="text"
Expand All @@ -17,8 +18,13 @@
</button>
</form>

<!-- Error message -->
<div v-if="fetchAlbumError" class="error-message text-center" style="color: red;">
{{ fetchAlbumError }}
</div>

<!-- Album Details -->
<div v-if="album" class="album-details mt-5">
<div v-if="album && !fetchAlbumError" class="album-details mt-5">
<h1 class="album-title">
Album: {{ album.name }} | Artist: {{ album.artists[0].name }}
</h1>
Expand Down Expand Up @@ -70,21 +76,23 @@
</div>

<!-- Loading Placeholder -->
<div v-else class="loading-text text-center mt-5">Loading...</div>
<div v-else-if="!fetchAlbumError" class="loading-text text-center mt-5">Loading...</div>
</div>
</template>

<script>
export default {
data() {
return {
albumId: "1VuIx4XMmSs1hGZk2uCzvO", // default val
albumId: "1VuIx4XMmSs1hGZk2uCzvO", // default value
album: null,
fetchAlbumError: null // Error message state
};
},
methods: {
async fetchAlbum() {
try {
this.fetchAlbumError = null; // Reset error state
const response = await fetch(
`http://localhost:8888/album/${this.albumId}`
);
Expand All @@ -96,6 +104,8 @@ export default {
console.log("this.album =", JSON.stringify(this.album));
} catch (error) {
console.error(error);
this.fetchAlbumError = error.message; // Set error message
this.album = null; // Clear album data on error
}
},
},
Expand Down Expand Up @@ -133,6 +143,13 @@ export default {
margin-top: 30px;
}
/* Error message styling */
.error-message {
font-size: 1.2rem;
color: red;
margin-top: 10px;
}
/* Album image styling */
.album-cover {
max-width: 400px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- Album Keyword Form -->
<form class="album-form text-center">
<div class="form-group">
<p style="text-align: center;">Search Album with keyword, example: funcky</p><br>
<label for="albumKeyword" class="form-label">Enter Album keyword</label>
<input
type="text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- Artist Keyword Form -->
<form class="album-form text-center">
<div class="form-group">
<p style="text-align: center;">Search Artist with keyword, example: jay</p><br>
<label for="artistKeyword" class="form-label">Enter Artist keyword</label>
<input
type="text"
Expand Down

0 comments on commit e9cd5a5

Please sign in to comment.