Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit de04452

Browse files
authored
feat(gui): new achievement "commentator" (#979)
* feat(gui): new badges * fix(gui): change counter for value annotations * feat(gui): new achievement "commentator" * style: apply automatic fixes of linters Co-authored-by: lars-reimann <[email protected]>
1 parent b7bda56 commit de04452

File tree

11 files changed

+36
-8
lines changed

11 files changed

+36
-8
lines changed
8.17 KB
Loading
12.2 KB
Loading
12.2 KB
Loading
13.2 KB
Loading
13.2 KB
Loading
13.5 KB
Loading

api-editor/gui/src/features/achievements/AchievementDisplay.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import {
66
selectNumberOfAnnotationsCreated,
77
selectNumberOfAnnotationsDeleted,
88
selectNumberOfAnnotationsMarkedAsCorrect,
9+
selectNumberOfCommentsTouched,
910
selectNumberOfElementsMarkedAsComplete,
1011
} from '../annotations/annotationSlice';
1112
import { pluralize } from '../../common/util/stringOperations';
1213
import {
1314
auditorAchievement,
1415
authorAchievement,
1516
cleanerAchievement,
17+
commentatorAchievement,
1618
completionistAchievement,
1719
editorAchievement,
1820
} from './achievements';
@@ -23,13 +25,15 @@ export const AchievementDisplay: React.FC = function () {
2325
const authorCount = useAppSelector(selectNumberOfAnnotationsCreated);
2426
const cleanerCount = useAppSelector(selectNumberOfAnnotationsDeleted);
2527
const completionistCount = useAppSelector(selectNumberOfElementsMarkedAsComplete);
28+
const commentatorCount = useAppSelector(selectNumberOfCommentsTouched);
2629
const editorCount = useAppSelector(selectNumberOfAnnotationsChanged);
2730

2831
if (
2932
auditorCount === 0 &&
3033
authorCount === 0 &&
3134
cleanerCount === 0 &&
3235
completionistCount === 0 &&
36+
commentatorCount === 0 &&
3337
editorCount === 0
3438
) {
3539
return null;
@@ -62,6 +66,11 @@ export const AchievementDisplay: React.FC = function () {
6266
achievement={completionistAchievement}
6367
description={`${pluralize(completionistCount, 'API element')} marked as complete`}
6468
/>
69+
<AchievementCard
70+
currentCount={commentatorCount}
71+
achievement={commentatorAchievement}
72+
description={`${pluralize(commentatorCount, 'comment')} touched`}
73+
/>
6574
<AchievementCard
6675
currentCount={editorCount}
6776
achievement={editorAchievement}

api-editor/gui/src/features/achievements/AnnotationToast.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import {
66
selectNumberOfAnnotationsCreated,
77
selectNumberOfAnnotationsDeleted,
88
selectNumberOfAnnotationsMarkedAsCorrect,
9+
selectNumberOfCommentsTouched,
910
selectNumberOfElementsMarkedAsComplete,
1011
} from '../annotations/annotationSlice';
1112
import {
1213
Achievement,
1314
auditorAchievement,
1415
authorAchievement,
1516
cleanerAchievement,
17+
commentatorAchievement,
1618
completionistAchievement,
1719
editorAchievement,
1820
} from './achievements';
@@ -23,6 +25,7 @@ export const useAnnotationToasts = () => {
2325
useAnnotationToast(authorAchievement, useAppSelector(selectNumberOfAnnotationsCreated));
2426
useAnnotationToast(cleanerAchievement, useAppSelector(selectNumberOfAnnotationsDeleted));
2527
useAnnotationToast(completionistAchievement, useAppSelector(selectNumberOfElementsMarkedAsComplete));
28+
useAnnotationToast(commentatorAchievement, useAppSelector(selectNumberOfCommentsTouched));
2629
useAnnotationToast(editorAchievement, useAppSelector(selectNumberOfAnnotationsChanged));
2730
};
2831

api-editor/gui/src/features/achievements/achievements.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ export const completionistAchievement = new Achievement('Completionist', [
6565
new AchievementLevel('Expert', 500, '4 Stars Completionist'),
6666
new AchievementLevel('Master', 1000, '5 Stars Completionist'),
6767
]);
68+
export const commentatorAchievement = new Achievement('Commentator', [
69+
new AchievementLevel('Rookie', 1, '0 Stars Commentator'),
70+
new AchievementLevel('Beginner', 10, '1 Star Commentator'),
71+
new AchievementLevel('Senior', 100, '2 Stars Commentator'),
72+
new AchievementLevel('Pro', 250, '3 Stars Commentator'),
73+
new AchievementLevel('Expert', 500, '4 Stars Commentator'),
74+
new AchievementLevel('Master', 1000, '5 Stars Commentator'),
75+
]);
6876
export const editorAchievement = new Achievement('Editor', [
6977
new AchievementLevel('Rookie', 1, '0 Stars Editor'),
7078
new AchievementLevel('Beginner', 10, '1 Star Editor'),

api-editor/gui/src/features/annotations/annotationSlice.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export interface AnnotationSlice {
5757
numberOfAnnotationsCreated: number;
5858
numberOfAnnotationsChanged: number;
5959
numberOfAnnotationsDeleted: number;
60+
numberOfCommentsTouched: number;
6061
}
6162

6263
// Initial state -------------------------------------------------------------------------------------------------------
@@ -88,6 +89,7 @@ export const initialAnnotationSlice: AnnotationSlice = {
8889
numberOfAnnotationsCreated: 0,
8990
numberOfAnnotationsChanged: 0,
9091
numberOfAnnotationsDeleted: 0,
92+
numberOfCommentsTouched: 0,
9193
};
9294

9395
// Thunks --------------------------------------------------------------------------------------------------------------
@@ -616,12 +618,6 @@ const annotationsSlice = createSlice({
616618
updateQueue(state);
617619
},
618620
upsertValueAnnotation(state, action: PayloadAction<ValueAnnotation>) {
619-
updateCreationOrChangedCount(
620-
state,
621-
state.annotations.valueAnnotations[action.payload.target],
622-
action.payload,
623-
);
624-
625621
if (action.payload.variant === 'required' || action.payload.variant === 'omitted') {
626622
// @ts-ignore
627623
delete action.payload.defaultValue;
@@ -634,6 +630,12 @@ const annotationsSlice = createSlice({
634630
action.payload.defaultValue = parseFloat(action.payload.defaultValue);
635631
}
636632

633+
updateCreationOrChangedCount(
634+
state,
635+
state.annotations.valueAnnotations[action.payload.target],
636+
action.payload,
637+
);
638+
637639
state.annotations.valueAnnotations[action.payload.target] = withAuthorAndReviewers(
638640
state.annotations.valueAnnotations[action.payload.target],
639641
action.payload,
@@ -644,8 +646,6 @@ const annotationsSlice = createSlice({
644646
},
645647
upsertValueAnnotations(state, action: PayloadAction<ValueAnnotation[]>) {
646648
action.payload.forEach((annotation) => {
647-
updateCreationOrChangedCount(state, state.annotations.valueAnnotations[annotation.target], annotation);
648-
649649
if (annotation.variant === 'required' || annotation.variant === 'omitted') {
650650
// @ts-ignore
651651
delete annotation.defaultValue;
@@ -658,6 +658,8 @@ const annotationsSlice = createSlice({
658658
annotation.defaultValue = parseFloat(annotation.defaultValue);
659659
}
660660

661+
updateCreationOrChangedCount(state, state.annotations.valueAnnotations[annotation.target], annotation);
662+
661663
state.annotations.valueAnnotations[annotation.target] = withAuthorAndReviewers(
662664
state.annotations.valueAnnotations[annotation.target],
663665
annotation,
@@ -735,6 +737,10 @@ const updateCreationOrChangedCount = function (
735737
} else {
736738
state.numberOfAnnotationsCreated++;
737739
}
740+
741+
if ((oldAnnotation?.comment ?? '') !== newAnnotation.comment) {
742+
state.numberOfCommentsTouched++;
743+
}
738744
};
739745

740746
const withAuthorAndReviewers = function <T extends Annotation>(
@@ -1025,3 +1031,5 @@ export const selectNumberOfAnnotationsChanged = (state: RootState): number =>
10251031
selectAnnotationSlice(state).numberOfAnnotationsChanged;
10261032
export const selectNumberOfAnnotationsDeleted = (state: RootState): number =>
10271033
selectAnnotationSlice(state).numberOfAnnotationsDeleted;
1034+
export const selectNumberOfCommentsTouched = (state: RootState): number =>
1035+
selectAnnotationSlice(state).numberOfCommentsTouched;

0 commit comments

Comments
 (0)