Skip to content

Commit

Permalink
Merge pull request #92 from realstorypro/tweet-filters
Browse files Browse the repository at this point in the history
Added tweet filters, updated approval workflow, adjusted global styling
  • Loading branch information
Leonid Medovyy committed Jul 21, 2023
2 parents ca24a0f + ea1841c commit 34331a0
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 46 deletions.
22 changes: 20 additions & 2 deletions app/controllers/tweets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class TweetsController < ApplicationController
include RestrictedAccess
def index
@tweets = Tweet.all.order(id: :desc).page params[:page]
@total_tweets = Tweet.all.count
scope = set_scope

@tweets = Tweet.send(scope).order(id: :desc).page params[:page]
@total_tweets = Tweet.send(scope).count
end

def show
Expand Down Expand Up @@ -47,4 +49,20 @@ def disapprove
@tweet.update(approved: false)
redirect_to tweet_path(@tweet)
end

private

def set_scope
if params[:scope] && params[:scope] == 'pending'
return 'needs_approval'
elsif params[:scope] && params[:scope] == 'approved'
return 'approved_tweets'
elsif params[:scope] && params[:scope] == 'denied'
return 'denied'
elsif params[:scope] && params[:scope] == 'published'
return 'published'
end

'all'
end
end
2 changes: 1 addition & 1 deletion app/frontend/stylesheets/admin/menu.sass
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.segment.basic.menu-wrapper
padding: 0.8em 0 1.7em
padding: 0.4em 0 1.3em

.ui.container,
.column
Expand Down
2 changes: 1 addition & 1 deletion app/models/discussion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ class Discussion < ApplicationRecord
}

scope :published, -> { where(uploaded: true) }
scope :unpublished, -> { where(uploaded: false, invalid_json: false, processed: true) }
scope :unpublished, -> { ready_to_upload }
end
8 changes: 8 additions & 0 deletions app/models/tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@
#
class Tweet < ApplicationRecord
belongs_to :discussion

scope :needs_approval, -> { where(approved: nil, uploaded: false, invalid_json: false) }

scope :approved_tweets, -> { where(approved: true) }

scope :denied, -> { where(approved: false) }

scope :published, -> { where(uploaded: true) }
end
5 changes: 0 additions & 5 deletions app/views/discussions/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
=r ux.container
=r ux.row
=r ux.column width: 16
=r ux.segment 'basic'
=r ux.text class: 'text-center', text: 'πŸ”’ This page is protected by devise. You can only see it if you are logged in & authorized. πŸ”’'

=r ux.divider

=r ux.h2 'center aligned !font-mono'
| Discussions
=r ux.label text: @total_discussions, class: 'circular !bg-black !text-white'
Expand Down
5 changes: 0 additions & 5 deletions app/views/feeds/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
=r ux.container
=r ux.row
=r ux.column width: 16
=r ux.segment 'basic'
=r ux.text class: 'text-center', text: 'πŸ”’ This page is protected by devise. You can only see it if you are logged in & authorized. πŸ”’'

=r ux.divider

=r ux.h2 'center aligned !font-mono'
| Feeds
=r ux.label text: @total_feeds, class: 'circular !bg-black !text-white'
Expand Down
5 changes: 0 additions & 5 deletions app/views/imaginations/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
=r ux.container
=r ux.row
=r ux.column width: 16
=r ux.segment 'basic'
=r ux.text class: 'text-center', text: 'πŸ”’ This page is protected by devise. You can only see it if you are logged in & authorized. πŸ”’'

=r ux.divider

=r ux.h2 'center aligned !font-mono'
| Imaginations
=r ux.label text: @total_imaginations, class: 'circular !bg-black !text-white'
Expand Down
28 changes: 22 additions & 6 deletions app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ html lang="en"
=r ux.grid
=r ux.row 'menu'
=r ux.column size: 16
=r ux.menu ui: :on, class: 'inverted tiny black internal !bg-zinc-900 !font-mono', controller: 'dropdown'
=r ux.menu ui: :on, class: 'inverted mini black internal !bg-zinc-900 !font-mono', controller: 'dropdown'
=r ux.item url: root_path, class: "logo-item #{menu_active?(root_path)}}"
=r ux.header text: '{e}', class: 'inverted logo !font-mono'

