Add drafted and published states

This commit is contained in:
Kevin McConnell
2025-01-07 17:13:56 +00:00
parent f209c23e45
commit cd1e6378d0
13 changed files with 69 additions and 8 deletions
+4
View File
@@ -443,6 +443,10 @@
border: var(--bubble-border-width) solid var(--bubble-color);
}
.bubble.drafted & {
border-style: dashed;
}
.bubble:has(.bubble__link) & {
z-index: -1;
}
@@ -0,0 +1,8 @@
class Bubbles::PublishesController < ApplicationController
include BubbleScoped, BucketScoped
def create
@bubble.published!
redirect_to @bubble
end
end
+1 -1
View File
@@ -7,7 +7,7 @@ class BubblesController < ApplicationController
before_action :set_bubble, only: %i[ show edit update destroy ]
def index
@bubbles = @filter.bubbles
@bubbles = @filter.bubbles.published_or_drafted_by(Current.user)
end
def create
+2 -1
View File
@@ -1,5 +1,6 @@
class Bubble < ApplicationRecord
include Assignable, Boostable, Colored, Commentable, Eventable, Messages, Notifiable, Poppable, Searchable, Staged, Taggable
include Assignable, Boostable, Colored, Commentable, Draftable,
Eventable, Messages, Notifiable, Poppable, Searchable, Staged, Taggable
belongs_to :bucket, touch: true
belongs_to :creator, class_name: "User", default: -> { Current.user }
+9
View File
@@ -0,0 +1,9 @@
module Bubble::Draftable
extend ActiveSupport::Concern
included do
enum :status, %w[ drafted published ].index_by(&:itself)
scope :published_or_drafted_by, ->(user) { where(status: :published).or(where(creator: user)) }
end
end
+1 -1
View File
@@ -1,5 +1,5 @@
<% cache bubble do %>
<div class="bubble"
<div class="<%= class_names("bubble", drafted: bubble.drafted?) %>"
style="view-transition-name: bubble-<%= bubble.id -%>; --bubble-color: <%= bubble.color %>; <%= bubble_rotation(bubble) %> <%= bubble_size(bubble) %>"
data-controller="animation upload-preview"
data-animation-play-class="bubble--wobble"
+4
View File
@@ -0,0 +1,4 @@
<%= button_to bucket_bubble_publish_path(bubble.bucket, bubble), class: "btn btn--positive full-width justify-start borderless" do %>
<%= image_tag "alert.svg", aria: { hidden: true }, size: 24 %>
<span>Publish</span>
<% end %>
+9 -5
View File
@@ -56,12 +56,16 @@
<% end %>
<hr class="separator--horizontal full-width" style="--border-color: var(--color-subtle);" />
<%= render "bubbles/pop_toggle", bubble: @bubble %>
<% if @bubble.drafted? %>
<%= render "bubbles/publish", bubble: @bubble %>
<% else %>
<%= render "bubbles/pop_toggle", bubble: @bubble %>
<button class="btn full-width justify-start borderless">
<%= image_tag "picture-double.svg", aria: { hidden: true }, size: 24 %>
<span>I've seen this</span>
</button>
<% end %>
<button class="btn full-width justify-start borderless">
<%= image_tag "picture-double.svg", aria: { hidden: true }, size: 24 %>
<span>I've seen this</span>
</button>
<%= button_to bucket_bubble_path(@bubble.bucket, @bubble),
method: :delete,
+1
View File
@@ -29,6 +29,7 @@ Rails.application.routes.draw do
scope module: :bubbles do
resource :image
resource :pop
resource :publish
resource :stage_picker
resources :stagings
end
@@ -0,0 +1,5 @@
class AddStatusToBubbles < ActiveRecord::Migration[8.1]
def change
add_column :bubbles, :status, :text, default: :drafted, null: false
end
end
Generated
+1
View File
@@ -106,6 +106,7 @@ ActiveRecord::Schema[8.1].define(version: 2025_01_09_153649) do
t.integer "stage_id"
t.integer "comments_count", default: 0, null: false
t.integer "activity_score", default: 0, null: false
t.text "status", default: "drafted", null: false
t.index ["bucket_id"], name: "index_bubbles_on_bucket_id"
t.index ["stage_id"], name: "index_bubbles_on_stage_id"
end
+4
View File
@@ -8,6 +8,7 @@ logo:
boosts_count: 5
comments_count: 2
activity_score: 7
status: published
layout:
bucket: writebook
@@ -17,6 +18,7 @@ layout:
created_at: <%= 1.week.ago %>
comments_count: 1
activity_score: 1
status: published
text:
bucket: writebook
@@ -24,6 +26,7 @@ text:
title: The text is too small
color: "#3B4B59"
created_at: <%= 1.week.ago %>
status: published
shipping:
bucket: writebook
@@ -31,3 +34,4 @@ shipping:
title: We need to ship the app
color: "#ED8008"
created_at: <%= 1.week.ago %>
status: published
+20
View File
@@ -0,0 +1,20 @@
require "test_helper"
class Bubble::DraftableTest < ActiveSupport::TestCase
test "bubbles are only visible to the creator by default" do
bubble = buckets(:writebook).bubbles.create! creator: users(:kevin), title: "Drafted Bubble"
assert bubble.drafted?
assert_includes Bubble.published_or_drafted_by(users(:kevin)), bubble
assert_not_includes Bubble.published_or_drafted_by(users(:jz)), bubble
end
test "bubbles are visible to everyone when published" do
bubble = buckets(:writebook).bubbles.create! creator: users(:kevin), title: "Drafted Bubble"
bubble.published!
assert bubble.published?
assert_includes Bubble.published_or_drafted_by(users(:kevin)), bubble
assert_includes Bubble.published_or_drafted_by(users(:jz)), bubble
end
end