Skip to content

Commit

Permalink
Simplified query/sort in projects list
Browse files Browse the repository at this point in the history
Added role to projects
Added will-change to prevent flickering
  • Loading branch information
Marvin Heilemann committed Jan 16, 2020
1 parent e0af04f commit 6c2b71f
Show file tree
Hide file tree
Showing 10 changed files with 422 additions and 142 deletions.
5 changes: 5 additions & 0 deletions content/projects/__demo__/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ ended: null

status: wip
website: https://marvin.digital/
role:
- design
- development
- ux
- ui
team:
- name: Marvin Heilemann
link: https://github.com/muuvmuuv/portfolio
Expand Down
2 changes: 1 addition & 1 deletion content/projects/additive/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ subtitle: Giving ADDITIVE a new face and modern interface
image: additive-preview.jpg
thumb: additive-preview.jpg

started: null
started: 2018-07-11
ended: 2019-01-10

status: finished
Expand Down
6 changes: 6 additions & 0 deletions gatsby/node/onCreateNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module.exports = async ({ node, getNode, actions }) => {
if (node.internal.type === 'MarkdownRemark') {
const nodeFrontmatterDefault = {
published: true,
status: 'wip',
website: '',
role: [],
team: [],
}

node.frontmatter = Object.assign(
Expand All @@ -15,6 +19,8 @@ module.exports = async ({ node, getNode, actions }) => {
node.frontmatter
)

console.log(node.frontmatter)

const fileNode = getNode(node.parent)
const source = fileNode.sourceInstanceName

Expand Down
409 changes: 347 additions & 62 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
},
"dependencies": {
"@ibm/plex": "^4.0.2",
"@mdx-js/mdx": "^1.5.3",
"@mdx-js/react": "^1.5.3",
"@mdx-js/mdx": "^1.5.4",
"@mdx-js/react": "^1.5.4",
"dayjs": "^1.8.19",
"gatsby": "^2.18.22",
"gatsby-image": "^2.2.38",
Expand Down
10 changes: 10 additions & 0 deletions src/components/HeroProjects.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const HeroProjects = ({ item }) => (
target="_blank"
rel="noopener noreferrer"
className="link"
title={`Link to website: ${item.website}`}
>
{item.website}
</a>
Expand All @@ -47,6 +48,15 @@ const HeroProjects = ({ item }) => (
<span className="pre">Team:</span>{' '}
<Members list={item.team}></Members>
</li>
<li>
<span className="pre">Role:</span>{' '}
{item.role.map((r, i) => (
<span>
{r}
{i < item.role.length - 1 && ', '}
</span>
))}
</li>
</ul>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/member.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Member = ({ item }) => {
return item.link ? (
<a
href={item.link}
title={item.name}
title={`Link to ${item.name} website: ${item.link}`}
target="_blank"
rel="noopener noreferrer"
className="link"
Expand Down
124 changes: 48 additions & 76 deletions src/pages/projects.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import { isDev } from '../environment'
import SEO from '../components/SEO'
import Portfolio from '../components/Portfolio'
import { History } from '../store'
import dayjs from 'dayjs'

const Page = ({
pageContext: { breadcrumb },
data: { withDates, withoutStartDate, withoutEndDate },
}) => {
const Page = ({ pageContext: { breadcrumb }, data: { projects } }) => {
const pageName = 'Projects'
const historyDispatch = useContext(History.Dispatch)

Expand All @@ -22,17 +20,26 @@ const Page = ({
})
})

// weird sort function, but works
const idList = new Set(withoutStartDate.edges.map((x) => x.node.id))
const items = [
...withDates.edges,
...withoutStartDate.edges,
...withoutEndDate.edges.filter((d) => !idList.has(d.node.id)),
].sort((starting, ending) => {
return (
new Date(ending.node.frontmatter.ended) -
new Date(starting.node.frontmatter.ended)
)
const items = projects.edges.sort((nodeA, nodeB) => {
const AF = nodeA.node.frontmatter
const BF = nodeB.node.frontmatter

const future = dayjs().add(10, 'y')
const present = dayjs().add(-10, 'y')
const AEnded = AF.ended ? dayjs(AF.ended) : future
const BEnded = BF.ended ? dayjs(BF.ended) : future
const diffEnded = BEnded.diff(AEnded)
const AStarted = AF.started ? dayjs(AF.started) : present
const BStarted = BF.started ? dayjs(BF.started) : present
const diffStarted = AStarted.diff(BStarted)

if (!BF.started && !BF.ended) {
return -1
} else if (!AF.started && !AF.ended) {
return 1
}

return diffEnded - diffStarted
})

if (isDev) {
Expand Down Expand Up @@ -65,70 +72,35 @@ const Page = ({

// NOTE: this query could be simplified (https://github.com/gatsbyjs/gatsby/issues/17953)
export const pageQuery = graphql`
fragment ProjectsNodes on MarkdownRemark {
frontmatter {
title
subtitle
image {
childImageSharp {
fluid(maxWidth: 1600) {
...GatsbyImageSharpFluid
}
}
}
thumb {
childImageSharp {
fluid(maxWidth: 300) {
...GatsbyImageSharpFluid
}
}
}
}
fields {
slug
}
}
query DevelopmentQuery {
withDates: allMarkdownRemark(
filter: {
fields: { source: { eq: "projects" } }
frontmatter: { started: { ne: null }, ended: { ne: null } }
}
sort: {
fields: [frontmatter___ended, frontmatter___started]
order: DESC
}
query ProjectsQuery {
projects: allMarkdownRemark(
filter: { fields: { source: { eq: "projects" } } }
) {
edges {
node {
...ProjectsNodes
}
}
}
withoutStartDate: allMarkdownRemark(
filter: {
fields: { source: { eq: "projects" } }
frontmatter: { started: { eq: null } }
}
sort: { fields: frontmatter___ended, order: DESC }
) {
edges {
node {
...ProjectsNodes
}
}
}
withoutEndDate: allMarkdownRemark(
filter: {
fields: { source: { eq: "projects" } }
frontmatter: { ended: { eq: null } }
}
sort: { fields: frontmatter___started, order: DESC }
) {
edges {
node {
...ProjectsNodes
frontmatter {
title
subtitle
image {
childImageSharp {
fluid(maxWidth: 1600) {
...GatsbyImageSharpFluid
}
}
}
thumb {
childImageSharp {
fluid(maxWidth: 300) {
...GatsbyImageSharpFluid
}
}
}
started
ended
}
fields {
slug
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/styles/layouts/_header.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#header {
will-change: padding position background;
position: relative;
top: 0;
width: 100%;
Expand Down
1 change: 1 addition & 0 deletions src/templates/ProjectsSingle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const pageQuery = graphql`
name
link
}
role
website
keywords
categories
Expand Down

0 comments on commit 6c2b71f

Please sign in to comment.