=r ux.item class: "top right pointing dropdown #{dropdown_active?(stories_path)}", ui: :on
=r ux.item class: "dropdown #{dropdown_active?(stories_path)}", ui: :on
=r ux.icon 'leaf'
| Stories
=r ux.icon 'dropdown'
Expand All @@ -50,7 +50,7 @@ html lang="en"
= link_to stories_path, class: "item"
| All

=r ux.item class: "top right pointing dropdown #{dropdown_active?(discussions_path)}", ui: :on
=r ux.item class: "dropdown #{dropdown_active?(discussions_path)}", ui: :on
=r ux.icon 'comments'
| Discussions
=r ux.icon 'dropdown'
Expand All @@ -64,10 +64,26 @@ html lang="en"
= link_to discussions_path, class: "item"
| All


= link_to tweets_path, class: "item #{menu_active?(tweets_path)}"
=r ux.item class: "dropdown #{dropdown_active?(tweets_path)}", ui: :on
=r ux.icon 'twitter'
| Tweets
=r ux.icon 'dropdown'
=r ux.menu
= link_to tweets_path(scope: :pending), class: "item"
| Pending
=r ux.divider
= link_to tweets_path(scope: :approved), class: "item"
| Approved
=r ux.divider
= link_to tweets_path(scope: :denied), class: "item"
| Denied
=r ux.divider
= link_to tweets_path(scope: :published), class: "item"
| Published
=r ux.divider
= link_to tweets_path, class: "item"
| All


= link_to imaginations_path, class: "item #{menu_active?(imaginations_path)}"
=r ux.icon 'image'
Expand All @@ -84,7 +100,7 @@ html lang="en"
= link_to tags_path, class: "item"
=r ux.icon 'tags'
| Tags
=r ux.item class: 'top right pointing dropdown', ui: :on
=r ux.item class: 'dropdown', ui: :on
= current_user.email
=r ux.icon 'dropdown'
=r ux.menu
Expand Down
5 changes: 0 additions & 5 deletions app/views/page/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
=r ux.container
=r ux.row
=r ux.column width: 16
=r ux.segment 'basic'
=r ux.text class: 'text-center', text: 'πŸ”’ This page is protected by devise. You can only see it if you are logged in & authorized. πŸ”’'

=r ux.divider

=r ux.h2 'center aligned !font-mono !mb-8'
| Topics
=r ux.label text: @topics.count, class: 'circular !bg-black !text-white'
Expand Down
5 changes: 0 additions & 5 deletions app/views/stories/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
=r ux.container
=r ux.row
=r ux.column width: 16
=r ux.segment 'basic'
=r ux.text class: 'text-center', text: 'πŸ”’ This page is protected by devise. You can only see it if you are logged in & authorized. πŸ”’'

=r ux.divider

=r ux.h2 'center aligned !font-mono'
| Stories
=r ux.label text: @total_stories, class: 'circular !bg-black !text-white'
Expand Down
5 changes: 0 additions & 5 deletions app/views/tags/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
=r ux.container
=r ux.row
=r ux.column width: 16
=r ux.segment 'basic'
=r ux.text class: 'text-center', text: 'πŸ”’ This page is protected by devise. You can only see it if you are logged in & authorized. πŸ”’'

=r ux.divider

=r ux.h2 'center aligned !font-mono'
| Tags
=r ux.label text: @total_tags, class: 'circular !bg-black !text-white'
Expand Down
3 changes: 2 additions & 1 deletion app/views/tweets/_tweet.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
= turbo_frame_tag frame_id
=r ux.code
- unless tweet.invalid_json
= highlight_hashtags(JSON.parse(tweet.stem)['tweet'])
= link_to edit_tweet_path(tweet), class: 'no-underline'
= highlight_hashtags(JSON.parse(tweet.stem)['tweet'])
- else
.text-red-700
| We could not generate the tweet automatically. Please click `edit` to manually create it.
Expand Down
5 changes: 0 additions & 5 deletions app/views/tweets/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
=r ux.container
=r ux.row
=r ux.column width: 16
=r ux.segment 'basic'
=r ux.text class: 'text-center', text: 'πŸ”’ This page is protected by devise. You can only see it if you are logged in & authorized. πŸ”’'

=r ux.divider

=r ux.h2 'center aligned !font-mono'
| Tweets
=r ux.label text: @total_tweets, class: 'circular !bg-black !text-white'
Expand Down

0 comments on commit 34331a0

Please sign in to comment.