Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .eslint_todo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This configuration was generated by `exe/eslint_autogen`
// on 2026-11-28 00:43:19 UTC.
// on 2026-11-28 02:17:20 UTC.
// The point is for the user to remove these configuration records
// one by one as the offenses are removed from the code base.

Expand All @@ -15,10 +15,9 @@ const config: Linter.Config[] = [
"@stylistic/dot-location": "off",
},
},
// Offense count: 60
// Offense count: 52
{
files: [
"app/javascript/controllers/keep_unread_toggle_controller.ts",
"app/javascript/controllers/mark_all_as_read_controller.ts",
"app/javascript/controllers/unread_count_controller.ts",
"app/javascript/helpers/api.ts",
Expand All @@ -44,10 +43,9 @@ const config: Linter.Config[] = [
"@stylistic/max-len": "off",
},
},
// Offense count: 9
// Offense count: 8
{
files: [
"app/javascript/controllers/keep_unread_toggle_controller.ts",
"spec/javascript/controllers/unread_count_controller_spec.ts",
"spec/javascript/helpers/ensure_spec.ts",
"spec/javascript/support/stimulus.ts",
Expand Down
4 changes: 2 additions & 2 deletions .stylelint_todo.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This configuration was generated by `exe/stylelint_autogen`
# on 2026-02-19 04:45:04 UTC.
# on 2026-11-28 02:16:51 UTC.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.

Expand Down Expand Up @@ -50,7 +50,7 @@ overrides:
files:
- app/assets/stylesheets/application.css

# Offense count: 68
# Offense count: 67
- rules: { 'order/properties-order': null }
files:
- app/assets/stylesheets/application.css
Expand Down
17 changes: 7 additions & 10 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -264,31 +264,28 @@ li.story.open .story-lead {

.story-keep-unread, .story-starred, .story-refresh {
display: inline-block;
padding: 0;
margin-right: 20px;
color: inherit;
cursor: pointer;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
margin-right: 20px;
background: none;
border: 0;
-webkit-touch-callout: none;
}

li.story > turbo-frame {
display: block;
}

.story-refresh-form, .story-star-form {
.story-refresh-form, .story-star-form, .story-keep-unread-form {
display: inline;
}

.story-refresh, .story-starred {
padding: 0;
color: inherit;
background: none;
border: 0;
}

/* Turbo sets aria-busy on the refresh form while its request is in flight. */
.story-refresh-form[aria-busy="true"] .fa-refresh {
animation: fa-spin 1s infinite linear;
Expand Down
22 changes: 22 additions & 0 deletions app/components/replace_stream.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

# A Turbo Stream response that replaces elements by id. `replacements` maps
# each target id to the component to render in its place.
class Components::ReplaceStream < Components::Base
register_element :turbo_stream

attr_accessor :replacements

def initialize(replacements)
super()
self.replacements = replacements
end

def view_template
replacements.each do |target, component|
turbo_stream(action: "replace", target:) do
template { render(component) }
end
end
end
end
15 changes: 4 additions & 11 deletions app/components/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Components::Story < Components::Base
# The star and refresh forms submit inside the story's frame: sample
# stories skip them, and a failed refresh leaves the story as it was.
ACTIONS = [
"keep-unread-toggle:toggled->story#keepUnreadToggled",
"submit->story#formSubmitted",
"turbo:frame-missing->story#frameMissing"
].join(" ").freeze
Expand All @@ -31,7 +30,7 @@ def classes

def data
{
controller: "story keep-unread-toggle",
controller: "story",
action: ACTIONS,
**values,
story_list_target: "story",
Expand All @@ -40,16 +39,10 @@ def data
end

def values
read_state = { is_read: story.is_read, keep_unread: story.keep_unread }
{
**controller_values("story", **read_state),
**controller_values("keep_unread_toggle", **read_state)
story_id_value: story.id.to_s,
story_is_read_value: story.is_read.to_s,
story_keep_unread_value: story.keep_unread.to_s
}
end

def controller_values(controller, **values)
{ id: story.id, **values }.to_h do |name, value|
[:"#{controller}_#{name}_value", value.to_s]
end
end
end
11 changes: 1 addition & 10 deletions app/components/story_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def view_template
div(class: "story-actions-container") do
div { span(class: "story-published") { story.pretty_date } }
div(class: "story-actions") do
keep_unread_button
render(Components::StoryKeepUnread.new(story:))
render(Components::StoryStar.new(story:, placement: :actions))
refresh_button
permalink_link
Expand All @@ -25,15 +25,6 @@ def view_template

private

def keep_unread_button
data = { action: "click->keep-unread-toggle#toggle:stop", **hotkey("m") }
div(class: "story-keep-unread", data:) do
icon = story.keep_unread ? "fa-check" : "fa-square-o"
i(class: "fa #{icon}", data: { keep_unread_toggle_target: "icon" })
plain(" #{t('stories.keep_unread')}")
end
end

# Submits inside the story's Turbo Frame; see Components::StoryFrame.
def refresh_button
url = "/stories/#{story.id}/refresh"
Expand Down
55 changes: 55 additions & 0 deletions app/components/story_keep_unread.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

# The keep unread button for a story, which also answers the m hotkey.
#
# The button submits a form; the response is a Turbo Stream that replaces
# this form with the saved state. The form is the story controller's
# `readState` target, so when it is replaced the controller copies the saved
# read and keep unread state onto the story.
class Components::StoryKeepUnread < Components::Base
attr_accessor :story

def self.dom_id(story)
"story_#{story.id}_keep_unread"
end

# This button, by id, for a Turbo Stream response.
def self.replacements(story)
{ dom_id(story) => new(story:) }
end

def initialize(story:)
super()
self.story = story
end

def view_template
url = "/stories/#{story.id}/keep_unread"
form_with(url:, method: :patch, class: "story-keep-unread-form", **attrs) do
value = (!story.keep_unread).to_s
input(type: "hidden", name: "keep_unread", value:)
keep_unread_button
end
end

private

def attrs
{
id: self.class.dom_id(story),
data: {
story_target: "readState",
is_read: story.is_read.to_s,
keep_unread: story.keep_unread.to_s
}
}
end

def keep_unread_button
data = { hotkeys_target: "click", hotkey: "m" }
button(type: "submit", class: "story-keep-unread", data:) do
i(class: "fa #{story.keep_unread ? 'fa-check' : 'fa-square-o'}")
plain(" #{t('stories.keep_unread')}")
end
end
end
9 changes: 8 additions & 1 deletion app/components/story_star.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# one in its actions, which also answers the s hotkey.
#
# The button submits a form; the response is a Turbo Stream that replaces both
# buttons (see `Components::StoryStarStream`), so the icon only changes once
# buttons (see `StoriesController#star`), so the icon only changes once
# the server has saved the star.
class Components::StoryStar < Components::Base
PLACEMENTS = [:preview, :actions].freeze
Expand All @@ -15,6 +15,13 @@ def self.dom_id(story, placement)
"story_#{story.id}_star_#{placement}"
end

# Both of the story's star buttons, by id, for a Turbo Stream response.
def self.replacements(story)
PLACEMENTS.to_h do |placement|
[dom_id(story, placement), new(story:, placement:)]
end
end

def initialize(story:, placement:)
super()
self.story = story
Expand Down
23 changes: 0 additions & 23 deletions app/components/story_star_stream.rb

This file was deleted.

29 changes: 23 additions & 6 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,23 @@ def refresh
render(Components::StoryFrame.new(story:), layout: false, status:)
end

# Responds with a Turbo Stream that replaces the story's star buttons.
# Responds with a Turbo Stream that replaces both of the story's star
# buttons.
def star
story = authorization.check(StoryRepository.fetch(params[:id]))
story.update!(is_starred: params[:starred] == "true")

render(
Components::StoryStarStream.new(story:),
layout: false,
content_type: "text/vnd.turbo-stream.html"
)
render_replacements(Components::StoryStar.replacements(story))
end

# Keeping a story unread also marks it unread; turning it off marks it
# read. Responds with a Turbo Stream that replaces the keep unread button.
def keep_unread
story = authorization.check(StoryRepository.fetch(params[:id]))
keep_unread = params[:keep_unread] == "true"
story.update!(keep_unread:, is_read: !keep_unread)

render_replacements(Components::StoryKeepUnread.replacements(story))
end

def mark_all_as_read
Expand All @@ -61,4 +68,14 @@ def starred
stories = authorization.scope(StoryRepository.starred(params[:page]))
render(Views::Stories::Starred.new(stories:))
end

private

def render_replacements(replacements)
render(
Components::ReplaceStream.new(replacements),
layout: false,
content_type: "text/vnd.turbo-stream.html"
)
end
end
3 changes: 0 additions & 3 deletions app/javascript/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ application.register("dialog", DialogController);
import HotkeysController from "./hotkeys_controller";
application.register("hotkeys", HotkeysController);

import KeepUnreadToggleController from "./keep_unread_toggle_controller";
application.register("keep-unread-toggle", KeepUnreadToggleController);

import MarkAllAsReadController from "./mark_all_as_read_controller";
application.register("mark-all-as-read", MarkAllAsReadController);

Expand Down
54 changes: 0 additions & 54 deletions app/javascript/controllers/keep_unread_toggle_controller.ts

This file was deleted.

Loading
Loading