Skip to content

Commit

Permalink
feat(uuid): add uuid to Tracker and TrackerEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
Clm-Roig committed Mar 18, 2022
1 parent e14c079 commit bd33589
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
"@types/react": "^16.14.24",
"@types/react-dom": "^16.9.14",
"@types/react-redux": "^7.1.23",
"@types/uuid": "^8.3.4",
"date-fns": "^2.28.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.6",
"react-router-dom": "^6.2.2",
"react-scripts": "5.0.0",
"typescript": "~4.1.5"
"typescript": "~4.1.5",
"uuid": "^8.3.2"
},
"scripts": {
"start": "react-scripts start",
Expand Down
2 changes: 2 additions & 0 deletions src/components/TrackerCard/TrackerCard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { subDays } from 'date-fns';
import TrackerStatus from '../../models/TrackerStatus';
import formatDate from '../../utils/formatDate';
import TrackerCard from './TrackerCard';
import { v4 } from 'uuid';

const tracker1 = {
id: v4(),
beginDate: subDays(new Date(), 3).toString(),
defaultQuantity: 15,
duration: 13,
Expand Down
1 change: 1 addition & 0 deletions src/models/Tracker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import TrackerEntry from './TrackerEntry';
import TrackerStatus from './TrackerStatus';
export default interface Tracker {
id: string; // uuid v4
beginDate: string;
dateHidden?: string;
defaultQuantity?: number;
Expand Down
1 change: 1 addition & 0 deletions src/models/TrackerEntry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default interface TrackerEntry {
id: string; // uuid v4
date: string;
quantity: number;
}
4 changes: 4 additions & 0 deletions src/store/trackers/trackers.actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { subDays } from 'date-fns';
import Tracker from '../../models/Tracker';
import TrackerStatus from '../../models/TrackerStatus';
import { v4 as uuidv4 } from 'uuid';

class TrackersActions {
// A mock function to mimic making an async request for data
Expand All @@ -11,6 +12,7 @@ class TrackersActions {
resolve({
data: [
{
id: uuidv4(),
beginDate: new Date().toString(),
name: "Boire plus d'eau",
defaultQuantity: 1,
Expand All @@ -19,6 +21,7 @@ class TrackersActions {
entries: []
},
{
id: uuidv4(),
beginDate: new Date().toString(),
defaultQuantity: 1,
name: 'Faire du yoga',
Expand All @@ -27,6 +30,7 @@ class TrackersActions {
entries: []
},
{
id: uuidv4(),
beginDate: subDays(new Date(), 7).toString(),
defaultQuantity: 15,
duration: 45,
Expand Down
3 changes: 3 additions & 0 deletions src/store/trackers/trackers.selectors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { v4 } from 'uuid';
import SliceStatus from '../../models/SliceStatus';
import Tracker from '../../models/Tracker';
import TrackerStatus from '../../models/TrackerStatus';
Expand All @@ -18,6 +19,7 @@ describe('trackers selector', () => {
...state.trackers,
trackers: [
{
id: v4(),
beginDate: new Date().toString(),
entries: [],
name: 'Do',
Expand All @@ -26,6 +28,7 @@ describe('trackers selector', () => {
unit: 'push-ups'
},
{
id: v4(),
beginDate: new Date().toString(),
duration: 10,
entries: [],
Expand Down

0 comments on commit bd33589

Please sign in to comment.