@@ -16,16 +16,16 @@ const colorss = ["#B794F4", "#c5fb9d", "#f5a9b8", "#faf089", "#90D2DA", "#FEB2B2
1616
1717const Home = ( ) => {
1818 const { user } = useContext ( AuthContext ) ;
19- const { transactions} = useContext ( DataContext ) ;
19+ const { transactions } = useContext ( DataContext ) ;
2020 const [ groups , setGroups ] = useState ( [ ] ) ;
21- const [ amount , setAmount ] = useState ( { total :0 , iOwe :0 , peopleOwe :0 } )
21+ const [ amount , setAmount ] = useState ( { total : 0 , iOwe : 0 , peopleOwe : 0 } )
2222 const [ loading , setLoading ] = useState ( true ) ;
2323 const [ show , setShow ] = useState ( false ) ;
2424 const handleClose = ( ) => setShow ( false ) ;
2525 const handleShow = ( ) => setShow ( true ) ;
2626
2727 useEffect ( ( ) => {
28- let temp = [ ] ;
28+ const temp = [ ] ;
2929 db . collection ( "groups" )
3030 . where ( "members" , "array-contains" , user . uid )
3131 . get ( )
@@ -45,25 +45,25 @@ const Home = () => {
4545
4646 } , [ user ] ) ;
4747
48- useEffect ( ( ) => {
49- let total = 0 , negative = 0 , positive = 0 ;
50- transactions . forEach ( ( transaction ) => {
51- const amt = transaction . data . amount / transaction . data . involved . length
52- if ( transaction . data . paidBy === user . uid ) {
53- positive += amt
54- total += amt
55- } else {
56- negative -= amt
57- total += amt
48+ useEffect ( ( ) => {
49+ let total = 0 , negative = 0 , positive = 0 ;
50+ transactions . forEach ( ( transaction ) => {
51+ const amt = transaction . data . amount / transaction . data . involved . length
52+ if ( transaction . data . paidBy === user . uid ) {
53+ positive += amt
54+ total += amt
55+ } else {
56+ negative -= amt
57+ total += amt
58+ }
59+ } )
60+ const updatedAmount = {
61+ total : total ,
62+ iOwe : negative ,
63+ peopleOwe : positive ,
5864 }
59- } )
60- const updatedAmount = {
61- total :total ,
62- iOwe :negative ,
63- peopleOwe :positive ,
64- }
65- setAmount ( updatedAmount )
66- } , [ transactions , user ] )
65+ setAmount ( updatedAmount )
66+ } , [ transactions , user ] )
6767
6868 // const [spent, setSpent] = useState(0);
6969 // const [remain, setRemain] = useState(0);
0 commit comments