Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
706a547
commit 96ebf6b
Showing
18 changed files
with
187 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,3 +66,7 @@ end | |
|
||
|
||
gem "devise", "~> 4.9" | ||
|
||
gem "faker", "~> 3.1" | ||
|
||
gem "pagy", "~> 6.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
class TweetsController < ApplicationController | ||
include Pagy::Backend | ||
before_action :set_tweet, only: %i[ show edit update destroy ] | ||
|
||
# GET /tweets | ||
def index | ||
@pagy, @tweets = pagy_countless(Tweet.all, items: 25) | ||
|
||
respond_to do |format| | ||
format.html | ||
format.turbo_stream | ||
end | ||
end | ||
|
||
# GET /tweets/1 | ||
def show | ||
end | ||
|
||
# GET /tweets/new | ||
def new | ||
@tweet = Tweet.new | ||
end | ||
|
||
# GET /tweets/1/edit | ||
def edit | ||
end | ||
|
||
# POST /tweets | ||
def create | ||
@tweet = Tweet.new(tweet_params) | ||
|
||
if @tweet.save | ||
redirect_to @tweet, notice: "Tweet was successfully created." | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# PATCH/PUT /tweets/1 | ||
def update | ||
if @tweet.update(tweet_params) | ||
redirect_to @tweet, notice: "Tweet was successfully updated." | ||
else | ||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# DELETE /tweets/1 | ||
def destroy | ||
@tweet.destroy | ||
redirect_to tweets_url, notice: "Tweet was successfully destroyed." | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_tweet | ||
@tweet = Tweet.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def tweet_params | ||
params.fetch(:tweet, {}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
module ApplicationHelper | ||
include Pagy::Frontend | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module TweetsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Tweet < ApplicationRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,4 @@ | |
</div> | ||
</div> | ||
</div> | ||
<% end %> | ||
|
||
|
||
z`` | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= turbo_frame_tag "infinite_scroll", | ||
src: tweets_path(page: page, format: :turbo_stream), loading: :lazy %> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<li id="<%= dom_id(tweet) %>" class="relative bg-white py-5 px-4 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600 hover:bg-gray-50"> | ||
<div class="flex justify-between space-x-3"> | ||
<div class="min-w-0 flex-1 flex items-center"> | ||
<div class="flex-shrink-0"> | ||
<img class="h-12 w-12 rounded-full" src="<%= Faker::LoremFlickr.image(size: "100x100", search_terms: ['star wars']) %>" alt=""> | ||
</div> | ||
<div class="min-w-0 flex-1 ml-2"> | ||
<p class="truncate text-sm font-medium text-gray-900"><%= tweet.handle %></p> | ||
</div> | ||
</div> | ||
<time datetime="2021-01-27T16:35" class="flex-shrink-0 whitespace-nowrap text-sm text-gray-500">1d ago</time> | ||
</div> | ||
<div class="mt-1"> | ||
<p class="text-sm text-gray-600 line-clamp-2"> | ||
<%= tweet.content %> | ||
</p> | ||
</div> | ||
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render partial: "tweets/tweet", collection: tweets %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8 pt-5"> | ||
<div class="mx-auto max-w-2xl mt-5 flex items-center justify-center"> | ||
<ul id="tweets" role="list" class="divide-y divide-gray-200"> | ||
</ul> | ||
<%= render 'tweets/scroll_frame', page: 1 %> | ||
</div> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<%= turbo_stream.append "tweets", partial: "tweets/tweets", locals: { tweets: @tweets } %> | ||
<% if @pagy.next.present? %> | ||
<%= turbo_stream.replace "infinite_scroll", | ||
partial: "tweets/scroll_frame", | ||
locals: { page: @pagy.next } %> | ||
<% end %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'pagy/extras/countless' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Rails.application.routes.draw do | ||
resources :tweets | ||
devise_for :users | ||
root 'pages#kitchensink' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateTweets < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :tweets do |t| | ||
t.string :content | ||
t.string :handle | ||
t.string :image_url | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters