-
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.
Merge pull request #622 from CodeForAfrica/feature/projects-showcase
Featured Projects block
- Loading branch information
Showing
10 changed files
with
74 additions
and
23 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,15 @@ | ||
import { sortTags } from "@/codeforafrica/lib/data/utils/tags"; | ||
|
||
async function featuredWork(block) { | ||
const { projects } = block; | ||
const projectTags = projects.map(({ tag }) => tag).filter(Boolean); | ||
const tags = sortTags(projectTags); | ||
|
||
return { | ||
...block, | ||
tags, | ||
slug: block.blockType, | ||
}; | ||
} | ||
|
||
export default featuredWork; |
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,13 @@ | ||
export function sortTags(tags) { | ||
// Since we know 2 different tags can't have the same slug, we can just use | ||
// an object instead of `Set` and `find` | ||
const tagsBySlug = tags.reduce((acc, curr) => { | ||
acc[curr.slug] = curr; | ||
return acc; | ||
}, {}); | ||
return Object.keys(tagsBySlug) | ||
.sort() | ||
.map((slug) => tagsBySlug[slug]); | ||
} | ||
|
||
export default null; |
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,28 @@ | ||
import tags from "../fields/tags"; | ||
|
||
const FeaturedWork = { | ||
slug: "featured-work", | ||
imageURL: "/images/cms/blocks/our-work-showcase.png", | ||
imageAltText: "Featured Work", | ||
fields: [ | ||
tags({ | ||
name: "defaultTag", | ||
label: { | ||
en: "Default Tag", | ||
}, | ||
hasMany: false, | ||
}), | ||
{ | ||
name: "projects", | ||
type: "relationship", | ||
relationTo: "projects", | ||
hasMany: true, | ||
required: true, | ||
admin: { | ||
isSortable: true, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
export default FeaturedWork; |
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