-
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.
feat(tracks): Added ability for users to view completed campaign & ch…
…aracter tracks and clocks
- Loading branch information
1 parent
e04b748
commit 3e70cc8
Showing
20 changed files
with
731 additions
and
562 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
198 changes: 79 additions & 119 deletions
198
src/components/features/ProgressTrack/ProgressTrackList.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,146 +1,106 @@ | ||
import { Button, Stack } from "@mui/material"; | ||
import { | ||
ProgressTrack as IProgressTrack, | ||
TRACK_SECTION_PROGRESS_TRACKS, | ||
} from "types/Track.type"; | ||
import { Button, Checkbox, FormControlLabel } from "@mui/material"; | ||
import { TRACK_SECTION_PROGRESS_TRACKS } from "types/Track.type"; | ||
import { EditOrCreateTrackDialog } from "./EditOrCreateTrackDialog"; | ||
import { ProgressTrack } from "./ProgressTrack"; | ||
import { SectionHeading } from "components/shared/SectionHeading"; | ||
import { EmptyState } from "components/shared/EmptyState"; | ||
import { useState } from "react"; | ||
import { useStore } from "stores/store"; | ||
import { ProgressTracks } from "./ProgressTracks"; | ||
|
||
export interface ProgressTrackListProps { | ||
trackType: TRACK_SECTION_PROGRESS_TRACKS; | ||
tracks?: { [trackId: string]: IProgressTrack }; | ||
typeLabel: string; | ||
handleAdd?: (newTrack: IProgressTrack) => Promise<boolean | void>; | ||
handleUpdateValue: ( | ||
trackId: string, | ||
value: number | ||
) => Promise<boolean | void>; | ||
handleDeleteTrack?: (trackId: string) => Promise<boolean | void>; | ||
handleUpdateTrack?: ( | ||
trackId: string, | ||
track: IProgressTrack | ||
) => Promise<boolean | void>; | ||
headingBreakContainer?: boolean; | ||
readOnly?: boolean; | ||
isCampaign?: boolean; | ||
} | ||
|
||
export function ProgressTrackList(props: ProgressTrackListProps) { | ||
const { | ||
tracks = {}, | ||
trackType, | ||
typeLabel, | ||
handleAdd, | ||
handleUpdateValue, | ||
handleDeleteTrack, | ||
handleUpdateTrack, | ||
headingBreakContainer, | ||
} = props; | ||
const { trackType, typeLabel, headingBreakContainer, readOnly, isCampaign } = | ||
props; | ||
|
||
const orderedTrackIds = tracks | ||
? Object.keys(tracks).sort((trackId1, trackId2) => { | ||
const track1 = tracks[trackId1]; | ||
const track2 = tracks[trackId2]; | ||
|
||
return track2.createdDate.getTime() - track1.createdDate.getTime(); | ||
}) | ||
: []; | ||
|
||
const [addTrackDialogOpen, setAddTrackDialogOpen] = useState<boolean>(false); | ||
const [currentlyEditingTrackId, setCurrentlyEditingTrackId] = | ||
useState<string>(); | ||
const setLoadCompletedTracks = useStore((store) => | ||
isCampaign | ||
? store.campaigns.currentCampaign.tracks.setLoadCompletedTracks | ||
: store.characters.currentCharacter.tracks.setLoadCompletedTracks | ||
); | ||
const [showCompletedTracks, setShowCompletedTracks] = useState(false); | ||
const toggleShowCompletedTracks = (value: boolean) => { | ||
if (value) { | ||
setLoadCompletedTracks(); | ||
} | ||
setShowCompletedTracks(value); | ||
}; | ||
|
||
const currentlyEditingTrack = | ||
currentlyEditingTrackId && tracks | ||
? tracks[currentlyEditingTrackId] | ||
: undefined; | ||
const addCampaignProgressTrack = useStore( | ||
(store) => store.campaigns.currentCampaign.tracks.addTrack | ||
); | ||
const addCharacterProgressTrack = useStore( | ||
(store) => store.characters.currentCharacter.tracks.addTrack | ||
); | ||
|
||
const [addTrackDialogOpen, setAddTrackDialogOpen] = useState(false); | ||
return ( | ||
<> | ||
<EditOrCreateTrackDialog | ||
open={addTrackDialogOpen} | ||
handleClose={() => setAddTrackDialogOpen(false)} | ||
trackType={trackType} | ||
trackTypeName={`${typeLabel}`} | ||
handleTrack={(track) => | ||
handleAdd ? handleAdd(track) : new Promise((res) => res(true)) | ||
} | ||
/> | ||
|
||
{handleUpdateTrack && | ||
currentlyEditingTrack && | ||
currentlyEditingTrackId && ( | ||
<EditOrCreateTrackDialog | ||
open={!!currentlyEditingTrack} | ||
handleClose={() => setCurrentlyEditingTrackId(undefined)} | ||
trackType={ | ||
currentlyEditingTrack.type as TRACK_SECTION_PROGRESS_TRACKS | ||
{!readOnly && ( | ||
<EditOrCreateTrackDialog | ||
open={addTrackDialogOpen} | ||
handleClose={() => setAddTrackDialogOpen(false)} | ||
trackType={trackType} | ||
trackTypeName={`${typeLabel}`} | ||
handleTrack={(track) => { | ||
if (isCampaign) { | ||
return addCampaignProgressTrack(track); | ||
} else { | ||
return addCharacterProgressTrack(track); | ||
} | ||
trackTypeName={`${typeLabel}`} | ||
initialTrack={currentlyEditingTrack} | ||
handleTrack={(track) => | ||
currentlyEditingTrack | ||
? handleUpdateTrack(currentlyEditingTrackId, track) | ||
: new Promise((res) => res(true)) | ||
} | ||
/> | ||
)} | ||
}} | ||
/> | ||
)} | ||
|
||
<SectionHeading | ||
label={`${typeLabel}s`} | ||
action={ | ||
handleAdd && ( | ||
<Button | ||
color={"inherit"} | ||
onClick={() => setAddTrackDialogOpen(true)} | ||
> | ||
Add {typeLabel} | ||
</Button> | ||
) | ||
<> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={showCompletedTracks} | ||
onChange={(evt, checked) => | ||
toggleShowCompletedTracks(checked) | ||
} | ||
/> | ||
} | ||
label={`Show Completed ${typeLabel}s`} | ||
/> | ||
{!readOnly && ( | ||
<Button | ||
color={"inherit"} | ||
onClick={() => setAddTrackDialogOpen(true)} | ||
> | ||
Add {typeLabel} | ||
</Button> | ||
)} | ||
</> | ||
} | ||
breakContainer={headingBreakContainer} | ||
/> | ||
<Stack | ||
mt={2} | ||
spacing={4} | ||
mb={4} | ||
sx={(theme) => ({ | ||
px: headingBreakContainer ? 0 : 2, | ||
[theme.breakpoints.up("md")]: { | ||
px: headingBreakContainer ? 0 : 3, | ||
}, | ||
})} | ||
> | ||
{Array.isArray(orderedTrackIds) && orderedTrackIds.length > 0 ? ( | ||
orderedTrackIds.map((trackId, index) => ( | ||
<ProgressTrack | ||
key={index} | ||
trackType={trackType} | ||
label={tracks[trackId].label} | ||
description={tracks[trackId].description} | ||
difficulty={tracks[trackId].difficulty} | ||
value={tracks[trackId].value} | ||
onValueChange={(value) => handleUpdateValue(trackId, value)} | ||
onDelete={ | ||
handleDeleteTrack | ||
? () => { | ||
handleDeleteTrack(trackId); | ||
} | ||
: undefined | ||
} | ||
max={40} | ||
onEdit={ | ||
handleUpdateTrack | ||
? () => setCurrentlyEditingTrackId(trackId) | ||
: undefined | ||
} | ||
/> | ||
)) | ||
) : ( | ||
<EmptyState message={`No ${typeLabel}s found`} /> | ||
)} | ||
</Stack> | ||
<ProgressTracks | ||
isCampaign={isCampaign} | ||
trackType={trackType} | ||
typeLabel={typeLabel} | ||
headingBreakContainer={headingBreakContainer} | ||
readOnly={readOnly} | ||
/> | ||
{showCompletedTracks && ( | ||
<ProgressTracks | ||
isCampaign={isCampaign} | ||
isCompleted | ||
trackType={trackType} | ||
typeLabel={typeLabel} | ||
headingBreakContainer={headingBreakContainer} | ||
readOnly={readOnly} | ||
/> | ||
)} | ||
</> | ||
); | ||
} |
Oops, something went wrong.