Skip to content

Commit

Permalink
add game card component and update example env
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonWingerAir committed Jan 15, 2024
1 parent 7c8b68a commit 5decbe2
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
NUXT_APP_BASE_URL='/OPTIONAL_BASE_URL'

EXTERNAL_API_KEY=YOUR_API_KEY
API_BASE_URL=YOUR_BASE_URL
34 changes: 34 additions & 0 deletions components/GameCard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<template>
<div class="h-128 w-64 border flex flex-col text-center">
<div class="mb-5 bg-transparent hover:bg-gray-200 inline-block">
<img
:src="imgPath"
alt="Game Artwork"
class="transform hover:translate-x-6 hover:-translate-y-6 delay-50 duration-100 inline-block"
/>
</div>
<div class="text-lg">
{{ game?.name }}
</div>
<p class="text-m text-gray-500 break-words text-wrap truncate overflow-hidden px-2">
{{ game?.summary }}
</p>
</div>
</template>

<script setup lang="ts">
import type { PropType } from 'vue';
import type { Game } from '../types/Game';
import { computed } from 'vue';
const props = defineProps({
game: {
type: Object as PropType<Game>
}
});
const config = useRuntimeConfig();
const imgPath = computed(() => props.game?.image.original_url != null ? `${config.public.imgBaseUrl}${props.game.image.original_url}` : 'https://via.placeholder.com/300x500');
</script>
5 changes: 4 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export default defineNuxtConfig({
],
runtimeConfig: {
apiKey: process.env.EXTERNAL_API_KEY,
apiBaseUrl: process.env.API_BASE_URL
apiBaseUrl: process.env.API_BASE_URL,
public: {
imgBaseUrl: ''
}
}
})
9 changes: 6 additions & 3 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@
</div>
<div class="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 self-center gap-x-10 gap-y-10 mb-10">
<div v-for="game in data?.results">
{{ game.name }}
<GameCard :game="game"></GameCard>
</div>
</div>
</div>
</div>
</template>

<script setup lang="ts">
import type { ApiResponse } from '~/types/ApiResponse';
import type { Response } from '~/types/Response';
const searchTerm = ref('');
const url = computed(() => {
return `api/games/search?query=${searchTerm.value}`;
});
const { data } = await useFetch<ApiResponse>(url);
const { data } = await useFetch<Response>(url);
console.log(data);
</script>
4 changes: 3 additions & 1 deletion types/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ export type Game = {
release_date: string;
aliases: string | null;
summary: string;
screenshot_path: string;
image: {
original_url: string;
};
}
2 changes: 1 addition & 1 deletion types/ApiResponse.ts → types/Response.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Game } from "./Game";

export type ApiResponse = {
export type Response = {
page: number;
results: Game[];
total_pages: number;
Expand Down

0 comments on commit 5decbe2

Please sign in to comment.