Skip to content

Commit 0bf3737

Browse files
CopilotKagamiChan
andcommitted
Extract hasNosakiInOtherFleets helper to reduce code duplication
Co-authored-by: KagamiChan <3816900+KagamiChan@users.noreply.github.com>
1 parent 008439a commit 0bf3737

1 file changed

Lines changed: 16 additions & 26 deletions

File tree

src/index.tsx

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,20 @@ const PluginAnchorageRepair: React.FC = () => {
202202
equips,
203203
)
204204

205+
// Helper to check if any other fleet has Nosaki in position 1 or 2
206+
const hasNosakiInOtherFleets = (excludeFleetId: number) =>
207+
fleets.some((fleet) => {
208+
if (fleet.api_id === excludeFleetId) return false
209+
const status = getFleetStatus(
210+
fleet,
211+
ships,
212+
$ships,
213+
repairId,
214+
equips,
215+
)
216+
return status.nosakiPresent
217+
})
218+
205219
// Handle changes to slot 1/2 (position 0 or 1)
206220
if (!Number.isNaN(shipIdx) && (shipIdx === 0 || shipIdx === 1)) {
207221
// Check current ship in this slot (before the change)
@@ -232,37 +246,13 @@ const PluginAnchorageRepair: React.FC = () => {
232246
// After 15 min: don't reset
233247
} else if (wasNosaki) {
234248
// Replacing Nosaki with non-Nosaki
235-
// Check if any other fleet still has Nosaki
236-
const otherFleetHasNosaki = fleets.some((fleet) => {
237-
if (fleet.api_id === changedFleetId) return false
238-
const status = getFleetStatus(
239-
fleet,
240-
ships,
241-
$ships,
242-
repairId,
243-
equips,
244-
)
245-
return status.nosakiPresent
246-
})
247-
if (!otherFleetHasNosaki) {
249+
if (!hasNosakiInOtherFleets(changedFleetId)) {
248250
timerState.clearNosakiTimer()
249251
}
250252
}
251253
} else if (wasNosaki) {
252254
// Removing Nosaki from slot 1 or 2 (shipId < 0 means removal)
253-
// Check if any other fleet still has Nosaki
254-
const otherFleetHasNosaki = fleets.some((fleet) => {
255-
if (fleet.api_id === changedFleetId) return false
256-
const status = getFleetStatus(
257-
fleet,
258-
ships,
259-
$ships,
260-
repairId,
261-
equips,
262-
)
263-
return status.nosakiPresent
264-
})
265-
if (!otherFleetHasNosaki) {
255+
if (!hasNosakiInOtherFleets(changedFleetId)) {
266256
timerState.clearNosakiTimer()
267257
}
268258
}

0 commit comments

Comments
 (0)