Skip to content
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

UX: use group full name, add settings for description & ordering #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 22 additions & 2 deletions common/common.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
.about__main-content {
.--custom-group {
max-width: unset !important; // ovverides ridiculously specific core style
margin-top: 3em;
@if $capitalize-names == "true" {
h3 {
a {
color: var(--primary);
&:hover {
color: var(--tertiary);
}
}
@if $capitalize-names == "true" {
&::first-letter {
text-transform: capitalize;
}
}
}

p {
margin-top: 0;
color: var(--primary-high);
}

&.--has-description {
h3 {
text-transform: capitalize;
margin-bottom: 0;
}
}
}
Expand Down
48 changes: 41 additions & 7 deletions javascripts/discourse/components/additional-about-groups.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import { service } from "@ember/service";
import { htmlSafe } from "@ember/template";
import AboutPageUsers from "discourse/components/about-page-users";
import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";

export default class AdditionalAboutGroups extends Component {
@service store;
@service site;

awesomerobot marked this conversation as resolved.
Show resolved Hide resolved
@tracked groups = [];
@tracked loading = false;

Expand All @@ -17,7 +19,7 @@ export default class AdditionalAboutGroups extends Component {
}

groupName(group) {
return group.name.replace(/_/g, " ");
return group.full_name || group.name.replace(/[_-]/g, " ");
}

@action
Expand All @@ -26,13 +28,26 @@ export default class AdditionalAboutGroups extends Component {
try {
const groupsSetting = settings.about_groups?.split("|").map(Number) || [];

const groupsToFetch = this.site.groups.filter((group) =>
let groupsToFetch = this.site.groups.filter((group) =>
groupsSetting.includes(group.id)
);

// ordered alphabetically by default
if (settings.order_additional_groups === "order of creation") {
groupsToFetch.sort((a, b) => a.id - b.id);
} else if (
settings.order_additional_groups === "order of theme setting"
) {
groupsToFetch.sort(
(a, b) => groupsSetting.indexOf(a.id) - groupsSetting.indexOf(b.id)
);
}

const groupPromises = groupsToFetch.map(async (group) => {
try {
const groupDetails = await this.loadGroupDetails(group.name);
group.members = await this.loadGroupMembers(group.name);
Object.assign(group, groupDetails);
return group;
} catch (error) {
// eslint-disable-next-line no-console
Expand All @@ -58,11 +73,21 @@ export default class AdditionalAboutGroups extends Component {
}
}

async loadGroupDetails(groupName) {
try {
const response = await fetch(`/g/${groupName}.json`);
const data = await response.json();
Comment on lines +78 to +79
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, btw, I didn't catch that earlier but I don't think we should be using fetch here 🤔

you know how our ajax helper is automatically adding the subfolder path, Discourse-Logged-In/Discourse-Track-View/Discourse-Track-View-Topic-Id/Discourse-Present headers, other custom headers, handles automatic sign-out and read-only mode, etc etc.

well, with fetch you don't have any of that 😄

return data.group;
} catch (error) {
// eslint-disable-next-line no-console
console.error(`Error loading details for group ${groupName}:`, error);
return "";
}
}

async loadGroupMembers(groupName) {
try {
const response = await fetch(
`/groups/${groupName}/members.json?offset=0&order=&asc=true`
);
const response = await fetch(`/g/${groupName}/members.json`);
const data = await response.json();
return data.members || [];
} catch (error) {
Expand All @@ -76,8 +101,17 @@ export default class AdditionalAboutGroups extends Component {
<ConditionalLoadingSpinner @condition={{this.loading}}>
{{#if this.groups}}
{{#each this.groups as |group|}}
<section class="about__{{group.name}} --custom-group">
<h3>{{this.groupName group}}</h3>
<section
class="about__{{group.name}}
--custom-group
{{if settings.show_group_description '--has-description'}}"
>
<h3>
<a href="/g/{{group.name}}">{{this.groupName group}}</a>
</h3>
{{#if settings.show_group_description}}
<p>{{htmlSafe group.bio_cooked}}</p>
{{/if}}
<AboutPageUsers
@users={{group.members}}
@truncateAt={{settings.show_initial_members}}
Expand Down
2 changes: 2 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ en:
about_groups: "Groups to show on the about page, groups with 0 members are automatically hidden."
show_initial_members: "Number of members to show on initial load for each group, others will be hidden behing a 'show more' button."
capitalize_names: "Capitalize the names of the groups on the about page."
order_additional_groups: "Reorder the groups added by this theme component. Note: won't change the order of default admin and moderator groups."
show_group_description: "Show the group description on the about page."
12 changes: 12 additions & 0 deletions settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ show_initial_members:
capitalize_names:
default: true
type: bool

order_additional_groups:
default: "alphabetically"
type: enum
choices:
- "alphabetically"
- "order of creation"
- "order of theme setting"

show_group_description:
default: false
type: bool
8 changes: 4 additions & 4 deletions spec/system/add_groups_to_about_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
it "renders the groups specified in the about_groups theme setting" do
visit "/about"

expect(about_groups_component).to have_group_with_name("Group1")
expect(about_groups_component).to have_group_with_name("Group2")
expect(about_groups_component).to have_group_with_name("group1")
expect(about_groups_component).to have_group_with_name("group2")
expect(about_groups_component).to have_group_with_member("user1")
expect(about_groups_component).to have_group_with_member("user2")
end
Expand All @@ -30,8 +30,8 @@

visit "/about"

expect(about_groups_component).to have_group_with_name("Group1")
expect(about_groups_component).to have_no_group_with_name("Group2")
expect(about_groups_component).to have_group_with_name("group1")
expect(about_groups_component).to have_no_group_with_name("group2")
expect(about_groups_component).to have_group_with_member("user1")
expect(about_groups_component).to have_no_group_with_member("user2")
end
Expand Down