-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #443 from scottbenton/feat/oracle-match-reminder
Feat/oracle match reminder
- Loading branch information
Showing
19 changed files
with
462 additions
and
38 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
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
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
55 changes: 55 additions & 0 deletions
55
src/components/features/assets/AssetCard/AssetControlClock.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Datasworn } from "@datasworn/core"; | ||
import { Box, Typography } from "@mui/material"; | ||
import { useDebouncedState } from "hooks/useDebouncedState"; | ||
import { useStore } from "stores/store"; | ||
import { ClockCircle } from "components/features/charactersAndCampaigns/Clocks/ClockCircle"; | ||
|
||
export interface AssetControlClockProps { | ||
value?: number; | ||
field: Datasworn.ClockField; | ||
onChange?: (value: number) => void; | ||
} | ||
|
||
export function AssetControlClock(props: AssetControlClockProps) { | ||
const { value, field, onChange } = props; | ||
|
||
const [localValue, setLocalValue] = useDebouncedState<number>( | ||
(value) => onChange && onChange(value), | ||
value ?? field.value, | ||
500 | ||
); | ||
|
||
const announce = useStore((store) => store.appState.announce); | ||
|
||
const handleIncrement = () => { | ||
setLocalValue((prev) => { | ||
const newValue = prev + 1; | ||
if (typeof field.max === "number" && field.max < newValue) { | ||
announce( | ||
`Cannot increase ${field.label} beyond ${field.max}. Resetting field to 0` | ||
); | ||
return 0; | ||
} | ||
announce(`Increased ${field.label} by 1 for a total of ${newValue}`); | ||
return newValue; | ||
}); | ||
}; | ||
|
||
return ( | ||
<Box> | ||
<Typography | ||
variant={"subtitle1"} | ||
fontFamily={(theme) => theme.fontFamilyTitle} | ||
color={"textSecondary"} | ||
> | ||
{field.label} | ||
</Typography> | ||
|
||
<ClockCircle | ||
value={localValue} | ||
segments={field.max} | ||
onClick={handleIncrement} | ||
/> | ||
</Box> | ||
); | ||
} |
131 changes: 131 additions & 0 deletions
131
src/components/features/assets/AssetCard/AssetControlCounter.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 |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { Datasworn } from "@datasworn/core"; | ||
import { Box, ButtonBase, Typography } from "@mui/material"; | ||
import { useDebouncedState } from "hooks/useDebouncedState"; | ||
import { useStore } from "stores/store"; | ||
import AddIcon from "@mui/icons-material/Add"; | ||
import SubtractIcon from "@mui/icons-material/Remove"; | ||
|
||
export interface AssetControlCounterProps { | ||
value?: number; | ||
field: Datasworn.CounterField; | ||
onChange?: (value: number) => void; | ||
} | ||
|
||
export function AssetControlCounter(props: AssetControlCounterProps) { | ||
const { value, field, onChange } = props; | ||
|
||
const [localValue, setLocalValue] = useDebouncedState<number>( | ||
(value) => onChange && onChange(value), | ||
value ?? field.value, | ||
500 | ||
); | ||
|
||
const announce = useStore((store) => store.appState.announce); | ||
|
||
const handleDecrement = () => { | ||
setLocalValue((prev) => { | ||
const newValue = prev - 1; | ||
if (typeof field.min === "number" && field.min > newValue) { | ||
announce(`Cannot decrease ${field.label} beyond ${field.max}`); | ||
return prev; | ||
} | ||
announce(`Decreased ${field.label} by 1 for a total of ${newValue}`); | ||
return newValue; | ||
}); | ||
}; | ||
|
||
const handleIncrement = () => { | ||
setLocalValue((prev) => { | ||
const newValue = prev + 1; | ||
if (typeof field.max === "number" && field.max < newValue) { | ||
announce(`Cannot increase ${field.label} beyond ${field.max}`); | ||
return prev; | ||
} | ||
announce(`Increased ${field.label} by 1 for a total of ${newValue}`); | ||
return newValue; | ||
}); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Box | ||
display={"inline-flex"} | ||
alignItems={"stretch"} | ||
border={`1px solid`} | ||
borderColor={"divider"} | ||
borderRadius={1} | ||
overflow={"hidden"} | ||
> | ||
<Typography | ||
variant={"subtitle1"} | ||
fontFamily={(theme) => theme.fontFamilyTitle} | ||
sx={(theme) => ({ | ||
bgcolor: (theme) => | ||
theme.palette.mode === "light" | ||
? theme.palette.darkGrey.light | ||
: theme.palette.grey[400], | ||
color: | ||
theme.palette.mode === "light" | ||
? theme.palette.darkGrey.contrastText | ||
: theme.palette.grey[800], | ||
px: 0.5, | ||
})} | ||
> | ||
{field.label} | ||
</Typography> | ||
{onChange && ( | ||
<ButtonBase | ||
aria-label={`Decrement ${field.label}`} | ||
onClick={handleDecrement} | ||
sx={(theme) => ({ | ||
bgcolor: theme.palette.mode === "light" ? "grey.300" : "grey.600", | ||
color: theme.palette.mode === "light" ? "grey.700" : "grey.200", | ||
transition: theme.transitions.create(["background-color"], { | ||
duration: theme.transitions.duration.shortest, | ||
}), | ||
"&:hover": { | ||
bgcolor: | ||
theme.palette.mode === "light" ? "grey.400" : "grey.700", | ||
}, | ||
})} | ||
> | ||
<SubtractIcon /> | ||
</ButtonBase> | ||
)} | ||
|
||
<Typography | ||
component={"p"} | ||
color={"textSecondary"} | ||
sx={{ | ||
fontWeight: 600, | ||
alignSelf: "center", | ||
textAlign: "center", | ||
width: 64, | ||
}} | ||
> | ||
{localValue > 0 ? "+" : ""} | ||
{localValue} | ||
</Typography> | ||
{onChange && ( | ||
<ButtonBase | ||
aria-label={`Increment ${field.label}`} | ||
onClick={handleIncrement} | ||
sx={(theme) => ({ | ||
bgcolor: theme.palette.mode === "light" ? "grey.300" : "grey.600", | ||
color: theme.palette.mode === "light" ? "grey.700" : "grey.200", | ||
transition: theme.transitions.create(["background-color"], { | ||
duration: theme.transitions.duration.shortest, | ||
}), | ||
"&:hover": { | ||
bgcolor: | ||
theme.palette.mode === "light" ? "grey.400" : "grey.700", | ||
}, | ||
})} | ||
> | ||
<AddIcon /> | ||
</ButtonBase> | ||
)} | ||
</Box> | ||
</div> | ||
); | ||
} |
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
Oops, something went wrong.