Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Link card title to IGDB

  • Loading branch information...
brtjkzl committed Jan 24, 2019
1 parent 85f6459 commit 222b69f8f8c45df38cb7184efb4905ebbb3edc40
@@ -8,6 +8,7 @@ export type Platform = {

export type Game = {
id: number,
url: string,
name: string,
cover: string,
platforms: Platform[],
@@ -0,0 +1,20 @@
// @flow
import * as React from "react";

type Props = {
url: string,
name: string
};

const CardTitle = ({ url, name }: Props) => (
<a
href={url}
target="_blank"
rel="noopener noreferrer"
className="card-title"
>
{name}
</a>
);

export default CardTitle;
@@ -7,6 +7,7 @@ import {
PlatformsDropdown,
CollectionNarrowDropdown
} from "../Dropdown";
import CardTitle from "./CardTitle";
import formatTestId from "ui/utils/formatTestId";
import type { Game } from "types";
import "./card";
@@ -33,7 +34,7 @@ const CollectionCard = ({ game }: Props) => (
distribute="space-between"
className="card-content"
>
<div className="card-title">{game.name}</div>
<CardTitle url={game.url} name={game.name} />
<Stack align="center" distribute="space-between">
<Score value={game.score} votes={game.votes} />
<RatingDropdown gameId={game.id} value={game.rating} />
@@ -7,6 +7,7 @@ import Stack from "../Stack";
import Score from "../Score";
import { SmallButton, SmallInactiveButton } from "../Button";
import { RatingDropdown, CollectionDropdown } from "../Dropdown";
import CardTitle from "./CardTitle";
import formatTestId from "ui/utils/formatTestId";
import type { Game, Platform } from "types";
import "./card";
@@ -62,7 +63,7 @@ const SearchCard = ({ game, setGamePlatforms }: Props) => (
</div>

<div className="card-content">
<div className="card-title">{game.name}</div>
<CardTitle url={game.url} name={game.name} />
<CollectionDropdown gameId={game.id} status={game.status} />
</div>
</div>
@@ -4,7 +4,7 @@ def self.query(query)
"https://api-endpoint.igdb.com/games/",
params: {
search: query,
fields: "name,platforms,cover.cloudinary_id",
fields: "name,platforms,cover.cloudinary_id,url",
limit: 12,
"filter[platforms][any]": "6,48,9,49,12,130"
},
@@ -14,11 +14,12 @@ def self.query(query)

def self.parse(data)
data.select do |game|
game["platforms"] && game["cover"] && game["cover"]["cloudinary_id"]
game["platforms"] && game["cover"] && game["cover"]["cloudinary_id"] && game["url"]
end.map do |game|
{
igdb: game["id"],
name: game["name"],
url: game["url"],
cover: cover(game["cover"]["cloudinary_id"]),
platforms: platforms(game["platforms"])
}
@@ -1,5 +1,5 @@
json.array! @games do |game|
json.(game, :id, :name, :cover)
json.(game, :id, :name, :url, :cover)
json.platforms game.platforms do |platform|
json.(platform, :id, :slug)
end
@@ -1,6 +1,6 @@
json.array! @user_games do |user_game|
game = user_game.game
json.(game, :id, :name, :cover)
json.(game, :id, :name, :url, :cover)
json.platforms game.platforms do |platform|
json.(platform, :id, :slug)
end
@@ -0,0 +1,7 @@
class AddUrlToGames < ActiveRecord::Migration[5.2]
def change
change_table :games do |t|
t.string :url
end
end
end
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_01_22_215028) do
ActiveRecord::Schema.define(version: 2019_01_24_223234) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -21,6 +21,7 @@
t.string "cover"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "url"
end

create_table "games_platforms", id: false, force: :cascade do |t|
@@ -13,7 +13,7 @@ class ApiGamesTest < ActionDispatch::IntegrationTest
assert_not_empty response_body

response_body.each do |game|
assert_equal ["id", "name", "cover", "platforms"], game.keys
assert_equal ["id", "name", "url", "cover", "platforms"], game.keys

game["platforms"].each do |platform|
assert_equal ["id", "slug"], platform.keys
@@ -10,7 +10,7 @@ class ApiUserGamesTest < ActionDispatch::IntegrationTest

assert_not_empty response_body

assert_equal ["id", "name", "cover", "platforms", "rating", "status", "userPlatforms"], response_body.first.keys
assert_equal ["id", "name", "url", "cover", "platforms", "rating", "status", "userPlatforms"], response_body.first.keys
assert_equal ["id", "slug"], response_body.first["platforms"].first.keys
assert_equal "backlog", response_body.first["status"]
assert_equal 8.0, response_body.first["rating"]
@@ -5,6 +5,7 @@
end

igdb { rand(9999..999999) }
url { Faker::Internet.url }
name { Faker::Esport.game }
cover { Faker::Placeholdit.image("249x374", "jpg") }

@@ -7,6 +7,7 @@ class IgdbTest < ActiveSupport::TestCase
expected = [
{
name: "The Witcher 3: Wild Hunt",
url: "https://www.igdb.com/games/the-witcher-3-wild-hunt",
cover:
"https://images.igdb.com/igdb/image/upload/t_cover_big/tri1c6vbydeosoqajwt1.jpg",
platforms: [
@@ -18,6 +19,7 @@ class IgdbTest < ActiveSupport::TestCase
},
{
name: "The Witcher 2: Assassins of Kings",
url: "https://www.igdb.com/games/the-witcher-2-assassins-of-kings",
cover:
"https://images.igdb.com/igdb/image/upload/t_cover_big/mcou7xzxq0qnerehesrh.jpg",
platforms: [
@@ -28,6 +30,7 @@ class IgdbTest < ActiveSupport::TestCase
},
{
name: "The Witcher",
url: "https://www.igdb.com/games/the-witcher",
cover:
"https://images.igdb.com/igdb/image/upload/t_cover_big/nrkdzmkevbbevdvm9bxh.jpg",
platforms: [
@@ -4,6 +4,7 @@ def igdb_games_response_body
{
"id" => 1942,
"name" => "The Witcher 3: Wild Hunt",
"url" => "https://www.igdb.com/games/the-witcher-3-wild-hunt",
"platforms" => [6, 48, 49],
"cover" => {
"cloudinary_id" => "tri1c6vbydeosoqajwt1"
@@ -12,6 +13,7 @@ def igdb_games_response_body
{
"id" => 478,
"name" => "The Witcher 2: Assassins of Kings",
"url" => "https://www.igdb.com/games/the-witcher-2-assassins-of-kings",
"platforms" => [6, 12, 3],
"cover" => {
"cloudinary_id" => "mcou7xzxq0qnerehesrh"
@@ -20,6 +22,7 @@ def igdb_games_response_body
{
"id" => 80,
"name" => "The Witcher",
"url" => "https://www.igdb.com/games/the-witcher",
"platforms" => [6, 0],
"cover" => {
"cloudinary_id" => "nrkdzmkevbbevdvm9bxh"

0 comments on commit 222b69f

Please sign in to comment.
You can’t perform that action at this time.