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

View file

@ -825,13 +825,20 @@
? GridType.Summon ? GridType.Summon
: GridType.Character : 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 // Open the search sidebar with the appropriate type
// Pass authUserId to enable collection mode toggle // Pass authUserId to enable collection mode toggle
openSearchSidebar({ openSearchSidebar({
type: opts.type, type: opts.type,
onAddItems: handleAddItems, onAddItems: handleAddItems,
canAddMore: true, canAddMore: true,
authUserId authUserId,
requiredProficiencies
}) })
} }
}) })

View file

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

View file

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