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 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) => value.length >= 10,
65
+ check: (value) => values.reduce((sum, val) => sum + (typeof val === 'number' ? val : 0), 0) >= 100,
65
66
  data: {
66
- id: 'ten_transactions',
67
- title: 'Ten Transactions',
68
- description: 'Completed ten transactions',
69
- icon: '/path/to/icon.png'
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, any>;
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
@@ -191,6 +191,9 @@ const AchievementProvider = ({ children, config, initialState = {}, storageKey =
191
191
  if (key in state) {
192
192
  acc[key] = state[key];
193
193
  }
194
+ else {
195
+ acc[key] = [];
196
+ }
194
197
  return acc;
195
198
  }, {});
196
199
  };
package/dist/index.esm.js CHANGED
@@ -189,6 +189,9 @@ const AchievementProvider = ({ children, config, initialState = {}, storageKey =
189
189
  if (key in state) {
190
190
  acc[key] = state[key];
191
191
  }
192
+ else {
193
+ acc[key] = [];
194
+ }
192
195
  return acc;
193
196
  }, {});
194
197
  };
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export type MetricValue = number | boolean | string | any;
1
+ export type MetricValueItem = number | boolean | string | any;
2
+ export type MetricValue = MetricValueItem[];
2
3
  export interface Metrics {
3
4
  [key: string]: MetricValue;
4
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-achievements",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "This package allows users to transpose a React achievements engine over their React apps",
5
5
  "keywords": [
6
6
  "react",
@@ -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, any>;
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, any>): Metrics => {
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);
package/src/types.ts CHANGED
@@ -1,4 +1,6 @@
1
- export type MetricValue = number | boolean | string | any;
1
+ export type MetricValueItem = number | boolean | string | any;
2
+
3
+ export type MetricValue = MetricValueItem[];
2
4
 
3
5
  export interface Metrics {
4
6
  [key: string]: MetricValue;