Skip to content

Commit

Permalink
feat: update EditNavBar to display collection/folder dropdown
Browse files Browse the repository at this point in the history
This commit updates the EditNavBar layout with a new folderDropdowns
state variable, which is passed to the TemplateNavBar as the
collectionsInfo prop. This gives the TemplateNavBar component the
necessary information to render the dropdown items for collections/folders
  • Loading branch information
SingpassAuth committed Mar 1, 2021
1 parent 7178cc9 commit 9b95f7d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { toast } from 'react-toastify';

import Toast from './components/Toast';

import { DEFAULT_ERROR_TOAST_MSG } from './utils';
import { DEFAULT_ERROR_TOAST_MSG, parseDirectoryFile, getNavFolderDropdownFromFolderOrder } from './utils';

import elementStyles from './styles/isomer-cms/Elements.module.scss';

Expand Down Expand Up @@ -44,11 +44,17 @@ const getEditNavBarData = async(siteName) => {
const resourceResp = await axios.get(`${BACKEND_URL}/sites/${siteName}/resources`)
resourceContent = resourceResp.data
const foldersResp = await axios.get(`${BACKEND_URL}/sites/${siteName}/folders/all`)
foldersContent = foldersResp.data

if (foldersContent && foldersContent.allFolderContent) {
if (foldersResp.data && foldersResp.data.allFolderContent) {
// parse directory files
foldersContent = foldersResp.data.allFolderContent.reduce((acc, currFolder) => {
const folderOrder = parseDirectoryFile(currFolder.content)
acc[currFolder.name.slice(1)] = getNavFolderDropdownFromFolderOrder(folderOrder)
return acc
}, {})

collectionContent = {
collections: foldersContent.allFolderContent.map((folder) => folder.name.slice(1)),
collections: foldersResp.data.allFolderContent.map((folder) => folder.name.slice(1)),
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/layouts/EditNavBar.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useState } from 'react';
import axios from 'axios';
import _ from 'lodash';
import PropTypes from 'prop-types';
import update from 'immutability-helper';
Expand Down Expand Up @@ -36,6 +35,7 @@ const EditNavBar = ({ match }) => {
const [links, setLinks] = useState([])
const [originalNav, setOriginalNav] = useState()
const [collections, setCollections] = useState([])
const [folderDropdowns, setFolderDropdowns] = useState({})
const [options, setOptions] = useState([])
const [displayLinks, setDisplayLinks] = useState([])
const [displaySublinks, setDisplaySublinks] = useState([])
Expand Down Expand Up @@ -142,6 +142,7 @@ const EditNavBar = ({ match }) => {
navContent,
navSha,
collectionContent,
foldersContent,
resourceContent,
} = navigationContents

Expand Down Expand Up @@ -179,6 +180,7 @@ const EditNavBar = ({ match }) => {
setDisplayLinks(initialDisplayLinks)
setDisplaySublinks(initialDisplaySublinks)
setCollections(initialCollections)
setFolderDropdowns(foldersContent)
setOptions(initialOptions)
setResources(initialResource.map(resource => deslugifyDirectory(resource.dirName)))
setOriginalNav(navContent)
Expand Down Expand Up @@ -610,7 +612,7 @@ const EditNavBar = ({ match }) => {
{/* TODO: update collectionInfo */}
<TemplateNavBar
links={links}
collectionInfo={null}
collectionInfo={folderDropdowns}
resources={resources}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/templates/NavBar.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

const NavDropdownSection = ({ children, link, linkIndex }) => (
const NavDropdownSection = ({ children, link }) => (
<div className="navbar-item has-dropdown is-hoverable">
<a className="navbar-link is-uppercase" href="/" onClick={(event) => event.preventDefault()}>
{ link.title }
Expand Down

0 comments on commit 9b95f7d

Please sign in to comment.