Skip to content

Commit 3f7ceb9

Browse files
authored
[Feat]: Communities Country Picker (#241)
* feat(): add country picker for communities
1 parent 630faed commit 3f7ceb9

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

angular-hub/src/app/pages/communities/index.page.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { Component } from '@angular/core';
1+
import { Component, computed, signal } from '@angular/core';
22
import { CommunityCardComponent } from '../../components/cards/community-card.component';
33
import { toSignal } from '@angular/core/rxjs-interop';
44
import { injectLoad, RouteMeta } from '@analogjs/router';
55
import { load } from './index.server';
66
import { Title } from '@angular/platform-browser';
77
import { JsonLdService } from '../../services/json-ld.service';
8+
import { DropdownModule } from 'primeng/dropdown';
9+
import { FormsModule } from '@angular/forms';
810

911
export const routeMeta: RouteMeta = {
1012
meta: [
@@ -18,7 +20,7 @@ export const routeMeta: RouteMeta = {
1820
@Component({
1921
selector: 'app-communities',
2022
standalone: true,
21-
imports: [CommunityCardComponent],
23+
imports: [CommunityCardComponent, DropdownModule, FormsModule],
2224
template: `
2325
<aside
2426
class="h-36 w-full flex flex-col justify-center items-center mb-8 bg-no-repeat bg-auto md:bg-cover px-4"
@@ -28,8 +30,22 @@ export const routeMeta: RouteMeta = {
2830
<h2 class="text-2xl text-center">Curated list of Angular Communities</h2>
2931
</aside>
3032
33+
<form
34+
class="w-full flex flex-col sm:flex-row justify-center items-center gap-2 mb-8"
35+
>
36+
<p-dropdown
37+
name="language"
38+
[options]="countries()"
39+
[style]="{ width: '230px' }"
40+
[showClear]="true"
41+
placeholder="Select a country"
42+
[ngModel]="selectedCountry()"
43+
(ngModelChange)="selectedCountry.set($event)"
44+
/>
45+
</form>
46+
3147
<ul class="flex flex-wrap justify-center gap-x-8 gap-y-4 px-8">
32-
@for (community of communities(); track community.name) {
48+
@for (community of filteredCommunities(); track community.name) {
3349
<li>
3450
<app-community-card [community]="community"></app-community-card>
3551
</li>
@@ -39,6 +55,33 @@ export const routeMeta: RouteMeta = {
3955
})
4056
export default class CommunitiesComponent {
4157
communities = toSignal(injectLoad<typeof load>(), { requireSync: true });
58+
selectedCountry = signal(null);
59+
countries = computed(() =>
60+
this.communities()
61+
.map((community) => community.location)
62+
.reduce<string[]>((acc, curr) => {
63+
const location = curr
64+
? curr.includes(',')
65+
? curr.split(',').at(-1)
66+
: curr
67+
: '';
68+
if (location && !acc.includes(location.trim())) {
69+
acc.push(location.trim());
70+
}
71+
return acc;
72+
}, [])
73+
.sort((a, b) =>
74+
a.toLocaleUpperCase().localeCompare(b.toLocaleUpperCase()),
75+
),
76+
);
77+
78+
filteredCommunities = computed(() =>
79+
this.communities().filter((community) =>
80+
this.selectedCountry()
81+
? community.location?.includes(this.selectedCountry() ?? '')
82+
: true,
83+
),
84+
);
4285

4386
constructor(
4487
private title: Title,

angular-hub/src/public/assets/data/community.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@
229229
{
230230
"name": "Angular Community Meetup",
231231
"type": "meetup",
232-
"location": "Earth",
232+
"location": "Worldwide Online",
233233
"url": "https://angularcommunity.net/home",
234234
"logo": "https://pbs.twimg.com/profile_images/1547959576015749120/96f233Pr_400x400.jpg",
235235
"twitter": "https://twitter.com/angular_meetup",
@@ -293,7 +293,7 @@
293293
{
294294
"name": "Angular Costa Rica",
295295
"type": "meetup",
296-
"location": "San Jose, Costa rica",
296+
"location": "San Jose, Costa Rica",
297297
"url": "https://www.facebook.com/angularcostarica",
298298
"logo": "https://pbs.twimg.com/profile_images/1275887771048083459/SldZRi5t_400x400.jpg",
299299
"twitter": "https://twitter.com/AngularCR",
@@ -831,7 +831,7 @@
831831
{
832832
"name": "ngGirls",
833833
"type": "workshop",
834-
"location": null,
834+
"location": "Worldwide Onsite",
835835
"url": "https://www.ng-girls.org/",
836836
"logo": "https://pbs.twimg.com/profile_images/1757125339090653184/5wgfX_ZD_400x400.jpg",
837837
"twitter": "https://twitter.com/AngularGirls",
@@ -992,7 +992,7 @@
992992
{
993993
"name": "Ng Asia",
994994
"type": "meetup",
995-
"location": null,
995+
"location": "Worldwide Online",
996996
"url": "https://www.youtube.com/@NgAsiaAngular/streams",
997997
"logo": "https://pbs.twimg.com/profile_images/1748238047056191488/QArIjHBp_400x400.jpg",
998998
"twitter": "https://twitter.com/angular_asia",

0 commit comments

Comments
 (0)