> For the complete documentation index, see [llms.txt](https://docs.wellcomecollection.org/request-for-comments-rfcs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wellcomecollection.org/request-for-comments-rfcs/086-item-viewer-refactor/12-phase-6-duplicate-calls.md).

# Phase 6: Eliminate Duplicate Index Calls

[← Back to Index](/request-for-comments-rfcs/086-item-viewer-refactor.md)

**Effort:** 30 minutes\
**Risk:** Low\
**Priority:** Medium\
**Previous:** [Phase 5: Restriction Status](/request-for-comments-rfcs/086-item-viewer-refactor/11-phase-5-restriction-status.md)\
**Next:** [Phase 7: Cleanup](/request-for-comments-rfcs/086-item-viewer-refactor/13-phase-7-cleanup.md)

## Goal

Since `currentCanvasIndex` is now in context (from Phase 1), remove all duplicate `queryParamToArrayIndex(query.canvas)` calls across components.

## Why?

**Before:**

```typescript
// Thumbnails.tsx
const index = queryParamToArrayIndex(query.canvas);

// NoScriptImage.tsx
const index = queryParamToArrayIndex(query.canvas);

// MultipleManifestList.tsx
const index = queryParamToArrayIndex(query.canvas);
```

**Problem:** Same calculation repeated in 3+ files.

**After:**

```typescript
const { currentCanvasIndex } = useItemViewerContextV2();
```

Single source of truth!

## Files to Update

Find all occurrences:

```bash
cd content/webapp
grep -r "queryParamToArrayIndex(query.canvas)" .
```

### Expected files (update each):

1. **`Thumbnails.tsx`** (lines 38, 49)
2. **`NoScriptImage.tsx`** (line 42)
3. **`MultipleManifestList.tsx`** (lines 23, 37)
4. Any others found

### Replace pattern:

```typescript
// OLD:
const index = queryParamToArrayIndex(query.canvas);
// or
queryParamToArrayIndex(query.canvas)

// NEW:
const { currentCanvasIndex } = useItemViewerContextV2();
// or just use currentCanvasIndex directly
```

## Testing

* [ ] Thumbnails highlight correct canvas
* [ ] NoScript image shows correct canvas
* [ ] Multiple manifest list shows correct position
* [ ] All components that use index still work

## Success Criteria

* [ ] No more `queryParamToArrayIndex(query.canvas)` calls in consuming components
* [ ] All components use `currentCanvasIndex` from context
* [ ] Test coverage maintained

## Time: \~30 minutes

***

**Next:** [Phase 7: Cleanup](/request-for-comments-rfcs/086-item-viewer-refactor/13-phase-7-cleanup.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wellcomecollection.org/request-for-comments-rfcs/086-item-viewer-refactor/12-phase-6-duplicate-calls.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
