-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "Any" option for conqueror dropdown select and fix trade search bug
- Loading branch information
Showing
8 changed files
with
208 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script lang="ts"> | ||
import { openQueryTrade, type Query } from '$lib/utils/trade_utils'; | ||
export let queries: Query[]; | ||
export let showTradeLinks = false; | ||
$: console.log(showTradeLinks); | ||
$: hasMultipleQueries = queries.length > 1; | ||
const handleOnClick = () => { | ||
if (queries.length === 1) { | ||
// if all filter fit into a single query, link straight to trade website | ||
openQueryTrade(queries[0]); | ||
} else if (hasMultipleQueries) { | ||
// otherwise toggle display of batched trade links | ||
showTradeLinks = !showTradeLinks; | ||
} | ||
}; | ||
</script> | ||
|
||
<button | ||
class="p-1 px-3 bg-blue-500/40 rounded disabled:bg-blue-900/40 mr-2" | ||
on:click={handleOnClick} | ||
disabled={!queries}> | ||
{hasMultipleQueries ? (showTradeLinks ? 'Hide Trade Links' : 'Show Trade Links') : 'Trade'} | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script lang="ts"> | ||
import { openQueryTrade, type Query } from '$lib/utils/trade_utils'; | ||
// queries to display trade link buttons for | ||
export let queries: Query[]; | ||
</script> | ||
|
||
<div class="flex flex-wrap gap-2.5 my-2"> | ||
{#each queries as query, index} | ||
<button class="p-1 px-3 bg-blue-500/40 rounded" on:click={() => openQueryTrade(query)}> | ||
Trade Batch {index + 1} | ||
</button> | ||
{/each} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export type Filter = { | ||
id: string; | ||
value: { min: number; max: number }; | ||
disabled?: boolean; | ||
}; | ||
export type FilterGroup = { | ||
type: string; | ||
value: { min: number }; | ||
filters: Filter[]; | ||
disabled: boolean; | ||
}; | ||
export type Query = { | ||
query: { | ||
status: { | ||
option: string; | ||
}; | ||
stats: FilterGroup[]; | ||
}; | ||
sort: { | ||
price: string; | ||
}; | ||
}; | ||
|
||
export const filtersToFilterGroup = (filters: Filter[], disabled: boolean): FilterGroup => ({ | ||
type: 'count', | ||
value: { min: 1 }, | ||
filters: filters, | ||
disabled: disabled | ||
}); | ||
|
||
export const filterGroupsToQuery = (FilterGroups: FilterGroup[]): Query => ({ | ||
query: { | ||
status: { | ||
option: 'online' | ||
}, | ||
stats: FilterGroups | ||
}, | ||
sort: { | ||
price: 'asc' | ||
} | ||
}); | ||
|
||
export const openQueryTrade = (query: Query) => { | ||
const url = new URL('https://www.pathofexile.com/trade/search/Necropolis'); | ||
url.searchParams.set('q', JSON.stringify(query)); | ||
window.open(url, '_blank'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Break an array into chunks of the given size | ||
* | ||
* e.g. for chunk size 2: | ||
* | ||
* [1, 2, 3, 4, 5] => [[1, 2], [3, 4], [5]] | ||
*/ | ||
export const chunkArray = <T>(inputArray: Array<T>, chunkSize: number): Array<T>[] => | ||
inputArray.reduce((resultArray, item, index) => { | ||
const chunkIndex = Math.floor(index / chunkSize); | ||
|
||
if (!resultArray[chunkIndex]) { | ||
resultArray[chunkIndex] = []; // start a new chunk | ||
} | ||
|
||
resultArray[chunkIndex].push(item); | ||
|
||
return resultArray; | ||
}, [] as Array<T>[]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.