Skip to content

Commit

Permalink
🥔✨Journal: Enter Entry#new flow via Keyword#show (#1718)
Browse files Browse the repository at this point in the history
- https://github.com/zinc-collective/convene/issues/1713
- https://github.com/zinc-collective/convene/issues/1566

I thought I would tilt at this while I waited for the build to go out;
since I noticed I go from an `Entry` to a `Keyword` when trying to
decide what to fill in next when world building.

It also auto-fills the new `Entry` body with the `Keywords` canonical
version and it's aliases!

Which... I need to make a UI for soonish.
  • Loading branch information
zspencer authored Jul 28, 2023
1 parent 96738d1 commit 7618eee
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
13 changes: 2 additions & 11 deletions app/furniture/journal/journals/_journal.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<section class="max-w-3xl mx-auto">
<%- new_entry = journal.entries.new %>
<%- if policy(new_entry).new? %>
<div class="text-center p-2">
<%= link_to "New Journal Entry", journal.location(:new, child: :entry) %>
</div>
<%- end %>
<%= render Journal::NewEntryButtonComponent.new(journal: journal) %>

<div class="flex flex-wrap">
<%- @pagy, @entries = pagy(policy_scope(journal.entries.recent)) %>
Expand All @@ -14,9 +9,5 @@

<%== pagy_nav(@pagy, nav_extra: 'flex justify-between') %>

<%- if policy(new_entry).new? %>
<footer class="text-center p-2">
<%= link_to "New Journal Entry", journal.location(:new, child: :entry) %>
</footer>
<%- end %>
<%= render Journal::NewEntryButtonComponent.new(journal: journal) %>
</section>
2 changes: 2 additions & 0 deletions app/furniture/journal/keywords/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
<%- end %>

<h2>Entries about <span class="italic"><%= keyword.canonical_keyword %></span></h2>
<%= render Journal::NewEntryButtonComponent.new(keyword: keyword) %>
<ul>
<%- policy_scope(keyword.entries).each do |entry|%>
<li><%= link_to(entry.headline, entry.location) %></li>
<%- end %>
</ul>
<%= render Journal::NewEntryButtonComponent.new(keyword: keyword) %>
5 changes: 5 additions & 0 deletions app/furniture/journal/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
en:
journal:
entries:
new:
link_to: "New Journal Entry"
3 changes: 3 additions & 0 deletions app/furniture/journal/new_entry_button_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="text-center p-2">
<%= link_to t("journal.entries.new.link_to"), location %>
</div>
27 changes: 27 additions & 0 deletions app/furniture/journal/new_entry_button_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Journal
class NewEntryButtonComponent < ApplicationComponent
attr_accessor :keyword, :journal
def initialize(keyword: nil, journal: keyword&.journal)
self.keyword = keyword
self.journal = journal
end

def render?
policy(new_entry).new?
end

def location
journal.location(:new, child: :entry, query_params: location_query_params)
end

private def location_query_params
return nil if keyword.blank?

{entry: {body: "##{keyword.canonical_with_aliases.join(" #")}"}}
end

private def new_entry
@new_entry ||= journal.entries.new
end
end
end

0 comments on commit 7618eee

Please sign in to comment.