Merge pull request #557 from Irev-Dev/franknoirot/add-recent-projects

Added recent projects list to logged-in nav
This commit was merged in pull request #557.
This commit is contained in:
Frank Noirot
2021-10-15 09:24:28 -04:00
committed by GitHub
5 changed files with 78 additions and 21 deletions

View File

@@ -8,6 +8,7 @@ import { ImageFallback } from 'src/components/ImageUploader'
import useUser from 'src/helpers/hooks/useUser' import useUser from 'src/helpers/hooks/useUser'
import LoginModal from 'src/components/LoginModal' import LoginModal from 'src/components/LoginModal'
import Gravatar from 'src/components/Gravatar/Gravatar' import Gravatar from 'src/components/Gravatar/Gravatar'
import ProjectsOfUserCell from 'src/components/ProjectsOfUserCell'
const ProfileSlashLogin = () => { const ProfileSlashLogin = () => {
const { logOut, isAuthenticated, currentUser, client } = useAuth() const { logOut, isAuthenticated, currentUser, client } = useAuth()
@@ -58,25 +59,39 @@ const ProfileSlashLogin = () => {
</Popover.Button> </Popover.Button>
{currentUser && ( {currentUser && (
<Popover.Panel className="w-48 absolute z-10 right-0 bg-ch-gray-700 mt-4 px-3 py-2 rounded shadow-md overflow-hidden text-ch-gray-300"> <Popover.Panel className="w-48 absolute z-10 right-0 bg-ch-gray-700 mt-4 px-3 py-2 rounded shadow-md overflow-hidden text-ch-gray-300">
<Link to={routes.user({ userName: user?.userName })}>
<h3 className="text-lg hover:text-ch-pink-300">
Hello {user?.name}
</h3>
</Link>
<hr className="my-2" />
<Link <Link
className="my-2 mt-4 block hover:text-ch-pink-300" to={routes.user({
to={routes.user({ userName: user?.userName })} userName: user?.userName || currentUser.userName,
})}
>
<p className="my-2 text-ch-blue-400 font-fira-code leading-4 text-sm">
Hello {user?.name}
</p>
</Link>
<Link
className="my-2 block hover:text-ch-pink-300"
to={routes.user({
userName: user?.userName || currentUser.userName,
})}
> >
<div>View Your Profile</div> <div>View Your Profile</div>
</Link> </Link>
<a <a
href="#" href="#"
onClick={logOut} onClick={logOut}
className="text-ch-gray-400 hover:text-ch-pink-300" className="my-2 text-ch-gray-400 hover:text-ch-pink-300"
> >
Logout Logout
</a> </a>
<hr className="my-4" />
<p className="text-ch-blue-400 font-fira-code leading-4 text-sm">
Recent Projects
</p>
<ProjectsOfUserCell
projectLimit={3}
isMinimal
userName={user?.userName || currentUser.userName}
/>
</Popover.Panel> </Popover.Panel>
)} )}
</Popover> </Popover>

View File

@@ -11,6 +11,7 @@ const ProjectsList = ({
projects, projects,
shouldFilterProjectsWithoutImage = false, shouldFilterProjectsWithoutImage = false,
projectLimit = 80, projectLimit = 80,
isMinimal = false,
}) => { }) => {
// temporary filtering projects that don't have images until some kind of search is added and there are more things on the website // temporary filtering projects that don't have images until some kind of search is added and there are more things on the website
// it helps avoid the look of the website just being filled with dumby data. // it helps avoid the look of the website just being filled with dumby data.
@@ -23,7 +24,7 @@ const ProjectsList = ({
? projects ? projects
.filter(({ mainImage }) => mainImage) .filter(({ mainImage }) => mainImage)
.slice(0, projectLimit || 80) .slice(0, projectLimit || 80)
: [...projects] : [...projects].slice(0, projectLimit || 80)
) )
// sort should probably be done on the service, but the filtering is temp too // sort should probably be done on the service, but the filtering is temp too
.sort( .sort(
@@ -33,7 +34,7 @@ const ProjectsList = ({
[projects, shouldFilterProjectsWithoutImage] [projects, shouldFilterProjectsWithoutImage]
) )
return ( return !isMinimal ? (
<section className="max-w-7xl mx-auto"> <section className="max-w-7xl mx-auto">
<ul <ul
className="grid gap-x-8 gap-y-8 items-center relative" className="grid gap-x-8 gap-y-8 items-center relative"
@@ -52,11 +53,29 @@ const ProjectsList = ({
Reaction={Reaction} Reaction={Reaction}
cadPackage={cadPackage} cadPackage={cadPackage}
childForks={childForks} childForks={childForks}
key={`project-card-${index}`}
/> />
) )
)} )}
</ul> </ul>
</section> </section>
) : (
<section>
<ul>
{filteredProjects.map(({ title, user }, index) => (
<Link
to={routes.project({
userName: user?.userName,
projectTitle: title,
})}
className="my-2 capitalize block hover:text-ch-pink-300"
key={`project-item-${index}`}
>
<p>{title.replace(/[-_]/g, ' ')}</p>
</Link>
))}
</ul>
</section>
) )
} }

