Skip to content

Commit

Permalink
Add search by old names & old names section
Browse files Browse the repository at this point in the history
* Add search by old names & old names section

* fix package json

Co-authored-by: Blue <[email protected]>
  • Loading branch information
xxshady and C0kkie authored Nov 28, 2022
1 parent a3014b0 commit e591a77
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
19 changes: 18 additions & 1 deletion src/components/Content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
<pre v-if="native.comment !== undefined && native.comment.trim().length > 0">{{ native.comment }}</pre>
<span v-else class="no-description">No description</span>
</div>
<div class="description-section">
<div class="section-header">Old names</div>

<pre v-if="nativeOldNames.length">{{ nativeOldNames }}</pre>
<span v-else class="no-description">No old names</span>
</div>
</div>
<div class="content-hash-history">
<div class="content-placeholder"></div>
Expand Down Expand Up @@ -102,7 +108,7 @@ import { NativeAlt } from '@/models/Native';
export default class Content extends Vue {
@Prop() private hash!: string;
private get native() {
private get native(): NativeAlt {
return this.$store.state.nativesByHash[this.hash];
}
Expand All @@ -125,6 +131,17 @@ export default class Content extends Vue {
return history;
}
private get nativeOldNames() {
const { oldNames = [], old_names = [] } = this.native;
if (!(oldNames.length || old_names.length)) return [];
return [
...oldNames, // altv names
...(oldNames.length ? " " : []),
...old_names // GTA_NAMES
].join("\n");
}
@Watch('native', { immediate: false, deep: true })
private onNativeChange(to: NativeAlt, from: NativeAlt) {
if (to && to.altName) {
Expand Down
1 change: 1 addition & 0 deletions src/models/Native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface Native {
hashes: NativeHash;
altName: string;
oldNames: string[];
old_names?: string[];
}

export interface NativeParam {
Expand Down
26 changes: 19 additions & 7 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export default new Vuex.Store({

ctx.commit('init', { nativesByCat, nativesByHash, nativesCount, nativesNamed, nativesOrigNamed });
},
search(ctx, str) {
const result: any[] = [];
search(ctx, str: string) {
const result: NativeAlt[] = [];
const strs = str.split(' ')
.flatMap((s: string) => s.split('_'))
.filter((s: string) => s.length > 0)
Expand All @@ -83,16 +83,27 @@ export default new Vuex.Store({
++found;
} else if (n.jhash!.toLowerCase() === s) {
++found;
} else if (n.hashes) {
for (const hash of Object.values(n.hashes)) {
if (hash.toLowerCase() === s) {
} else if (n.hashes || n.oldNames || n.old_names) {
let hashFound = false;
if (n.hashes) {
for (const hash of Object.values(n.hashes)) {
if (hash.toLowerCase() === s) {
++found;
hashFound = true;
break;
}
}
}

if (!hashFound) {
if (n.oldNames?.find(name => name.toLowerCase().includes(s))) {
++found;
} else if (n.old_names?.find(name => name.toLowerCase().replace(/_/gm, '').includes(s))) {
++found;
break;
}
}
}
}

if (found === strs.length) {
++count;
result.push(n);
Expand All @@ -105,6 +116,7 @@ export default new Vuex.Store({
}
}


if (count >= 200) {
break;
}
Expand Down

0 comments on commit e591a77

Please sign in to comment.