Skip to content

Commit

Permalink
Add keyword search on click
Browse files Browse the repository at this point in the history
  • Loading branch information
dmstern committed Sep 7, 2018
1 parent 3b26ea4 commit c8ed364
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export default class App extends Vue {
private fireSearchFilterEvent() {
this.$nextTick(() => {
EventBus.$emit(Events.FILTER_SEARCH, { filters: this.searchItemsFiltered, query: this.searchInput.value });
EventBus.$emit(Events.FILTER_SEARCH, { filters: this.activeFilters, query: this.searchInput.value });
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/PackageList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class Packages extends Vue {
this.packages.all = await DataStore.Instance.getPackages();
this.packages.loading = false;
this.packages.data = this.packages.all
.filter((item) => args.filters.indexOf(item) >= 0)
.filter((item) => args.filters.every((filter) => filter.matches(item, this.packages.all)))
.filter((item) => {
if (!args.query) {
return true;
Expand Down
22 changes: 20 additions & 2 deletions src/views/PackageDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,17 @@
<span v-else>{{data.currentPackage.displayName}}</span> -->
<CrafterAvatar v-for="(crafter, index) in data.currentPackage.crafters" :key="index" :crafter="crafter"></CrafterAvatar>
</PackageDetailItem>
<PackageDetailItem title="Keywords" :bigContent="false" v-if="data.currentPackage.keywords" :icon="$vuetify.icons.tags">
<v-chip v-for="keyword in data.currentPackage.keywords" :key="keyword">{{keyword}}</v-chip>
<PackageDetailItem title="Keywords" :bigContent="false" v-if="data.currentPackage.tags" :icon="$vuetify.icons.tags">
<v-chip
v-for="(tag, index) in data.currentPackage.tags"
:key="index"
@click="onKeywordClick(tag)"
>
{{tag.value}}
<v-avatar>
<v-icon>{{$vuetify.icons.search}}</v-icon>
</v-avatar>
</v-chip>
</PackageDetailItem>
</v-layout>
</v-flex>
Expand All @@ -207,6 +216,8 @@ import Config from '../../types/Config';
import PackageDetailItem from '@/components/PackageDetailItem.vue';
import CodeBlock from '@/components/CodeBlock.vue';
import CrafterAvatar from '@/components/CrafterAvatar.vue';
import { EventBus, Events } from '@/services/event-bus';
import { setTimeout } from 'timers';
@Component({
components: {
Expand Down Expand Up @@ -305,6 +316,13 @@ export default class PackageDetail extends Vue {
};
}
}
private onKeywordClick(tag) {
router.push(`/`);
this.$nextTick(() => {
EventBus.$emit(Events.FILTER_SEARCH, { filters: [tag] });
});
}
}
</script>
Expand Down
4 changes: 4 additions & 0 deletions types/Crafter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ export default class Crafter extends Searchable {
return text;
}

public toString(): string {
return `${this.name}`;
}

public equals(other: Crafter): boolean {
if (this.email && other.email) {
return this.email === other.email;
Expand Down
4 changes: 4 additions & 0 deletions types/Package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ export default class Package extends Searchable implements PackageMetaDataDTO {
}
}

public toString(): string {
return this.name;
}

private url2Name(url: string): string {
if (url.includes('github')) {
return 'github';
Expand Down
2 changes: 2 additions & 0 deletions types/Searchable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export default abstract class Searchable {
public matchesPattern(pattern: string): boolean {
return this.getSearchItemText().some((text) => text.toLowerCase().includes(pattern.toLowerCase()));
}

public abstract toString(): string;
}
4 changes: 4 additions & 0 deletions types/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export class Tag extends Searchable {
return false;
}

public toString(): string {
return this.value;
}

public getSearchItemText(): string[] {
return [
`#${this.value}`,
Expand Down

0 comments on commit c8ed364

Please sign in to comment.