View File

@@ -27,26 +27,30 @@ export const QUERY = gql`
export const Loading = () => <div>Loading...</div> export const Loading = () => <div>Loading...</div>
export const Empty = () => { export const Empty = ({ isMinimal = false }) => {
return ( return !isMinimal ? (
<div className="rw-text-center"> <div className="rw-text-center">
{'No projects yet. '} {'No projects yet. '}
<Link to={routes.draftProject()} className="rw-link"> <Link to={routes.draftProject()} className="rw-link">
{'Create one?'} {'Create one?'}
</Link> </Link>
</div> </div>
) : (
<p className="text-ch-gray-400">None yet!</p>
) )
} }
export const Success = ({ export const Success = ({
projects, projects,
variables: { shouldFilterProjectsWithoutImage, projectLimit }, variables: { shouldFilterProjectsWithoutImage, projectLimit },
isMinimal = false,
}) => { }) => {
return ( return (
<Projects <Projects
projects={projects} projects={projects}
shouldFilterProjectsWithoutImage={shouldFilterProjectsWithoutImage} shouldFilterProjectsWithoutImage={shouldFilterProjectsWithoutImage}
projectLimit={projectLimit} projectLimit={projectLimit}
isMinimal={isMinimal}
/> />
) )
} }

View File

@@ -15,6 +15,7 @@ export const QUERY = gql`
createdAt createdAt
updatedAt updatedAt
user { user {
id
image image
userName userName
} }
@@ -27,18 +28,27 @@ export const QUERY = gql`
export const Loading = () => <div>Loading...</div> export const Loading = () => <div>Loading...</div>
export const Empty = () => { export const Empty = ({ isMinimal = false }) => {
return <div className="rw-text-center">No projects yet.</div> return (
<p className={`${isMinimal && 'my-2 text-ch-gray-400'}`}>
No projects yet.
</p>
)
} }
export const Success = ({ export const Success = ({
projects, projects,
variables: { shouldFilterProjectsWithoutImage }, variables: { userName },
shouldFilterProjectsWithoutImage = false,
projectLimit = 80,
isMinimal = false,
}) => { }) => {
return ( return (
<Projects <Projects
projects={projects} projects={projects}
shouldFilterProjectsWithoutImage={shouldFilterProjectsWithoutImage} shouldFilterProjectsWithoutImage={shouldFilterProjectsWithoutImage}
projectLimit={projectLimit}
isMinimal={isMinimal}
/> />
) )
} }

View File

@@ -16,6 +16,7 @@ import Svg from 'src/components/Svg'
import { ImageFallback } from 'src/components/ImageUploader' import { ImageFallback } from 'src/components/ImageUploader'
import useUser from 'src/helpers/hooks/useUser' import useUser from 'src/helpers/hooks/useUser'
import './MainLayout.css' import './MainLayout.css'
import ProjectsOfUserCell from 'src/components/ProjectsOfUserCell'
let previousSubmission = '' let previousSubmission = ''
@@ -130,13 +131,12 @@ const MainLayout = ({ children, shouldRemoveFooterInIde }) => {
{currentUser && ( {currentUser && (
<Popover.Panel className="w-48 absolute z-10 right-0 bg-ch-gray-700 mt-4 px-3 py-2 rounded shadow-md overflow-hidden text-ch-gray-300"> <Popover.Panel className="w-48 absolute z-10 right-0 bg-ch-gray-700 mt-4 px-3 py-2 rounded shadow-md overflow-hidden text-ch-gray-300">
<Link to={routes.user({ userName: user?.userName })}> <Link to={routes.user({ userName: user?.userName })}>
<h3 className="text-lg hover:text-ch-pink-300"> <p className="my-2 text-ch-blue-400 font-fira-code leading-4 text-sm">
Hello {user?.name} Hello {user?.name}
</h3> </p>
</Link> </Link>
<hr className="my-2" />
<Link <Link
className="my-2 mt-4 block hover:text-ch-pink-300" className="my-2 block hover:text-ch-pink-300"
to={routes.user({ userName: user?.userName })} to={routes.user({ userName: user?.userName })}
> >
<div>View Your Profile</div> <div>View Your Profile</div>
@@ -144,10 +144,19 @@ const MainLayout = ({ children, shouldRemoveFooterInIde }) => {
<a <a
href="#" href="#"
onClick={logOut} onClick={logOut}
className="text-ch-gray-400 hover:text-ch-pink-300" className="my-2 text-ch-gray-400 hover:text-ch-pink-300"
> >
Logout Logout
</a> </a>
<hr className="my-4" />
<p className="text-ch-blue-400 font-fira-code leading-4 text-sm">
Recent Projects
</p>
<ProjectsOfUserCell
projectLimit={3}
isMinimal
userName={user?.userName}
/>
</Popover.Panel> </Popover.Panel>
)} )}
</Popover> </Popover>