filter mainhand weapons by job proficiency

This commit is contained in:
Justin Edmund 2025-12-20 02:13:56 -08:00
parent e1fe9810ce
commit 7793715a30
4 changed files with 36 additions and 12 deletions

View file

@ -11,6 +11,7 @@
onClose?: () => void
onAddItems?: (items: SearchResult[]) => void
canAddMore?: boolean
requiredProficiencies?: number[] // For mainhand: restricts to job's proficiencies
}
let {
@ -18,7 +19,8 @@
type = 'weapon',
onClose = () => {},
onAddItems = () => {},
canAddMore = true
canAddMore = true,
requiredProficiencies
}: Props = $props()
// Search state
@ -118,8 +120,12 @@
if (rarityFilters.length > 0) {
params.filters.rarity = rarityFilters
}
if (type === 'weapon' && proficiencyFilters.length > 0) {
params.filters.proficiency1 = proficiencyFilters
if (type === 'weapon') {
// Use required proficiencies (for mainhand) if set, otherwise use user-selected filters
const profs = requiredProficiencies ?? (proficiencyFilters.length > 0 ? proficiencyFilters : undefined)
if (profs && profs.length > 0) {
params.filters.proficiency1 = profs
}
}
let response
@ -264,8 +270,8 @@
</div>
</div>
<!-- Proficiency filters (weapons only) -->
{#if type === 'weapon'}
<!-- Proficiency filters (weapons only, hidden when required proficiencies set) -->
{#if type === 'weapon' && !requiredProficiencies}
<div class="filter-group">
<label class="filter-label">Proficiency</label>
<div class="filter-buttons proficiency-grid">

View file

@ -825,13 +825,20 @@
? GridType.Summon
: GridType.Character
// For mainhand weapons (position -1), restrict to job's proficiencies
const requiredProficiencies =
opts.type === 'weapon' && opts.position === -1 && party.job?.proficiency
? party.job.proficiency.filter((p): p is number => p !== null && p !== undefined && p !== 0)
: undefined
// Open the search sidebar with the appropriate type
// Pass authUserId to enable collection mode toggle
openSearchSidebar({
type: opts.type,
onAddItems: handleAddItems,
canAddMore: true,
authUserId
authUserId,
requiredProficiencies
})
}
})

View file

@ -19,13 +19,16 @@
canAddMore?: boolean
/** User ID to enable collection search mode */
authUserId?: string
/** Required proficiencies for mainhand weapon selection */
requiredProficiencies?: number[]
}
let {
type = 'weapon',
onAddItems = () => {},
canAddMore = true,
authUserId
authUserId,
requiredProficiencies
}: Props = $props()
// Search state (local UI state)
@ -95,10 +98,15 @@
})
// Build filters object for query
// Use requiredProficiencies for mainhand selection if set, otherwise use user-selected filters
const effectiveProficiencies = $derived(
requiredProficiencies ?? (proficiencyFilters.length > 0 ? proficiencyFilters : undefined)
)
const filters = $derived<SearchFilters>({
element: elementFilters.length > 0 ? elementFilters : undefined,
rarity: rarityFilters.length > 0 ? rarityFilters : undefined,
proficiency: type === 'weapon' && proficiencyFilters.length > 0 ? proficiencyFilters : undefined
proficiency: type === 'weapon' && effectiveProficiencies ? effectiveProficiencies : undefined
})
// Helper to map collection items to search result format with collectionId
@ -394,8 +402,8 @@
</div>
</div>
<!-- Proficiency filters (weapons only) -->
{#if type === 'weapon'}
<!-- Proficiency filters (weapons only, hidden when required proficiencies set for mainhand) -->
{#if type === 'weapon' && !requiredProficiencies}
<div class="filter-group">
<label class="filter-label">Proficiency</label>
<div class="filter-buttons proficiency-grid">

View file

@ -8,10 +8,12 @@ interface SearchSidebarOptions {
canAddMore?: boolean
/** User ID to enable collection search mode. If not provided, only "All Items" mode is available. */
authUserId?: string
/** Required proficiencies for mainhand weapon selection */
requiredProficiencies?: number[]
}
export function openSearchSidebar(options: SearchSidebarOptions) {
const { type, onAddItems, canAddMore = true, authUserId } = options
const { type, onAddItems, canAddMore = true, authUserId, requiredProficiencies } = options
// Open the sidebar with the search component
const title = `Search ${type.charAt(0).toUpperCase() + type.slice(1)}s`
@ -19,7 +21,8 @@ export function openSearchSidebar(options: SearchSidebarOptions) {
type,
onAddItems,
canAddMore,
authUserId
authUserId,
requiredProficiencies
})
}