From d2ad5924bce17e3b07ee0af86a8739559dac3b35 Mon Sep 17 00:00:00 2001 From: realtradam Date: Wed, 15 May 2024 00:44:53 -0400 Subject: begin implementing game file upload and also styling --- .byebug_history | 10 ++ Gemfile | 5 + Gemfile.lock | 2 + app/assets/stylesheets/application.css | 0 app/assets/stylesheets/application.tailwind.css | 50 +++++++++- app/controllers/api/v1/games_controller.rb | 18 ++++ app/controllers/api/v1/users_controller.rb | 4 + app/helpers/api/v1/games_helper.rb | 2 + app/javascript/components/Button.jsx | 15 +++ app/javascript/components/Home.jsx | 42 ++++++-- app/javascript/components/Layout.jsx | 39 ++++++-- app/models/game.rb | 8 ++ app/models/user.rb | 1 + app/views/layouts/application.html.erb | 12 +++ config/routes.rb | 9 ++ config/tailwind.config.js | 43 +++++---- db/migrate/20240509225147_create_games.rb | 12 +++ db/schema.rb | 8 +- package.json | 2 +- public/img/star.png | Bin 0 -> 6001 bytes public/img/star.svg | 117 +++++++++++++++++++++++ test/controllers/api/v1/games_controller_test.rb | 7 ++ test/fixtures/games.yml | 13 +++ test/models/game_test.rb | 7 ++ yarn.lock | 11 +-- 25 files changed, 388 insertions(+), 49 deletions(-) create mode 100644 .byebug_history create mode 100644 app/assets/stylesheets/application.css create mode 100644 app/controllers/api/v1/games_controller.rb create mode 100644 app/helpers/api/v1/games_helper.rb create mode 100644 app/javascript/components/Button.jsx create mode 100644 app/models/game.rb create mode 100644 db/migrate/20240509225147_create_games.rb create mode 100644 public/img/star.png create mode 100644 public/img/star.svg create mode 100644 test/controllers/api/v1/games_controller_test.rb create mode 100644 test/fixtures/games.yml create mode 100644 test/models/game_test.rb diff --git a/.byebug_history b/.byebug_history new file mode 100644 index 0000000..3bfc71a --- /dev/null +++ b/.byebug_history @@ -0,0 +1,10 @@ +continue +q +next +q +out +next +q +next +n +step diff --git a/Gemfile b/Gemfile index f7a8210..d000904 100644 --- a/Gemfile +++ b/Gemfile @@ -44,6 +44,9 @@ gem "tzinfo-data", platforms: %i[ windows jruby ] # Reduces boot times through caching; required in config/boot.rb gem "bootsnap", require: false +# Uploading files +#gem 'rack-cors' + # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" @@ -56,6 +59,8 @@ group :development do # Use console on exceptions pages [https://github.com/rails/web-console] gem "web-console" + gem 'byebug', '~> 11.1', '>= 11.1.1' + # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] # gem "rack-mini-profiler" diff --git a/Gemfile.lock b/Gemfile.lock index e48bb45..1e1987f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -83,6 +83,7 @@ GEM bootsnap (1.18.3) msgpack (~> 1.2) builder (3.2.4) + byebug (11.1.3) capybara (3.40.0) addressable matrix @@ -265,6 +266,7 @@ PLATFORMS DEPENDENCIES bootsnap + byebug (~> 11.1, >= 11.1.1) capybara cssbundling-rails debug diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.css index 8666d2f..c6f1a68 100644 --- a/app/assets/stylesheets/application.tailwind.css +++ b/app/assets/stylesheets/application.tailwind.css @@ -5,9 +5,53 @@ /* @layer components { - .btn-primary { - @apply py-2 px-4 bg-blue-200; +.btn-primary { +@apply py-2 px-4 bg-blue-200; +} +} + + */ + +@keyframes pan { + 0% { + background-position: 0% 0%; + } + 100% { + background-position: 200% -100%; + } +} + +#radial-wrap { + background: linear-gradient(90deg, rgba(251,191,36,1) 0%, rgba(251,191,36,0) 20%, rgba(251,191,36,0) 80%, rgba(251,191,36,1) 100%); +} + +@keyframes buttonSpin { + from { + transform: rotate(32deg); + } + to { + transform: rotate(calc(360deg + 32deg)); + filter: hue-rotate(360deg); } } -*/ +.contact { transition: opacity 1s ease; position: absolute;} +.contact + .contact, + a:hover .contact:first-child { opacity: 0; } + a:hover .contact:first-child + .contact { opacity: 1; } +.contact + .contact { pointer-events: none; } + +@layer utilities { + .star { + animation: pan 360s linear infinite; + } + .sawtooth-right { + clip-path: polygon(0% -1%, -1% 100.0%, 101% 98.0%, -1% 96.0%, 101% 94.0%, -1% 92.0%, 101% 90.0%, -1% 88.0%, 101% 86.0%, -1% 84.0%, 101% 82.0%, -1% 80.0%, 101% 78.0%, -1% 76.0%, 101% 74.0%, -1% 72.0%, 101% 70.0%, -1% 68.0%, 101% 66.0%, -1% 64.0%, 101% 62.0%, -1% 60.0%, 101% 58.0%, -1% 56.0%, 101% 54.0%, -1% 52.0%, 101% 50.0%, -1% 48.0%, 101% 46.0%, -1% 44.0%, 101% 42.0%, -1% 40.0%, 101% 38.0%, -1% 36.0%, 101% 34.0%, -1% 32.0%, 101% 30.0%, -1% 28.0%, 101% 26.0%, -1% 24.0%, 101% 22.0%, -1% 20.0%, 101% 18.0%, -1% 16.0%, 101% 14.0%, -1% 12.0%, 101% 10.0%, -1% 8.0%, 101% 6.0%, -1% 4.0%, 101% 2.0%); + } + .sawtooth-left { + clip-path: polygon(102% 0%, 102% 100.0%, 0% 98.0%, 100% 96.0%, 0% 94.0%, 100% 92.0%, 0% 90.0%, 100% 88.0%, 0% 86.0%, 100% 84.0%, 0% 82.0%, 100% 80.0%, 0% 78.0%, 100% 76.0%, 0% 74.0%, 100% 72.0%, 0% 70.0%, 100% 68.0%, 0% 66.0%, 100% 64.0%, 0% 62.0%, 100% 60.0%, 0% 58.0%, 100% 56.0%, 0% 54.0%, 100% 52.0%, 0% 50.0%, 100% 48.0%, 0% 46.0%, 100% 44.0%, 0% 42.0%, 100% 40.0%, 0% 38.0%, 100% 36.0%, 0% 34.0%, 100% 32.0%, 0% 30.0%, 100% 28.0%, 0% 26.0%, 100% 24.0%, 0% 22.0%, 100% 20.0%, 0% 18.0%, 100% 16.0%, 0% 14.0%, 100% 12.0%, 0% 10.0%, 100% 8.0%, 0% 6.0%, 100% 4.0%, 0% 2.0%); + } + .sawtooth-left-wrap { + filter: drop-shadow(-10px 5px 4px rgba(0, 0, 0, 0.8)); + } +} diff --git a/app/controllers/api/v1/games_controller.rb b/app/controllers/api/v1/games_controller.rb new file mode 100644 index 0000000..073eec9 --- /dev/null +++ b/app/controllers/api/v1/games_controller.rb @@ -0,0 +1,18 @@ +class Api::V1::GamesController < ApplicationController + skip_before_action :verify_authenticity_token + def create + puts request.methods.sort + @game = Game.new(games_params) + if @game.save + render json: @game, status: :created + else + render json: @game.errors, status: :unprocessable_entity + end + end + + private + + def games_params + params.require(:game).permit(:title, :game_file) + end +end diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index f367ae4..985ace9 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -5,6 +5,10 @@ class Api::V1::UsersController < ApplicationController render json: blog end + def get + + end + def create_or_update(user_params) # add new user, overwrite if exists end diff --git a/app/helpers/api/v1/games_helper.rb b/app/helpers/api/v1/games_helper.rb new file mode 100644 index 0000000..1b49744 --- /dev/null +++ b/app/helpers/api/v1/games_helper.rb @@ -0,0 +1,2 @@ +module Api::V1::GamesHelper +end diff --git a/app/javascript/components/Button.jsx b/app/javascript/components/Button.jsx new file mode 100644 index 0000000..f9505f8 --- /dev/null +++ b/app/javascript/components/Button.jsx @@ -0,0 +1,15 @@ +import React from "react"; +import { Link } from "react-router-dom"; + +export default function Button ({ link }) +{ + return ( + <> +
+
+ { link } +
+
+ + ) +}; diff --git a/app/javascript/components/Home.jsx b/app/javascript/components/Home.jsx index efe3cd5..6ead779 100644 --- a/app/javascript/components/Home.jsx +++ b/app/javascript/components/Home.jsx @@ -1,8 +1,27 @@ -import React from "react"; +import React, { } from "react"; import { Link } from "react-router-dom"; -export default () => ( -
+//export default () => ( +export default function Home () { + var handleSubmit = (e) => { + e.preventDefault() //stops submit from happening + + const formData = new FormData() + formData.append('game[title]', e.target.title.value) + formData.append('game[game_file]', e.target.game_file.files[0], e.target.game_file.value) + +for (var pair of formData.entries()) { + console.log(pair[0] + ', ' + pair[1]) +}; + + fetch('http://127.0.0.1:3000/api/v1/games', { + method: 'post', + body: formData, + }); + } + return( + <> +

Games!

@@ -17,14 +36,17 @@ export default () => ( > View Games - - View Blogs -
+
+ + + + + + +
+ ); +}; diff --git a/app/javascript/components/Layout.jsx b/app/javascript/components/Layout.jsx index 6bf698a..0c5d5b6 100644 --- a/app/javascript/components/Layout.jsx +++ b/app/javascript/components/Layout.jsx @@ -1,15 +1,42 @@ import React from "react"; import { Outlet, Link } from "react-router-dom"; - +import Button from "./Button"; export default function Layout ({userData}) { console.log(userData); //const [userData, setUserData] = useState({ name: "" }); return ( <> -
- +
+
+
+
+
+
+
+
+
+ +
+
-
+
- + ) }; diff --git a/app/models/game.rb b/app/models/game.rb new file mode 100644 index 0000000..fbdc561 --- /dev/null +++ b/app/models/game.rb @@ -0,0 +1,8 @@ +class Game < ApplicationRecord + #enum status: { + # draft: 0, + # published: 1 + #} + #belongs_to :user + has_one_attached :game_file +end diff --git a/app/models/user.rb b/app/models/user.rb index 39c7822..0317c47 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ class User < ApplicationRecord validates :identifier, presence: true + has_many :games end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 7ed5167..e7e2040 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,10 +10,22 @@ <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> <%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %> + + + + + diff --git a/config/routes.rb b/config/routes.rb index 786c21d..7d8a766 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,15 +1,24 @@ Rails.application.routes.draw do namespace :api do namespace :v1 do + resources :games + + # USERS get 'users/index', to: 'users#index' #get 'users/new' #get 'users/create' #get 'users/delete' + + # GAMES + + + # BLOGS get 'blogs/index', to: 'blog#index' post 'blogs/create', to: 'blog#create' get '/show/:id', to: 'blog#show' delete '/destroy/:id', to: 'blog#destroy' + # AUTH get 'auth/callback', to: 'auth#callback' get 'auth/data', to: 'auth#data' end diff --git a/config/tailwind.config.js b/config/tailwind.config.js index a5ba70b..ddc2e3e 100644 --- a/config/tailwind.config.js +++ b/config/tailwind.config.js @@ -1,24 +1,27 @@ const defaultTheme = require('tailwindcss/defaultTheme') module.exports = { - content: [ - './public/*.html', - './app/helpers/**/*.rb', - './app/javascript/**/*.js', - './app/javascript/**/*.jsx', - './app/views/**/*.{erb,haml,html,slim}' - ], - theme: { - extend: { - fontFamily: { - sans: ['Inter var', ...defaultTheme.fontFamily.sans], - }, - }, - }, - plugins: [ - require('@tailwindcss/forms'), - require('@tailwindcss/aspect-ratio'), - require('@tailwindcss/typography'), - require('@tailwindcss/container-queries'), - ] + content: [ + './public/*.html', + './app/helpers/**/*.rb', + './app/javascript/**/*.js', + './app/javascript/**/*.jsx', + './app/views/**/*.{erb,haml,html,slim}' + ], + theme: { + extend: { + backgroundImage: { + 'star': "url('/img/star.png')", + }, + fontFamily: { + sans: ['Inter var', ...defaultTheme.fontFamily.sans], + }, + }, + }, + plugins: [ + require('@tailwindcss/forms'), + require('@tailwindcss/aspect-ratio'), + require('@tailwindcss/typography'), + require('@tailwindcss/container-queries'), + ] } diff --git a/db/migrate/20240509225147_create_games.rb b/db/migrate/20240509225147_create_games.rb new file mode 100644 index 0000000..af8f77b --- /dev/null +++ b/db/migrate/20240509225147_create_games.rb @@ -0,0 +1,12 @@ +class CreateGames < ActiveRecord::Migration[7.1] + def change + create_table :games do |t| + t.string :title + #t.text :body + #t.integer :status, default: 0 + #t.references :user, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 69731f6..3131a91 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_05_03_001922) do +ActiveRecord::Schema[7.1].define(version: 2024_05_09_225147) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -53,6 +53,12 @@ ActiveRecord::Schema[7.1].define(version: 2024_05_03_001922) do t.datetime "updated_at", null: false end + create_table "games", force: :cascade do |t| + t.string "title" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "users", force: :cascade do |t| t.string "identifier" t.string "access_token_digest" diff --git a/package.json b/package.json index 5d91cff..e648d5c 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ }, "scripts": { "build": "esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets", - "build:css:compile": "sass ./app/assets/builds/application.css --no-source-map --load-path=node_modules", + "build:css:compile": "sass ./app/assets/stylesheets/application.css:./app/assets/builds/application.css --no-source-map --load-path=node_modules", "build:css:prefix": "postcss ./app/assets/builds/application.css --use=autoprefixer --output=./app/assets/builds/application.css", "build:css": "yarn build:css:compile && yarn build:css:prefix", "watch:css": "nodemon --watch ./app/assets/stylesheets/ --ext scss --exec \"yarn build:css\"" diff --git a/public/img/star.png b/public/img/star.png new file mode 100644 index 0000000..2fed1e3 Binary files /dev/null and b/public/img/star.png differ diff --git a/public/img/star.svg b/public/img/star.svg new file mode 100644 index 0000000..50f56e2 --- /dev/null +++ b/public/img/star.svg @@ -0,0 +1,117 @@ + + + + + + + + + + + + + diff --git a/test/controllers/api/v1/games_controller_test.rb b/test/controllers/api/v1/games_controller_test.rb new file mode 100644 index 0000000..0052dbb --- /dev/null +++ b/test/controllers/api/v1/games_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class Api::V1::GamesControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/games.yml b/test/fixtures/games.yml new file mode 100644 index 0000000..ba6c0d7 --- /dev/null +++ b/test/fixtures/games.yml @@ -0,0 +1,13 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + title: MyString + body: MyText + status: 1 + user: one + +two: + title: MyString + body: MyText + status: 1 + user: two diff --git a/test/models/game_test.rb b/test/models/game_test.rb new file mode 100644 index 0000000..6628fae --- /dev/null +++ b/test/models/game_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class GameTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/yarn.lock b/yarn.lock index 8de7d19..fdb8735 100644 --- a/yarn.lock +++ b/yarn.lock @@ -297,11 +297,6 @@ binary-extensions@^2.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== -bootstrap-icons@^1.11.3: - version "1.11.3" - resolved "https://registry.yarnpkg.com/bootstrap-icons/-/bootstrap-icons-1.11.3.tgz#03f9cb754ec005c52f9ee616e2e84a82cab3084b" - integrity sha512-+3lpHrCw/it2/7lBL15VR0HEumaBss0+f/Lb6ZvHISn1mlK83jjFpooTLsMWbIjJMDjDjOExMsTxnXSIT4k4ww== - brace-expansion@^1.1.7: version "1.1.11" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" @@ -340,9 +335,9 @@ camelcase-css@^2.0.1: integrity sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA== caniuse-lite@^1.0.30001587, caniuse-lite@^1.0.30001599: - version "1.0.30001612" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001612.tgz#d34248b4ec1f117b70b24ad9ee04c90e0b8a14ae" - integrity sha512-lFgnZ07UhaCcsSZgWW0K5j4e69dK1u/ltrL9lTUiFOwNHs12S3UMIEYgBV0Z6C6hRDev7iRnMzzYmKabYdXF9g== + version "1.0.30001618" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001618.tgz" + integrity sha512-p407+D1tIkDvsEAPS22lJxLQQaG8OTBEqo0KhzfABGk0TU4juBNDSfH0hyAp/HRyx+M8L17z/ltyhxh27FTfQg== "chokidar@>=3.0.0 <4.0.0", chokidar@^3.3.0, chokidar@^3.5.2, chokidar@^3.5.3: version "3.6.0" -- cgit v1.2.3