Skip to content

Commit

Permalink
feat(scene challenges): Added scene challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbenton committed May 25, 2024
1 parent aefa331 commit 6f02cac
Show file tree
Hide file tree
Showing 24 changed files with 367 additions and 265 deletions.
2 changes: 1 addition & 1 deletion src/api-calls/tracks/_getRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function convertToDatabase(track: Track): TrackDocument {
return {
...rest,
createdTimestamp: Timestamp.fromDate(createdDate),
};
} as TrackDocument;
}

export function convertFromDatabase(track: TrackDocument): Track {
Expand Down
7 changes: 6 additions & 1 deletion src/api-calls/tracks/_track.type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Timestamp } from "firebase/firestore";
import { Clock, ProgressTrack } from "types/Track.type";
import { Clock, ProgressTrack, SceneChallenge } from "types/Track.type";

export interface ProgressTrackDocument
extends Omit<ProgressTrack, "createdDate"> {
Expand All @@ -9,4 +9,9 @@ export interface ClockDocument extends Omit<Clock, "createdDate"> {
createdTimestamp: Timestamp;
}

export interface SceneChallengeDocument
extends Omit<SceneChallenge, "createdDate"> {
createdTimestamp: Timestamp;
}

export type TrackDocument = ProgressTrackDocument | ClockDocument;
15 changes: 3 additions & 12 deletions src/api-calls/tracks/listenToProgressTracks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import {
getCampaignTracksCollection,
getCharacterTracksCollection,
} from "./_getRef";
import { Track, TrackTypes } from "types/Track.type";
import { Track, TrackSectionTracks } from "types/Track.type";

export function listenToProgressTracks(
campaignId: string | undefined,
characterId: string | undefined,
status: string,
addOrUpdateTracks: (tracks: { [trackId: string]: Track }) => void,
removeTrack: (
trackId: string,
trackType: TrackTypes.Fray | TrackTypes.Journey | TrackTypes.Vow
) => void,
removeTrack: (trackId: string, trackType: TrackSectionTracks) => void,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onError: (error: any) => void
): Unsubscribe | undefined {
Expand All @@ -36,13 +33,7 @@ export function listenToProgressTracks(

snapshot.docChanges().forEach((change) => {
if (change.type === "removed") {
removeTrack(
change.doc.id,
change.doc.data().type as
| TrackTypes.Fray
| TrackTypes.Journey
| TrackTypes.Vow
);
removeTrack(change.doc.id, change.doc.data().type);
} else {
addOrUpdateChanges[change.doc.id] = convertFromDatabase(
change.doc.data()
Expand Down
43 changes: 30 additions & 13 deletions src/components/features/ProgressTrack/EditOrCreateTrackDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ import {
Difficulty,
TrackStatus,
TrackSectionProgressTracks,
TrackTypes,
SceneChallenge,
} from "types/Track.type";

export interface EditOrCreateTrackDialogProps {
open: boolean;
handleClose: () => void;
initialTrack?: ProgressTrack;
trackType: TrackSectionProgressTracks;
initialTrack?: ProgressTrack | SceneChallenge;
trackType: TrackSectionProgressTracks | TrackTypes.SceneChallenge;
trackTypeName: string;
handleTrack: (track: ProgressTrack) => Promise<boolean | void>;
handleTrack: (
track: ProgressTrack | SceneChallenge
) => Promise<boolean | void>;
}

export function EditOrCreateTrackDialog(props: EditOrCreateTrackDialogProps) {
Expand Down Expand Up @@ -69,16 +73,29 @@ export function EditOrCreateTrackDialog(props: EditOrCreateTrackDialogProps) {
return;
}

const track: ProgressTrack = {
createdDate: new Date(),
status: TrackStatus.Active,
type: trackType,
...(initialTrack ?? {}),
label: title,
description,
difficulty: difficulty,
value: initialTrack && !resetProgress ? initialTrack.value : 0,
};
const track: ProgressTrack | SceneChallenge =
trackType === TrackTypes.SceneChallenge
? {
createdDate: new Date(),
status: TrackStatus.Active,
type: trackType,
...((initialTrack as SceneChallenge | undefined) ?? {}),
label: title,
description,
difficulty: difficulty,
value: initialTrack && !resetProgress ? initialTrack.value : 0,
segmentsFilled: 0,
}
: {
createdDate: new Date(),
status: TrackStatus.Active,
type: trackType,
...((initialTrack as ProgressTrack | undefined) ?? {}),
label: title,
description,
difficulty: difficulty,
value: initialTrack && !resetProgress ? initialTrack.value : 0,
};

setLoading(true);
handleTrack(track)
Expand Down
Loading

0 comments on commit 6f02cac

Please sign in to comment.