Fix/improve edits for listings (#2555)
* Fix the edit process for listings * Add category to listing * Fix issue in listing update
This commit is contained in:
parent
834b9423da
commit
3f92ac4919
6 changed files with 44 additions and 7 deletions
|
|
@ -165,7 +165,6 @@
|
|||
a {
|
||||
color: $medium-gray;
|
||||
color: var(--theme-secondary-color, $medium-gray);
|
||||
font-style: italic;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,8 +35,7 @@ class ClassifiedListingsController < ApplicationController
|
|||
@classified_listing.published = true
|
||||
@classified_listing.organization_id = current_user.organization_id if @classified_listing.post_as_organization.to_i == 1
|
||||
if @classified_listing.save
|
||||
CacheBuster.new.bust("/listings")
|
||||
CacheBuster.new.bust("/listings?i=i")
|
||||
clear_listings_cache
|
||||
available_credits.limit(number_of_credits_needed).update_all(spent: true)
|
||||
redirect_to "/listings"
|
||||
else
|
||||
|
|
@ -63,9 +62,12 @@ class ClassifiedListingsController < ApplicationController
|
|||
@classified_listing.save
|
||||
@classified_listing.remove_from_index!
|
||||
elsif params[:classified_listing][:body_markdown].present? && @classified_listing.bumped_at > 24.hours.ago
|
||||
@classified_listing.body_markdown = params[:classified_listing][:body_markdown]
|
||||
@classified_listing.title = params[:classified_listing][:title] if params[:classified_listing][:title]
|
||||
@classified_listing.body_markdown = params[:classified_listing][:body_markdown] if params[:classified_listing][:body_markdown]
|
||||
@classified_listing.tag_list = params[:classified_listing][:tag_list] if params[:classified_listing][:tag_list]
|
||||
@classified_listing.save
|
||||
end
|
||||
clear_listings_cache
|
||||
redirect_to "/listings"
|
||||
end
|
||||
|
||||
|
|
@ -81,4 +83,9 @@ class ClassifiedListingsController < ApplicationController
|
|||
accessible = %i[title body_markdown category tag_list contact_via_connect post_as_organization action]
|
||||
params.require(:classified_listing).permit(accessible)
|
||||
end
|
||||
|
||||
def clear_listings_cache
|
||||
CacheBuster.new.bust("/listings")
|
||||
CacheBuster.new.bust("/listings?i=i")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -165,6 +165,7 @@ export class Listings extends Component {
|
|||
const allListings = listings.map(listing => (
|
||||
<SingleListing
|
||||
onAddTag={this.addTag}
|
||||
onChangeCategory={this.selectCategory}
|
||||
listing={listing}
|
||||
currentUserId={currentUserId}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { h, Component } from 'preact';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
export const SingleListing = ({listing, onAddTag, currentUserId}) => {
|
||||
export const SingleListing = ({listing, onAddTag, currentUserId, onChangeCategory}) => {
|
||||
const tagLinks = listing.tag_list.map(tag => (
|
||||
<a href={`/listings?t=${tag}`} onClick={e => onAddTag(e, tag)} data-no-instant>{tag}</a>
|
||||
));
|
||||
|
|
@ -13,7 +13,10 @@ export const SingleListing = ({listing, onAddTag, currentUserId}) => {
|
|||
<div className="single-classified-listing-body" dangerouslySetInnerHTML={{ __html: listing.processed_html }} />
|
||||
<div className="single-classified-listing-tags">{ tagLinks }</div>
|
||||
<div className="single-classified-listing-author-info">
|
||||
<a href={`/${listing.author.username}`}>{listing.author.name}</a> {editButton}
|
||||
<a href={`/listings/${listing.category}`} onClick={e => onChangeCategory(e, listing.category)}>{listing.category}</a>
|
||||
・
|
||||
<a href={`/${listing.author.username}`}>{listing.author.name}</a>
|
||||
{editButton}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -23,5 +26,6 @@ export const SingleListing = ({listing, onAddTag, currentUserId}) => {
|
|||
SingleListing.propTypes = {
|
||||
listing: PropTypes.object.isRequired,
|
||||
onAddTag: PropTypes.func.isRequired,
|
||||
onChangeCategory: PropTypes.func.isRequired,
|
||||
currentUserId: PropTypes.number,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -20,7 +20,18 @@
|
|||
<h2>
|
||||
Markdown: You can only modify within the first 24 hours of listing/bumping
|
||||
</h2>
|
||||
<%= f.text_area :body_markdown%>
|
||||
<div class="field">
|
||||
<%= f.label "title", "Title" %>
|
||||
<%= f.text_field "title", maxlength: 128, placeholder: "128 characters max, plain text" %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label "body_markdown", "Body Markdown" %>
|
||||
<%= f.text_area "body_markdown", maxlength: 400, placeholder: "400 characters max, 12 line break max, no images allowed" %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label "tag_list", "Tags" %>
|
||||
<%= f.text_field "tag_list", value: @classified_listing.cached_tag_list, placeholder: "8 tags max, comma separated, no spaces or special characters" %>
|
||||
</div>
|
||||
<%= f.submit "Update Body Markdown" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
@ -113,5 +113,20 @@ RSpec.describe "/listings", type: :request do
|
|||
}
|
||||
expect(ClassifiedListing.last.body_markdown).not_to eq("hello new markdown")
|
||||
end
|
||||
it "updates other fields" do
|
||||
put "/listings/#{classified_listing.id}", params: {
|
||||
classified_listing: { body_markdown: "hello new markdown", title: "New title!", tag_list: "new, tags, hey" }
|
||||
}
|
||||
expect(ClassifiedListing.last.title).to eq("New title!")
|
||||
expect(ClassifiedListing.last.cached_tag_list).to include("hey")
|
||||
end
|
||||
it "does not update other fields" do
|
||||
classified_listing.update_column(:bumped_at, 50.hours.ago)
|
||||
put "/listings/#{classified_listing.id}", params: {
|
||||
classified_listing: { body_markdown: "hello new markdown", title: "New title!", tag_list: "new, tags, hey" }
|
||||
}
|
||||
expect(ClassifiedListing.last.title).not_to eq("New title!")
|
||||
expect(ClassifiedListing.last.cached_tag_list).not_to include("hey")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue