-
Notifications
You must be signed in to change notification settings - Fork 2
Avatars Stage 1 #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zbarnz
wants to merge
9
commits into
master
Choose a base branch
from
zb/avatars
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Avatars Stage 1 #378
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
24191b6
added menu option and modal init
zbarnz f2b5aeb
modal final draft
zbarnz f7ceee0
create backend
zbarnz 1780998
removed image controller for now
zbarnz 4eab95c
removed image upload functionality from frontend
zbarnz 2f35d26
store functionality
zbarnz 8ecc748
added tests
zbarnz b6cc118
removed unused vars
zbarnz ed7a1b8
moved account menu to own page
zbarnz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,31 @@ | ||
| const Avatar = require("../models/avatar"); | ||
|
|
||
| module.exports = { | ||
| get: async (req, res) => { | ||
| const subject_id = req.credentials.sub; | ||
| const avatar = await Avatar.findOne({ owner_id: subject_id }); | ||
|
|
||
| res.status(200).send(avatar); | ||
| }, | ||
|
|
||
| create: async (req, res) => { | ||
| const subject_username = req.credentials.user.username; | ||
| const subject_id = req.credentials.sub; | ||
|
|
||
| const getColor = () => { | ||
| return ( | ||
| "hsl(" + | ||
| 360 * Math.random() + | ||
| "," + | ||
| '100%,50%)' | ||
| ); | ||
| }; | ||
|
|
||
| const avatar = await Avatar.create({ | ||
| color: getColor(), | ||
| user_id: subject_id | ||
| }); | ||
|
|
||
| res.status(200).send(avatar); | ||
| }, | ||
| }; |
This file contains hidden or 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,25 @@ | ||
| const mongoose = require("mongoose"); | ||
| const Schema = mongoose.Schema; | ||
|
|
||
| const colorValidator = (v) => (/^#([0-9a-f]{3}){1,2}$/i).test(v) | ||
|
|
||
| const avatarSchema = new mongoose.Schema( | ||
| { | ||
| color: { | ||
| type: String, | ||
| validator: [colorValidator, 'Invalid color'], | ||
| required: true, | ||
| }, | ||
| image: { | ||
| type: String | ||
| }, | ||
| user_id: { | ||
| type: Schema.Types.ObjectId, | ||
| ref: "User", | ||
| required: true, | ||
| index: true, | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| module.exports = mongoose.model("Avatar", avatarSchema); |
This file contains hidden or 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,10 @@ | ||
| const router = require("express").Router(); | ||
| const avatarController = require("../controllers/avatar"); | ||
| const { wrapController } = require("../util/error-wrapper"); | ||
|
|
||
| const wrapped = wrapController(avatarController); | ||
|
|
||
| router.post("/", wrapped.create); | ||
| router.get("/", wrapped.get); | ||
|
|
||
| module.exports = router; |
This file contains hidden or 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 hidden or 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,8 @@ | ||
| const ObjectID = require("mongoose").Types.ObjectId; | ||
|
|
||
| module.exports = () => { | ||
| return { | ||
| color: "hsl(144.61708086985226,77.63562668242602%,91.11721900382429%)", | ||
| user_id: new ObjectID() | ||
| }; | ||
| }; |
This file contains hidden or 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,57 @@ | ||
| const { assert } = require("chai"); | ||
| const dbUtils = require("../../utils/db"); | ||
| const db = require("../../../lib/db"); | ||
| const api = require("../../utils/api"); | ||
| const client = require("../../utils/client"); | ||
| const fakeAvatar = require("../../fakes/avatar"); | ||
| const Avatar = require("../../../lib/models/avatar"); | ||
|
|
||
| describe("lib/controllers/ui", () => { | ||
| let user_id; | ||
| const path = "/avatar"; | ||
|
|
||
| before(async () => { | ||
| await api.start(); | ||
| await db.connect(); | ||
| await dbUtils.clean(); | ||
|
|
||
| const res = await client.post("/user/register", { | ||
| username: "user", | ||
| password: "pass", | ||
| email: "email", | ||
| }); | ||
|
|
||
| user_id = res.data.user._id; | ||
|
|
||
| client.defaults.headers.common["Authorization"] = res.data.access_token; | ||
| }); | ||
|
|
||
| after(async () => { | ||
| await api.stop(); | ||
| await db.disconnect(); | ||
| }); | ||
|
|
||
| describe("#get", () => { | ||
| it("should get a users avatar", async () => { | ||
| const fake = fakeAvatar() | ||
| await Avatar.create({...fake, user_id: user_id}); | ||
|
|
||
| const res = await client.get(path); | ||
|
|
||
| assert.strictEqual(res.status, 200); | ||
| assert.strictEqual(res.data.user_id, user_id); | ||
| }); | ||
| }); | ||
|
|
||
| describe("#create", () => { | ||
| it("should create a new Avatar", async () => { | ||
| const res = await client.post(path, {}); | ||
|
|
||
| assert.strictEqual(res.status, 200); | ||
|
|
||
| const inserted = await Avatar.findOne({ user_id }); | ||
|
|
||
| assert.strictEqual(inserted.user_id.toString(), user_id); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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
52 changes: 52 additions & 0 deletions
52
www/components/Layout/ProfileButton/AccountModal/AccountModal.js
This file contains hidden or 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,52 @@ | ||
| import { Modal, Avatar } from "@mui/material"; | ||
| import { CameraAlt } from "@mui/icons-material"; | ||
| import styles from "./AccountModal.module.scss"; | ||
| import Link from "next/link"; | ||
|
|
||
| import { useSelector } from "react-redux"; | ||
|
|
||
| export default function AccountModal({ open, setOpen, user }) { | ||
| const avatar = useSelector((s) => s.avatar); | ||
|
|
||
| return ( | ||
| <Modal open={open} onClose={() => setOpen(false)}> | ||
| <div className={styles.modal_container}> | ||
| <section className={styles.main_options}> | ||
| <div className={styles.avatar_container}> | ||
| <Avatar | ||
| sx={{ bgcolor: avatar.color, width: 100, height: 100 }} | ||
| className={styles.avatar_current} | ||
| > | ||
| {avatar.initials} | ||
| {/* <input //Will need this for image upload in future | ||
| type="file" | ||
| className={styles.file_upload} | ||
| accept="image/*" | ||
| onChange={handleUpload} | ||
| /> */} | ||
| </Avatar> | ||
| <Avatar | ||
| className={styles.avatar_change} | ||
| sx={{ width: 100, height: 100 }} | ||
| > | ||
| <CameraAlt fontSize="large" color="primary" /> | ||
| </Avatar> | ||
| </div> | ||
| <div className={styles.info}> | ||
| <h1>{user.username}</h1> | ||
| <span>{user.email}</span> | ||
| </div> | ||
| <div className={styles.account_options}> | ||
| <h3>Account Options:</h3> | ||
| <Link href="#"> | ||
| <a>Change password</a> | ||
| </Link> | ||
| <Link href="#"> | ||
| <a>Delete account</a> | ||
| </Link> | ||
| </div> | ||
| </section> | ||
| </div> | ||
| </Modal> | ||
| ); | ||
| } | ||
91 changes: 91 additions & 0 deletions
91
www/components/Layout/ProfileButton/AccountModal/AccountModal.module.scss
This file contains hidden or 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,91 @@ | ||
| .modal_container { | ||
| background: #fff; | ||
| border-radius: 6px; | ||
| width: 800px; | ||
| max-width: 90%; | ||
| min-width: 600px; | ||
| position: absolute; | ||
| top: 300px; | ||
| left: 50%; | ||
| transform: translate(-50%, -50%); | ||
| padding: 2em 2em 2em 2em; | ||
|
|
||
| &:focus { | ||
| border: none; | ||
| } | ||
| } | ||
|
|
||
| .main_options { | ||
| display: flex; | ||
| margin-right: 0; | ||
|
|
||
| .avatar_current:hover { | ||
| opacity: 20%; | ||
| } | ||
|
|
||
| .avatar_change{ | ||
| position: absolute; | ||
| transform: translate(0, -100%); | ||
| z-index: -1; | ||
| } | ||
|
|
||
| .file_upload { | ||
| opacity: 0.0; | ||
|
|
||
| /* IE 8 */ | ||
| -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; | ||
|
|
||
| /* IE 5-7 */ | ||
| filter: alpha(opacity=0); | ||
|
|
||
| /* Netscape or and older firefox browsers */ | ||
| -moz-opacity: 0.0; | ||
|
|
||
| /* older Safari browsers */ | ||
| -khtml-opacity: 0.0; | ||
|
|
||
| position: absolute; | ||
| top: 0; | ||
| left: 0; | ||
| bottom: 0; | ||
| right: 0; | ||
| width: 100%; | ||
| height:100%; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .info{ | ||
| display: flex; | ||
| flex-direction: column; | ||
| margin: 0 0 0 1em; | ||
| justify-content: center; | ||
|
|
||
|
|
||
| h1 { | ||
| font-weight: 500; | ||
| margin: 0; | ||
| } | ||
|
|
||
| span { | ||
| font-size: small; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .account_options { | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: center; | ||
| gap: .3em; | ||
| min-width: 125px; | ||
| margin-left: 25%; | ||
|
|
||
|
|
||
| a { | ||
| font-size: x-small; | ||
| } | ||
|
|
||
| a:hover { | ||
| opacity: 60%; | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it could be a good idea to create a separate account page at
user/[_id](with largely the same format as this modal). That should make it easier for us to allow group members to look at other user's accounts.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this initially there was just so much white space I couldn't make it look good. If you think well have enough content to give it its own page we could certainly do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the groups and integrations related things on the page we should have enough content.