Skip to content

Commit

Permalink
add product/subproduct search. finalize product page w/ descs
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Apr 23, 2024
1 parent 3f70e01 commit 84e3934
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 134 deletions.
4 changes: 4 additions & 0 deletions interfaces/carddata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export interface ICard {
name: string;
tags: string[];

product: string;
subproduct: string;
locale: string;

imageClass?: string;
meta: Record<string, number>;
}
1 change: 1 addition & 0 deletions interfaces/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface IProductFilter {
export interface IProductDefinition {
id: string;
name: string;
desc: string;
}

export interface IProduct extends IProductDefinition {
Expand Down
23 changes: 10 additions & 13 deletions search/operators/card.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
import { type ICardHelp } from '../../interfaces';
import { partialWithOptionalExactTextOperator } from './_helpers';

export const card = partialWithOptionalExactTextOperator(
['card', 'id', 'code'],
'id'
);
export const card = partialWithOptionalExactTextOperator(['card', 'id'], 'id');

export const cardDescription: ICardHelp = {
name: 'Code / ID',
id: 'code',
name: 'ID',
id: 'id',

icon: 'finger-print-outline',

color: '#8360c3',

help: `
You can find cards that match a certain code/id by using the \`id:\` operator.
You can find cards that match a certain id by using the \`id:\` operator.
This operator is special, you may also search without using the operator.
`,

examples: [
{
example: '`5HY/W83-E001`',
explanation: 'Find specifically the card matching 5HY/W83-E001',
example: '`OATH/1`',
explanation: 'Find specifically the card matching OATH/1',
},
{
example: '`id:=5HY/W83-E001`',
explanation: 'Find specifically the card matching 5HY/W83-E001.',
example: '`id:=OATH/1`',
explanation: 'Find specifically the card matching OATH/1.',
},
{
example: '`-id:5HY/W83`',
explanation: 'Exclude the cards matching 5HY/W83.',
example: '`-id:OATH`',
explanation: 'Exclude the cards matching OATH.',
},
],
};
75 changes: 0 additions & 75 deletions search/operators/in.ts

This file was deleted.

3 changes: 2 additions & 1 deletion search/operators/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './bare';
export * from './card';
export * from './in';
export * from './name';
export * from './product';
export * from './subproduct';
export * from './tag';
16 changes: 8 additions & 8 deletions search/operators/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ If a name has spaces in its name, you must use quotation marks around the name.

examples: [
{
example: '`Nino Nakano`',
explanation: 'Cards with "Nino Nakano" in their name.',
example: '`Alchemist`',
explanation: 'Cards with "Alchemist" in their name.',
},
{
example: '`name:nakano`',
explanation: 'Cards that have "Nakano" in their name.',
example: '`name:alchemist`',
explanation: 'Cards that have "alchemist" in their name.',
},
{
example: '`name:"=Nino Nakano"`',
explanation: 'Cards that are called exactly "Nino Nakano".',
example: '`name:"=Alchemist"`',
explanation: 'Cards that are called exactly "Alchemist".',
},
{
example: '`-name:"Futaro Uesugi"`',
explanation: 'Cards without "Futaro Uesugi" in their name.',
example: '`-name:"Alchemist"`',
explanation: 'Cards without "Alchemist" in their name.',
},
],
};
28 changes: 28 additions & 0 deletions search/operators/product.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { type ICardHelp } from '../../interfaces';
import { exactTextOperator } from './_helpers';

export const product = exactTextOperator(['product', 'game'], 'product');

export const productDescription: ICardHelp = {
name: 'Product',
id: 'id',

icon: 'game-controller-outline',

color: '#d0312d',

help: `
You can find cards that are associated with a certain product/game by using the \`product:\` operator.
`,

examples: [
{
example: '`product:oath`',
explanation: 'Find cards belonging to Oath.',
},
{
example: '`-product:root`',
explanation: 'Exclude the cards belonging to Root.',
},
],
};
31 changes: 31 additions & 0 deletions search/operators/subproduct.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { type ICardHelp } from '../../interfaces';
import { exactTextOperator } from './_helpers';

export const subproduct = exactTextOperator(
['subproduct', 'expansion'],
'subproduct'
);

export const subproductDescription: ICardHelp = {
name: 'Subproduct',
id: 'id',

icon: 'hardware-chip-outline',

color: '#ffa500',

help: `
You can find cards that are associated with a certain subproduct/expansion by using the \`subproduct:\` operator.
`,

examples: [
{
example: '`subproduct:clockwork-1`',
explanation: 'Find cards belonging to the first Clockwork expansion.',
},
{
example: '`-subproduct:exiles-partisans`',
explanation: 'Exclude the cards belonging to Exiles & Partisans.',
},
],
};
8 changes: 4 additions & 4 deletions search/operators/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ Almost every card will have a tag. You can find a list of valid tags by using th

examples: [
{
example: '`tag:"Army"`',
explanation: 'Cards that have the Army tag.',
example: '`tag:"Power"`',
explanation: 'Cards that have the Power tag.',
},
{
example: '`tag:"Army,Clock Cleanset"`',
explanation: 'Cards that have the Army and Clock Cleanse triggers.',
example: '`tag:"Power,Arcane"`',
explanation: 'Cards that have the Power and Arcane triggers.',
},
{
example: '`tag:none`',
Expand Down
34 changes: 16 additions & 18 deletions search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import * as parser from 'search-query-parser';

import { type ICard } from '../interfaces';

import { bare, card, inC, name, tag } from './operators';
import { bare, card, name, product, subproduct, tag } from './operators';

const allKeywords = [
['id'], // exact text
['in'], // special operator
['name', 'n'], // loose text
['product', 'game'], // exact text
['subproduct', 'expansion'], // exact text
['tag'], // array search
];

const operators = [inC, card, name, tag];
const operators = [card, name, product, subproduct, tag];

export function properOperatorsInsteadOfAliases(
result: parser.SearchParserResult
Expand Down Expand Up @@ -48,18 +49,6 @@ const allQueryFormatters = [
return `${value}`;
},
},
{
key: 'expansion',
includes: 'has',
excludes: 'does not have',
formatter: (result: Record<string, any>) => {
const value = result['expansion'];
const expansions: string[] = isString(value)
? [value]
: (value as unknown as string[]);
return `${expansions.map((x) => `"${x}"`).join(' or ')}`;
},
},
{
key: 'name',
includes: 'contains',
Expand All @@ -70,11 +59,20 @@ const allQueryFormatters = [
},
},
{
key: 'set',
key: 'product',
includes: 'is',
excludes: 'is not',
formatter: (result: Record<string, any>) => {
const value = result['product'];
return `${value}`;
},
},
{
key: 'subproduct',
includes: 'is',
excludes: 'is not',
formatter: (result: Record<string, any>) => {
const value = result['set'];
const value = result['subproduct'];
return `${value}`;
},
},
Expand Down Expand Up @@ -104,7 +102,7 @@ export function queryToText(query: string): string {
.split(' ')
.map((x) => `"${x}"`)
.join(' or ');
return `cards with ${queries} in the name, abilities, expansion, or code`;
return `cards with ${queries} in the name or card id`;
}

const result = properOperatorsInsteadOfAliases(firstResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,8 @@ <h2>No results found</h2>
<ion-select class="themed" [(ngModel)]="querySort" interface="popover" placeholder="Sort Prop"
(ionChange)="redoCurrentSearch()">
<ion-select-option value="name">Name</ion-select-option>
<ion-select-option value="code">Code</ion-select-option>
<ion-select-option value="rarity">Rarity</ion-select-option>
<ion-select-option value="expansion">Expansion</ion-select-option>
<ion-select-option value="side">Side</ion-select-option>
<ion-select-option value="type">Type</ion-select-option>
<ion-select-option value="color">Color</ion-select-option>
<ion-select-option value="level">Level</ion-select-option>
<ion-select-option value="cost">Cost</ion-select-option>
<ion-select-option value="power">Power</ion-select-option>
<ion-select-option value="soul">Soul</ion-select-option>
<ion-select-option value="set">Set</ion-select-option>
<ion-select-option value="release">Release</ion-select-option>
<ion-select-option value="id">ID</ion-select-option>
<ion-select-option value="product">Product</ion-select-option>
</ion-select>

<ion-select class="themed" [(ngModel)]="querySortBy" interface="popover" placeholder="Sort Dir"
Expand Down
6 changes: 6 additions & 0 deletions src/app/sets/sets.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
</a>
</ion-col>
</ion-row>

<ion-row>
<ion-col>
<p>{{ subproduct.desc }}</p>
</ion-col>
</ion-row>
</ion-label>
</ion-item>
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/sets/sets.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class SetsPage implements OnInit {
}

formatSetNameForSearch(productId: string, subproductId: string): string {
return `game:"${productId}" expansion:"${subproductId}"`;
return `product:"${productId}" subproduct:"${subproductId}"`;
}

search(query: string) {
Expand Down
6 changes: 4 additions & 2 deletions src/app/syntax/syntax.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { type ICardHelp } from '../../../interfaces';

import {
cardDescription,
inDescription,
nameDescription,
productDescription,
subproductDescription,
tagDescription,
} from '../../../search/operators';

Expand All @@ -24,8 +25,9 @@ export class SyntaxPage implements OnInit {

public allOperators: ICardHelp[] = [
cardDescription,
inDescription,
nameDescription,
productDescription,
subproductDescription,
tagDescription,
];

Expand Down

0 comments on commit 84e3934

Please sign in to comment.