-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
167 additions
and
71 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
25 changes: 11 additions & 14 deletions
25
src/views/components/database/quest/editors/earnings/QuestEarningItem.tsx
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
16 changes: 5 additions & 11 deletions
16
src/views/components/database/quest/editors/earnings/QuestEarningMoney.tsx
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
22 changes: 9 additions & 13 deletions
22
src/views/components/database/quest/editors/earnings/QuestEarningPokemon.tsx
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
7 changes: 7 additions & 0 deletions
7
src/views/components/database/quest/editors/earnings/QuestEarningProps.tsx
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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
import { DbSymbol } from '@modelEntities/dbSymbol'; | ||
import { StudioQuestEarning } from '@modelEntities/quest'; | ||
import { MutableRefObject, RefObject } from 'react'; | ||
|
||
export type QuestEarningProps = { | ||
earning: StudioQuestEarning; | ||
refs: { | ||
entityRef: MutableRefObject<DbSymbol | undefined>; | ||
inputRef: RefObject<HTMLInputElement>; | ||
}; | ||
checkIsValid?: () => void; | ||
}; |
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
42 changes: 42 additions & 0 deletions
42
src/views/components/database/quest/editors/useEarningQuest.ts
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,42 @@ | ||
import { DbSymbol } from '@modelEntities/dbSymbol'; | ||
import { StudioQuestEarning } from '@modelEntities/quest'; | ||
import { assertUnreachable } from '@utils/assertUnreachable'; | ||
import { useRef, useState } from 'react'; | ||
|
||
export const useEarningQuest = (initialEarning: StudioQuestEarning) => { | ||
const [earning, setEarning] = useState(initialEarning); | ||
const [isValid, setIsValid] = useState<boolean>(true); | ||
const entityRef = useRef<DbSymbol | undefined>(); | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
const checkIsValid = () => { | ||
switch (earning.earningMethodName) { | ||
case 'earning_money': | ||
return setIsValid(!!inputRef.current && inputRef.current.validity.valid); | ||
case 'earning_item': | ||
return setIsValid(!!entityRef.current && !!inputRef.current && inputRef.current.validity.valid); | ||
case 'earning_pokemon': | ||
case 'earning_egg': | ||
return setIsValid(!!entityRef.current); | ||
default: | ||
assertUnreachable(earning.earningMethodName); | ||
} | ||
return setIsValid(true); | ||
}; | ||
|
||
const updateEarning = (earning: StudioQuestEarning) => { | ||
setEarning(earning); | ||
setIsValid(true); | ||
}; | ||
|
||
return { | ||
earning, | ||
refs: { | ||
entityRef, | ||
inputRef, | ||
}, | ||
updateEarning, | ||
checkIsValid, | ||
isValid, | ||
}; | ||
}; |
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