Compare commits

..

2 commits

11 changed files with 87 additions and 21 deletions

View file

@ -11,7 +11,7 @@
<style> <style>
body { body {
background-color: #f5f5f5; background-color: var(--color-primary);
font-family: var(--font-body), serif; font-family: var(--font-body), serif;
} }

View file

@ -1,5 +1,11 @@
:root { :root {
--color-primary: #000; --color-primary: #f5f5f5;
--color-surface: #fff; --color-surface: #fff;
--font-body: 'Ubuntu', serif; --font-body: 'Ubuntu', serif;
--result-background: #c4c1d2;
--panel-background: #f5f5f5;
--card-background: #c4c1d2;
--color-action-button: #4caf50;
--color-action-button-text: #fff;
--color-error-text: red;
} }

View file

@ -0,0 +1,22 @@
<script lang="ts" setup>
defineProps<{
buttonText: string
}>()
const emit = defineEmits(['action'])
</script>
<template>
<button @click="emit('action')">{{ buttonText }}</button>
</template>
<style scoped>
button {
padding: 0.5rem 1rem;
border-radius: 0.25rem;
background-color: var(--color-action-button);
color: var(--color-action-button-text);
border: none;
cursor: pointer;
}
</style>

View file

@ -12,7 +12,7 @@
<style scoped> <style scoped>
.card { .card {
padding: 2rem; padding: 2rem;
background-color: lightgray; background-color: var(--card-background);
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 0.5rem; border-radius: 0.5rem;
} }

View file

@ -5,6 +5,7 @@ defineProps<{
placeholder: string placeholder: string
buttonText: string buttonText: string
inputName: string inputName: string
inputId?: string
}>() }>()
const emit = defineEmits(['action']) const emit = defineEmits(['action'])
@ -13,7 +14,8 @@ const emit = defineEmits(['action'])
<template> <template>
<div class="form-group"> <div class="form-group">
<input v-model="model" <input :id="inputId"
v-model="model"
:name="inputName" :name="inputName"
:placeholder="placeholder" :placeholder="placeholder"
type="text"> type="text">
@ -24,8 +26,8 @@ const emit = defineEmits(['action'])
<style scoped> <style scoped>
button { button {
background-color: #4caf50; background-color: var(--color-action-button);
color: white; color: var(--color-action-button-text, white);
padding: .5rem 1rem; padding: .5rem 1rem;
border: none; border: none;
border-radius: 0 4px 4px 0; border-radius: 0 4px 4px 0;

View file

@ -55,6 +55,10 @@ const handleLogin = async () => {
gap: 1rem; gap: 1rem;
} }
.error-message {
color: var(--color-error-text, red);
}
.password-form { .password-form {
display: flex; display: flex;
flex-direction: column; flex-direction: column;

View file

@ -50,7 +50,7 @@ form {
} }
.error { .error {
color: red; color: var(--color-error-text, red);
padding: 2em; padding: 2em;
} }
</style> </style>

View file

@ -60,7 +60,7 @@ const handleRegistration = async () => {
} }
.error-message { .error-message {
color: red; color: var(--color-error-text, red);
text-align: center; text-align: center;
} }

View file

@ -79,7 +79,6 @@ dt {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding: 2rem; padding: 2rem;
justify-content: center;
max-width: 40rem; max-width: 40rem;
margin: 0 auto; margin: 0 auto;
} }

View file

