-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Animation bugfix and added UserList Skeleton
- Loading branch information
1 parent
136331f
commit 45eda98
Showing
5 changed files
with
138 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from "react"; | ||
import { Box, Skeleton } from "@mui/material"; | ||
const UsersListSkeleton = () => { | ||
return ( | ||
<Box sx={{ width: "100%" }}> | ||
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "center" }}> | ||
<Box sx={{ display: "flex", alignItems: "center", width: "100%", padding: "8px", borderBottom: "1px solid #eee" }}> | ||
<Skeleton variant="circular" width={36} height={36} sx={{ mr: "16px" }} /> | ||
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "flex-start", flexGrow: 1 }}> | ||
<Skeleton variant="text" width={100} height={30} sx={{ mb: "4px" }} /> | ||
<Skeleton variant="text" width={200} height={20} /> | ||
</Box> | ||
<Skeleton variant="text" width={100} height={20} /> | ||
</Box> | ||
<Box sx={{ display: "flex", alignItems: "center", width: "100%", padding: "8px", borderBottom: "1px solid #eee" }}> | ||
<Skeleton variant="circular" width={36} height={36} sx={{ mr: "16px" }} /> | ||
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "flex-start", flexGrow: 1 }}> | ||
<Skeleton variant="text" width={100} height={30} sx={{ mb: "4px" }} /> | ||
<Skeleton variant="text" width={200} height={20} /> | ||
</Box> | ||
<Skeleton variant="text" width={100} height={20} /> | ||
</Box> | ||
<Box sx={{ display: "flex", alignItems: "center", width: "100%", padding: "8px", borderBottom: "1px solid #eee" }}> | ||
<Skeleton variant="circular" width={36} height={36} sx={{ mr: "16px" }} /> | ||
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "flex-start", flexGrow: 1 }}> | ||
<Skeleton variant="text" width={100} height={30} sx={{ mb: "4px" }} /> | ||
<Skeleton variant="text" width={200} height={20} /> | ||
</Box> | ||
<Skeleton variant="text" width={100} height={20} /> | ||
</Box> | ||
</Box> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default UsersListSkeleton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import * as React from "react"; | ||
import { Link } from "react-router-dom"; | ||
import { motion } from "framer-motion"; | ||
import { styled } from "@mui/material/styles"; | ||
import { Avatar, Box, ListItem, ListItemAvatar, ListItemText, Typography } from "@mui/material"; | ||
|
||
const UsersList = styled(Box)({ | ||
width: "100%", | ||
".user-link": { | ||
textDecoration: "none", | ||
}, | ||
".user-avatar": { | ||
color: "#fff", | ||
|
||
fontWeight: "bold", | ||
fontSize: "18px", | ||
width: "36px", | ||
height: "36px", | ||
marginRight: "16px", | ||
}, | ||
".list-item": { | ||
display: "flex", | ||
justifyContent: "space-between", | ||
alignItems: "center", | ||
width: "100%", | ||
padding: "8px", | ||
borderBottom: "1px solid #eee", | ||
cursor: "pointer", | ||
"&:hover": { | ||
backgroundColor: "#f9f9f9", | ||
}, | ||
}, | ||
}); | ||
|
||
const formatDate = (timestamp) => { | ||
const date = new Date(timestamp); | ||
const options = { | ||
year: "numeric", | ||
month: "short", | ||
day: "numeric", | ||
hour: "2-digit", | ||
minute: "2-digit", | ||
}; | ||
return new Intl.DateTimeFormat("en-US", options).format(date); | ||
}; | ||
|
||
const UsersListItems = ({ users }) => ( | ||
<UsersList component="div"> | ||
{users.map((user) => ( | ||
<motion.div key={user.uid} whileHover={{ scale: 1.05 }} whileTap={{ scale: 0.95 }}> | ||
<Link to={`/chat/${user.uid}`} className="user-link"> | ||
<ListItem disablePadding className="list-item"> | ||
<ListItemAvatar> | ||
<Avatar className="user-avatar">{user.username.charAt(0).toUpperCase()}</Avatar> | ||
</ListItemAvatar> | ||
<ListItemText | ||
primary={ | ||
<Typography variant="subtitle1" component="div"> | ||
{user.username} | ||
</Typography> | ||
} | ||
secondary={ | ||
<Typography variant="body2" component="div" sx={{ color: "text.secondary" }}> | ||
{user.lastMessage | ||
? user.lastMessage.text.length > 30 | ||
? `${user.lastMessage.text.substring(0, 30)}...` | ||
: user.lastMessage.text | ||
: "No messages yet"} | ||
</Typography> | ||
} | ||
/> | ||
<Typography variant="body2" sx={{ color: "text.secondary" }}> | ||
{user.lastMessage && formatDate(user.lastMessage.timestamp)} | ||
</Typography> | ||
</ListItem> | ||
</Link> | ||
</motion.div> | ||
))} | ||
</UsersList> | ||
); | ||
|
||
export default UsersListItems; |