-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add QuestionComponent
#1404
Merged
Merged
Add QuestionComponent
#1404
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
01bf874
Add base `ApplicationComponent`
pixeldesu 77147cf
Add `QuestionComponent`
pixeldesu 85ff169
Extract question styling from answerbox
pixeldesu 14e75ec
Replace question markup with `QuestionComponent`
pixeldesu ba86b77
Remove obsolete question-related partials
pixeldesu 1e80d75
Adjust class references to question CSS classes
pixeldesu 45bfc51
Remove transferred locales
pixeldesu 75434b3
Tighten inbox entry view spec
pixeldesu 67bf413
Merge branch 'main' into feature/question-component
pixeldesu 44adb0f
Apply review suggestion from @nilsding
pixeldesu 3609c91
Fix rubocop nits
pixeldesu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
@use "sass:map"; | ||
|
||
.question { | ||
&--fixed { | ||
position: absolute; | ||
|
||
&__avatar { | ||
margin-right: map.get($spacers, 2); | ||
border-radius: $avatar-border-radius; | ||
} | ||
|
||
&__text, | ||
&__user { | ||
margin-bottom: 0; | ||
overflow: hidden; | ||
word-break: break-word; | ||
} | ||
|
||
&--sticky { | ||
border-radius: 0; | ||
width: 100%; | ||
z-index: 999; | ||
|
||
@include media-breakpoint-up('sm') { | ||
position: fixed; | ||
position: sticky; | ||
top: $navbar-height; | ||
} | ||
} | ||
|
||
&--hidden { | ||
visibility: hidden; | ||
position: relative; | ||
box-shadow: none; | ||
z-index: -1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationComponent < ViewComponent::Base | ||
include ApplicationHelper | ||
delegate :current_user, to: :helpers | ||
delegate :user_signed_in?, to: :helpers | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
class QuestionComponent < ApplicationComponent | ||
include ApplicationHelper | ||
include BootstrapHelper | ||
include UserHelper | ||
|
||
def initialize(question:, context_user: nil, collapse: true, hide_avatar: false, profile_question: false) | ||
@question = question | ||
@context_user = context_user | ||
@collapse = collapse | ||
@hide_avatar = hide_avatar | ||
@profile_question = profile_question | ||
end | ||
|
||
private | ||
|
||
def author_identifier = @question.author_is_anonymous ? @question.author_identifier : nil | ||
|
||
def follower_question? = [email protected]_is_anonymous && [email protected] && @question.answer_count.positive? | ||
|
||
def hide_avatar? = @hide_avatar || @question.author_is_anonymous | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
en: | ||
answers: | ||
zero: "0 answers" | ||
one: "1 answer" | ||
other: "%{count} answers" | ||
asked_html: "%{user} asked %{time} ago" | ||
visible_to_you: "Only visible to you as it was asked directly" | ||
visible_mod_mode: "You can see this because you are in moderation view" |
30 changes: 30 additions & 0 deletions
30
app/components/question_component/question_component.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
.d-flex | ||
- unless hide_avatar? | ||
.flex-shrink-0 | ||
%a{ href: user_path(@question.user) } | ||
= render AvatarComponent.new(user: @question.user, size: "md", classes: ["question__avatar"]) | ||
.flex-grow-1 | ||
%h6.text-muted.question__user | ||
- if @question.author_is_anonymous | ||
%i.fas.fa-user-secret{ title: t(".anon_hint") } | ||
- if @profile_question && @question.direct | ||
- if user_signed_in? && @question.user == current_user | ||
%i.fa.fa-eye-slash{ data: { bs_toggle: "tooltip", bs_title: t(".visible_to_you") } } | ||
- elsif moderation_view? | ||
%i.fa.fa-eye-slash{ data: { bs_toggle: "tooltip", bs_title: t(".visible_mod_mode") } } | ||
= t(".asked_html", user: user_screen_name(@question.user, context_user: @context_user, author_identifier: author_identifier), time: time_tooltip(@question)) | ||
Check warning on line 15 in app/components/question_component/question_component.html.haml GitHub Actions / haml-lint[haml-lint] app/components/question_component/question_component.html.haml#L15
Raw output
|
||
- if follower_question? | ||
· | ||
%a{ href: question_path(@question.user.screen_name, @question.id), data: { selection_hotkey: "a" } } | ||
= t(".answers", count: @question.answer_count) | ||
.question__body{ data: { controller: @question.long? ? "collapse" : nil } } | ||
.question__text{ class: @question.long? && @collapse ? "collapsed" : "", data: { collapse_target: "content" } } | ||
= question_markdown @question.content | ||
- if @question.long? && @collapse | ||
= render "shared/collapse", type: "question" | ||
- if user_signed_in? | ||
.flex-shrink-0.ms-auto | ||
.btn-group | ||
%button.btn.btn-link.btn-sm.dropdown-toggle{ data: { bs_toggle: :dropdown }, aria: { expanded: false } } | ||
%span.caret | ||
= render "actions/question", question: @question |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,4 @@ | ||
- type ||= nil | ||
.card.questionbox{ data: { id: q.id } } | ||
.card-body{ data: { controller: q.long? ? "collapse" : nil } } | ||
.d-flex | ||
- if type == "discover" | ||
.flex-shrink-0 | ||
%a{ href: user_screen_name(q.user, link_only: true) } | ||
= render AvatarComponent.new(user: q.user, size: "md", classes: ["me-2"]) | ||
.flex-grow-1 | ||
%h6.text-muted.answerbox__question-user | ||
- if type.nil? && q.direct | ||
- if user_signed_in? && q.user == current_user | ||
%i.fa.fa-eye-slash{ data: { bs_toggle: "tooltip", bs_title: t(".visible_to_you") } } | ||
- elsif moderation_view? | ||
%i.fa.fa-eye-slash{ data: { bs_toggle: "tooltip", bs_title: t(".visible_mod_mode") } } | ||
= t("answerbox.header.asked_html", user: user_screen_name(q.user), time: time_tooltip(q)) | ||
- if q.answer_count > 1 | ||
· | ||
%a{ href: question_path(q.user.screen_name, q.id) } | ||
= pluralize(q.answer_count, t("voc.answer")) | ||
.answerbox__question-text{ class: q.long? ? "collapsed" : "", data: { collapse_target: "content" } } | ||
= question_markdown q.content | ||
- if q.long? | ||
= render "shared/collapse", type: "question" | ||
- if user_signed_in? | ||
.flex-shrink-0.ms-auto | ||
.btn-group | ||
%button.btn.btn-link.btn-sm.dropdown-toggle{ data: { bs_toggle: :dropdown }, aria: { expanded: false } } | ||
%span.caret | ||
= render "actions/question", question: q | ||
= render QuestionComponent.new(question: q, hide_avatar: type == "discover" ? false : true, profile_question: true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could put something like "No answers" or "Unanswered" here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zarro answoors found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This technically doesn't appear anyway (answer count must be positive to show uppp), it's just added to match all numerical translation values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then i would suggest to change it to something more fun