Skip to content

Commit

Permalink
fix(tracks): Tracks and clocks can now be deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbenton committed Jun 2, 2024
1 parent 386ef7a commit ce621da
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 21 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
- The default gold Crew Link theme is now called Eidolon
- The teal Crew Link theme is now called Myriad
- Clocks now use the "Likely" oracle by default
- Clocks now progress by two ticks when a match is rolled on the oracle die.
- Clocks now progress by two ticks when a match is rolled on the oracle die
- Added a new button to completed clocks and progress tracks that allows users to delete them permanently

### Bug Fixes

Expand Down
37 changes: 27 additions & 10 deletions src/components/features/ProgressTrack/ProgressTrack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface BaseProgressTrackProps {
max: number;
value: number;
onValueChange?: (value: number) => void;
onComplete?: () => void;
onDelete?: () => void;
onEdit?: () => void;
hideDifficultyLabel?: boolean;
Expand Down Expand Up @@ -111,6 +112,7 @@ export function ProgressTrack(props: ProgressTracksProps) {
max,
value,
onValueChange,
onComplete,
onDelete,
onEdit,
hideDifficultyLabel,
Expand All @@ -129,15 +131,9 @@ export function ProgressTrack(props: ProgressTracksProps) {

const [checks, setChecks] = useState<number[]>([]);

const handleDelete = () => {
if (onDelete) {
onDelete();
}
};

const confirm = useConfirm();

const handleDeleteClick = () => {
const handleCompleteClick = () => {
confirm({
title: "Complete Track",
description: "Are you sure you want to complete this track?",
Expand All @@ -148,7 +144,23 @@ export function ProgressTrack(props: ProgressTracksProps) {
},
})
.then(() => {
handleDelete();
onComplete && onComplete();
})
.catch(() => {});
};

const handleDeleteClick = () => {
confirm({
title: "Complete Track",
description: "Are you sure you want to delete this track?",
confirmationText: "Delete",
confirmationButtonProps: {
variant: "contained",
color: "primary",
},
})
.then(() => {
onDelete && onDelete();
})
.catch(() => {});
};
Expand Down Expand Up @@ -385,10 +397,10 @@ export function ProgressTrack(props: ProgressTracksProps) {
/>
)}
</Box>
{onDelete && (
{onComplete && (
<Button
color={"inherit"}
onClick={handleDeleteClick}
onClick={handleCompleteClick}
endIcon={<CompleteIcon />}
variant={"outlined"}
sx={{ mt: 2, mr: 1 }}
Expand All @@ -407,6 +419,11 @@ export function ProgressTrack(props: ProgressTracksProps) {
Roll {move?.name}
</Button>
)}
{onDelete && status === TrackStatus.Completed && (
<Button color={"error"} sx={{ mt: 1 }} onClick={handleDeleteClick}>
Delete Permanently
</Button>
)}
</Box>
);
}
20 changes: 17 additions & 3 deletions src/components/features/ProgressTrack/ProgressTracks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function ProgressTracks(props: ProgressTracksProps) {
? updateCampaignProgressTrack
: updateCharacterProgressTrack;

const deleteProgressTrack = (trackId: string) => {
const completeProgressTrack = (trackId: string) => {
updateProgressTrack(trackId, { status: TrackStatus.Completed }).catch(
() => {}
);
Expand All @@ -83,6 +83,17 @@ export function ProgressTracks(props: ProgressTracksProps) {
updateProgressTrack(trackId, { segmentsFilled }).catch(() => {});
};

const deleteCampaignProgressTrack = useStore(
(store) => store.campaigns.currentCampaign.tracks.deleteTrack
);
const deleteCharacterProgressTrack = useStore(
(store) => store.characters.currentCharacter.tracks.deleteTrack
);

const deleteProgressTrack = isCampaign
? deleteCampaignProgressTrack
: deleteCharacterProgressTrack;

return (
<>
<Stack
Expand Down Expand Up @@ -112,16 +123,19 @@ export function ProgressTracks(props: ProgressTracksProps) {
? undefined
: (value) => updateProgressTrackValue(trackId, value)
}
onDelete={
onComplete={
readOnly || isCompleted
? undefined
: () => deleteProgressTrack(trackId)
: () => completeProgressTrack(trackId)
}
onEdit={
readOnly || isCompleted
? undefined
: () => setCurrentlyEditingTrackId(trackId)
}
onDelete={
readOnly ? undefined : () => deleteProgressTrack(trackId)
}
hideRollButton={readOnly || isCompleted}
{...(trackType === TrackTypes.SceneChallenge
? {
Expand Down
34 changes: 32 additions & 2 deletions src/components/features/charactersAndCampaigns/Clocks/Clock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ export interface ClockProps {
onValueChange?: (value: number) => void;
onSelectedOracleChange?: (oracleKey: AskTheOracle) => void;
onComplete?: () => void;
handleDelete?: () => void;
}

export function Clock(props: ClockProps) {
const { clock, onEdit, onValueChange, onSelectedOracleChange, onComplete } =
props;
const {
clock,
onEdit,
onValueChange,
onSelectedOracleChange,
onComplete,
handleDelete,
} = props;

const { askTheOracle } = useSystemOracles();

Expand All @@ -53,6 +60,24 @@ export function Clock(props: ClockProps) {
}
};

const handleDeleteClick = () => {
if (handleDelete) {
confirm({
title: "Delete Clock",
description: "Are you sure you want to delete this clock?",
confirmationText: "Delete",
confirmationButtonProps: {
variant: "contained",
color: "primary",
},
})
.then(() => {
handleDelete();
})
.catch(() => {});
}
};

const handleProgressionRoll = () => {
if (onValueChange) {
const result = rollClockProgression(
Expand Down Expand Up @@ -182,6 +207,11 @@ export function Clock(props: ClockProps) {
Complete Clock
</Button>
)}
{handleDelete && clock.status === TrackStatus.Completed && (
<Button color={"error"} sx={{ mt: 1 }} onClick={handleDeleteClick}>
Delete Permanently
</Button>
)}
</Box>
);
}
12 changes: 12 additions & 0 deletions src/components/features/charactersAndCampaigns/Clocks/Clocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ export function Clocks(props: ClocksProps) {
? updateCampaignClock
: updateCharacterClock;

const deleteCharacterClock = useStore(
(store) => store.characters.currentCharacter.tracks.deleteTrack
);
const deleteCampaignClock = useStore(
(store) => store.campaigns.currentCampaign.tracks.deleteTrack
);

const deleteClock = isCampaignSection
? deleteCampaignClock
: deleteCharacterClock;

return (
<>
{sortedClockIds.length > 0 ? (
Expand Down Expand Up @@ -101,6 +112,7 @@ export function Clocks(props: ClocksProps) {
? undefined
: (value) => updateClock(clockId, { value }).catch(() => {})
}
handleDelete={() => deleteClock(clockId).catch(() => {})}
/>
))}
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function TracksTab() {
value,
})
}
onDelete={() =>
onComplete={() =>
updateCharacterProgressTrack(characterId, trackId, {
status: TrackStatus.Completed,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ export function TracksSection() {
type={TrackTypes.Journey}
typeLabel={isStarforged ? "Expedition" : "Journey"}
/>
<ProgressTrackSection
type={TrackTypes.SceneChallenge}
typeLabel={"Scene Challenge"}
/>
{isStarforged && (
<ProgressTrackSection
type={TrackTypes.SceneChallenge}
typeLabel={"Scene Challenge"}
/>
)}
<ClockSection />
</Stack>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { listenToProgressTracks } from "api-calls/tracks/listenToProgressTracks"
import { TrackStatus } from "types/Track.type";
import { addProgressTrack } from "api-calls/tracks/addProgressTrack";
import { updateProgressTrack } from "api-calls/tracks/updateProgressTrack";
import { removeProgressTrack } from "api-calls/tracks/removeProgressTrack";

export const createCampaignTracksSlice: CreateSliceType<CampaignTracksSlice> = (
set,
Expand Down Expand Up @@ -53,6 +54,10 @@ export const createCampaignTracksSlice: CreateSliceType<CampaignTracksSlice> = (
const campaignId = getState().campaigns.currentCampaign.currentCampaignId;
return updateProgressTrack({ campaignId, trackId, track });
},
deleteTrack: (trackId) => {
const campaignId = getState().campaigns.currentCampaign.currentCampaignId;
return removeProgressTrack({ campaignId, id: trackId });
},

updateCharacterTrack: (characterId, trackId, track) => {
return updateProgressTrack({ characterId, trackId, track });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface CampaignTracksSliceActions {

addTrack: (track: Track) => Promise<void>;
updateTrack: (trackId: string, track: Partial<Track>) => Promise<void>;
deleteTrack: (trackId: string) => Promise<void>;

updateCharacterTrack: (
characterId: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { listenToProgressTracks } from "api-calls/tracks/listenToProgressTracks"
import { TrackStatus } from "types/Track.type";
import { addProgressTrack } from "api-calls/tracks/addProgressTrack";
import { updateProgressTrack } from "api-calls/tracks/updateProgressTrack";
import { removeProgressTrack } from "api-calls/tracks/removeProgressTrack";

export const createCharacterTracksSlice: CreateSliceType<
CharacterTracksSlice
Expand Down Expand Up @@ -54,6 +55,11 @@ export const createCharacterTracksSlice: CreateSliceType<
getState().characters.currentCharacter.currentCharacterId;
return updateProgressTrack({ characterId, trackId, track });
},
deleteTrack: (trackId) => {
const characterId =
getState().characters.currentCharacter.currentCharacterId;
return removeProgressTrack({ characterId, id: trackId });
},

setLoadCompletedTracks: () => {
set((store) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface CharacterTracksSliceActions {

addTrack: (track: Track) => Promise<void>;
updateTrack: (trackId: string, track: Partial<Track>) => Promise<void>;
deleteTrack: (trackId: string) => Promise<void>;

setLoadCompletedTracks: () => void;
resetStore: () => void;
Expand Down

0 comments on commit ce621da

Please sign in to comment.