Skip to content

Commit

Permalink
add source Description and Image columns, more work on Source card
Browse files Browse the repository at this point in the history
  • Loading branch information
pessi-v committed Jul 4, 2024
1 parent 3f6f7ad commit 4525e45
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
10 changes: 10 additions & 0 deletions app/models/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Source < ApplicationRecord
scope :active, -> { where(active: true) }

has_many :articles, dependent: :destroy
before_create :add_description_and_image
after_update :update_articles_source_name, if: :saved_change_to_name?

def valid_feed
Expand All @@ -30,6 +31,15 @@ def valid_feed

private

def add_description_and_image
uri = URI(s.url)
uri.query = uri.fragment = nil
uri.path = ""
ogp = Ogpr.fetch(uri.to_s)
image_url = ogp.image
description = ogp.description
end

def update_articles_source_name
articles.update_all(source_name: name)
end
Expand Down
29 changes: 21 additions & 8 deletions app/views/sources/_source.html.slim
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
css:
.error {
color: var(--color-primary);
}

.source_card {
width: 100%;
height: auto;
border: var(--border);
display: flex;
}

.section {
width: 50%;
}

.half {
width: 50%;
.error {
color: var(--color-primary);
}

.image {
height: var(--space-9xl);
aspect-ratio: 1 / 1;
object-fit: cover;
}
}


= turbo_frame_tag source
.source_card
.half
img.image src=source.image_url

.section
h1
= source.name

Expand Down Expand Up @@ -49,6 +59,9 @@ css:
p.error
= source.last_error_status

.half
.section
p
= source.description

= button_to "Change", edit_source_path(source), method: :get
= button_to "Unsubscribe", source, method: :delete, form: {data: {turbo_confirm: "Unsubscribing from this source will remove all of it's articles from the database. If you want to keep the articles, you should just deactivate the source."}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddDescriptionAndImageToSource < ActiveRecord::Migration[7.1]
def change
add_column :sources, :description, :string
add_column :sources, :image_url, :string
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4525e45

Please sign in to comment.