@ -2,6 +2,8 @@
import type {MovieSearchResult} from "~/types/movie-search-results"; import type {MovieSearchResult} from "~/types/movie-search-results";
import type {MovieList} from "~/types/movie-list"; import type {MovieList} from "~/types/movie-list";
import type {ResourceResponse} from "@/types/api"; import type {ResourceResponse} from "@/types/api";
import InputAction from "~/components/common/input-action.vue";
import ButtonAction from "~/components/common/button-action.vue";
const emit = defineEmits(['add-movie']); const emit = defineEmits(['add-movie']);
const props = defineProps<{ const props = defineProps<{
@ -9,15 +11,18 @@ const props = defineProps<{
}>() }>()
const searchQuery = ref(""); const searchQuery = ref("");
const errorMessage = ref("");
const movies = ref<MovieSearchResult[]>([]); const movies = ref<MovieSearchResult[]>([]);
const searchMovies = () => { const searchMovies = () => {
$api<ResourceResponse<MovieSearchResult[]>>(`/api/movies/search/${searchQuery.value}`, { $api<ResourceResponse<MovieSearchResult[]>>(`/api/movies/search/${searchQuery.value}`, {
method: "GET" method: "GET"
}).then((response) => { }).then((response) => {
errorMessage.value = "";
movies.value = response.data movies.value = response.data
}).catch((error) => { }).catch((error) => {
alert(error.message) if (error.response.status === 404)
errorMessage.value = "No movies found"
}); });
} }
@ -37,23 +42,27 @@ const addMovieToList = (movie: MovieSearchResult) => {
</script> </script>
<template> <template>
<div> <div class="content">
<h2>Movie Search</h2> <h2>Movie Search</h2>
<form @submit.prevent="searchMovies"> <form @submit.prevent="searchMovies">
<label for="search">Search Movies</label> <label for="search">Search Movies</label>
<InputAction
<div> v-model="searchQuery"
<input id="search" v-model="searchQuery" type="text"/> button-text="Search"
<button>Search</button> input-id="search"
</div> input-name="search"
placeholder="Enter a movie title"
@action="searchMovies"
/>
</form> </form>
<ul class="results-list"> <p v-if="errorMessage" class="error-message">{{ errorMessage }}</p>
<ul v-else class="results-list">
<li v-for="movie in movies" :key="movie.imdbId" class="movie-result"> <li v-for="movie in movies" :key="movie.imdbId" class="movie-result">
<img :src="movie.poster" alt="movie poster"> <img :src="movie.poster" alt="movie poster">
<div class="movie-details"> <div class="movie-details">
<span>{{ movie.title }}</span> <span>{{ movie.title }}</span>
<span>{{ movie.year }}</span> <span>{{ movie.year }}</span>
<button @click="addMovieToList(movie)">Add Movie</button> <ButtonAction button-text="Add Movie" @action="addMovieToList(movie)"/>
</div> </div>
</li> </li>
</ul> </ul>
@ -63,6 +72,22 @@ const addMovieToList = (movie: MovieSearchResult) => {
</template> </template>
<style scoped> <style scoped>
h2 {
margin-bottom: 1rem;
}
label {
margin-bottom: 0.5em;
display: block;
}
.error-message {
color: var(--color-error-text, red);
text-align: center;
margin: 5rem 0;
}
.results-list { .results-list {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -83,9 +108,12 @@ const addMovieToList = (movie: MovieSearchResult) => {
.movie-result { .movie-result {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
border: 1px solid black; border: 1px solid rgba(0, 0, 0, 0.3);
box-shadow: 0 0 0.5em rgba(0, 0, 0, 0.1);
align-items: center; align-items: center;
text-align: center; text-align: center;
border-radius: 0.3rem;
background-color: var(--result-background);
} }
.movie-result img { .movie-result img {
@ -93,4 +121,9 @@ const addMovieToList = (movie: MovieSearchResult) => {
width: 10rem; width: 10rem;
} }
.content {
display: flex;
flex-direction: column;
margin: 0 auto;
}
</style> </style>

View file

@ -37,11 +37,11 @@ const emit = defineEmits<{
right: 0; right: 0;
bottom: 0; bottom: 0;
width: 40%; width: 40%;
background: var(--color-surface, #fff); background: var(--panel-background, #fff);
z-index: 101; z-index: 101;
overflow-y: auto; overflow-y: auto;
padding: 1rem;
box-shadow: -2px 0 8px rgba(0, 0, 0, 0.2); box-shadow: -2px 0 8px rgba(0, 0, 0, 0.2);
padding: 3rem;
} }
.close-button { .close-button {