react-achievements 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/dist/context/AchievementContext.d.ts +2 -2
- package/dist/index.cjs.js +3 -0
- package/dist/index.esm.js +3 -0
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
- package/src/context/AchievementContext.tsx +5 -3
- package/src/types.ts +3 -1
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# Welcome to React-Achievements!
|
|
2
2
|
|
|
3
|
+
## THIS IS STILL A WORK IN PROGRESS
|
|
3
4
|
A flexible and customizable achievement system for React applications.
|
|
4
5
|
|
|
5
6
|
## Installation
|
|
@@ -61,12 +62,12 @@ const achievementConfig = {
|
|
|
61
62
|
}
|
|
62
63
|
},
|
|
63
64
|
{
|
|
64
|
-
check: (value) =>
|
|
65
|
+
check: (value) => values.reduce((sum, val) => sum + (typeof val === 'number' ? val : 0), 0) >= 100,
|
|
65
66
|
data: {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
id: 'thousand_dollars',
|
|
68
|
+
title: 'Big Spender',
|
|
69
|
+
description: 'Spent a total of $1000',
|
|
70
|
+
icon: '/path/to/icon.png'
|
|
70
71
|
}
|
|
71
72
|
},
|
|
72
73
|
],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { Metrics, AchievementConfig } from '../types';
|
|
2
|
+
import { Metrics, AchievementConfig, MetricValue } from '../types';
|
|
3
3
|
interface AchievementContextProps {
|
|
4
4
|
metrics: Metrics;
|
|
5
5
|
setMetrics: (metrics: Metrics | ((prevMetrics: Metrics) => Metrics)) => void;
|
|
@@ -10,7 +10,7 @@ interface AchievementContextProps {
|
|
|
10
10
|
interface AchievementProviderProps {
|
|
11
11
|
children: ReactNode;
|
|
12
12
|
config: AchievementConfig;
|
|
13
|
-
initialState?: Record<string,
|
|
13
|
+
initialState?: Record<string, MetricValue>;
|
|
14
14
|
storageKey?: string;
|
|
15
15
|
badgesButtonPosition?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
16
16
|
}
|
package/dist/index.cjs.js
CHANGED
package/dist/index.esm.js
CHANGED
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { createContext, useContext, useState, useEffect, useCallback, ReactNode } from 'react';
|
|
2
|
-
import { Metrics, AchievementConfig, AchievementData } from '../types';
|
|
2
|
+
import { Metrics, AchievementConfig, AchievementData, MetricValue } from '../types';
|
|
3
3
|
import AchievementModal from '../components/AchievementModal';
|
|
4
4
|
import BadgesModal from '../components/BadgesModal';
|
|
5
5
|
import BadgesButton from '../components/BadgesButton';
|
|
@@ -16,7 +16,7 @@ interface AchievementContextProps {
|
|
|
16
16
|
interface AchievementProviderProps {
|
|
17
17
|
children: ReactNode;
|
|
18
18
|
config: AchievementConfig;
|
|
19
|
-
initialState?: Record<string,
|
|
19
|
+
initialState?: Record<string, MetricValue>;
|
|
20
20
|
storageKey?: string;
|
|
21
21
|
badgesButtonPosition?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
22
22
|
}
|
|
@@ -30,10 +30,12 @@ export const AchievementProvider: React.FC<AchievementProviderProps> = ({
|
|
|
30
30
|
storageKey = 'react-achievements',
|
|
31
31
|
badgesButtonPosition = 'top-right'
|
|
32
32
|
}) => {
|
|
33
|
-
const extractMetrics = (state: Record<string,
|
|
33
|
+
const extractMetrics = (state: Record<string, MetricValue>): Metrics => {
|
|
34
34
|
return Object.keys(config).reduce((acc, key) => {
|
|
35
35
|
if (key in state) {
|
|
36
36
|
acc[key] = state[key];
|
|
37
|
+
} else {
|
|
38
|
+
acc[key] = [];
|
|
37
39
|
}
|
|
38
40
|
return acc;
|
|
39
41
|
}, {} as Metrics);
|