Skip to content

Commit

Permalink
feat: grab the users from the database and display them in a vertical…
Browse files Browse the repository at this point in the history
… list

this closes #157
  • Loading branch information
marianzburlea committed Sep 9, 2019
1 parent 6cd9149 commit faca3fc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/component/manage-user/manage-user.component.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { db } from '../data/firebase';
import UserItem from '../user-item/user-item.component';
import { StyledUserList } from './manage-user.style';
import HeaderTitle from '../_dumb/header-title/header-title.component';

const ManageUser = () => {
return <div>Manage user panel</div>;
const [userList, setUserList] = useState([])
useEffect(() => {
(async () => {
const userSnap = await db.collection('user').get()
const userList = userSnap.docs.map(user => ({ id: user.id, ...user.data() }))
setUserList(userList)
})()
}, [])
return (
<div>
<HeaderTitle {...{
text: 'Manage user panel',
tag: 'h1',
fontSize: '22px',
}} />
<StyledUserList>
{userList.map(user => <UserItem key={user.id} user={user} />)}
</StyledUserList>
</div>
);
};

export default ManageUser;
7 changes: 7 additions & 0 deletions src/component/manage-user/manage-user.style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import styled from 'styled-components'

export const StyledUserList = styled.div`
display: grid;
grid-template-columns: auto 1fr 1fr;
grid-gap: 0.5rem;
`
1 change: 1 addition & 0 deletions src/component/user-item/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './user-item.component'
15 changes: 15 additions & 0 deletions src/component/user-item/user-item.component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import Avatar from '../avatar'

const UserItem = ({ user }) => {
const { displayName, photoUrl, email, id } = user
return (
<>
<Avatar user={user} />
<div>{email}</div>
<div id={id}><a href={`#${id}`} title={id}>#{id.slice(0, 6)}</a></div>
</>
)
}

export default UserItem

0 comments on commit faca3fc

Please sign in to comment.