Skip to content

Commit

Permalink
Fix: rebase errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderleegs committed Apr 29, 2021
1 parent d58c728 commit 61ea027
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 47 deletions.
1 change: 0 additions & 1 deletion src/layouts/EditPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ const EditPage = ({ match, isResourcePage, isCollectionPage, history, type }) =>
content: dirContent,
} = dirData
const { order: parsedFolderContents } = parseDirectoryFile(dirContent)
const parsedFolderContents = parseDirectoryFile(dirContent)
// Filter out placeholder files
const filteredFolderContents = parsedFolderContents.filter(name => !name.includes('.keep'))
generatedLeftNavPages = filteredFolderContents.map((name) =>
Expand Down
42 changes: 2 additions & 40 deletions src/layouts/Folders.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ const Folders = ({ match, location }) => {
// parse contents of current folder directory
useEffect(() => {
if (folderContents && folderContents.sha) {
const parsedFolderContents = parseDirectoryFile(folderContents.content)
const { order: directoryFileOrder, output: directoryFileOutput } = parseDirectoryFile(folderContents.content)
setDirectoryFileSha(folderContents.sha)
setParsedFolderContents(parsedFolderContents)
setParsedFolderContents(directoryFileOrder)
setIsFolderLive(directoryFileOutput)

if (subfolderName) {
Expand Down Expand Up @@ -224,44 +224,6 @@ const Folders = ({ match, location }) => {
setMoveDropdownQuery({ ...initialMoveDropdownQueryState });
};

// REORDERING
// save file-reordering
const { mutate: rearrangeFolder } = useMutation(
payload => setDirectoryFile(siteName, folderName, payload),
{
onError: () => errorToast(`Your file reordering could not be saved. ${DEFAULT_RETRY_MSG}`),
onSuccess: () => successToast('Successfully updated page order'),
onSettled: () => setIsRearrangeActive((prevState) => !prevState),
}
)

// REORDERING utils
const toggleRearrange = () => {
if (isRearrangeActive) {
// drag and drop complete, save new order
let newFolderOrder
if (subfolderName) {
newFolderOrder = convertSubfolderArray(folderOrderArray, parsedFolderContents, subfolderName)
} else {
newFolderOrder = convertArrayToFolderOrder(folderOrderArray)
}
if (JSON.stringify(newFolderOrder) === JSON.stringify(parsedFolderContents)) {
// no change in file order
setIsRearrangeActive((prevState) => !prevState)
return
}
const updatedDirectoryFile = updateDirectoryFile(folderContents.content, newFolderOrder)

const payload = {
content: updatedDirectoryFile,
sha: directoryFileSha,
}
rearrangeFolder(payload) // setIsRearrangeActive(false) handled by mutate
} else {
setIsRearrangeActive((prevState) => !prevState)
}
}

return (
<>
{
Expand Down
6 changes: 0 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,6 @@ export const getObjectDiff = (obj1, obj2) => {
}

export const parseDirectoryFile = (folderContent) => {
const decodedContent = yaml.parse(folderContent)
const collectionKey = Object.keys(decodedContent.collections)[0]
return decodedContent.collections[collectionKey].order
}

export const updateDirectoryFile = (folderContent, folderOrder) => {
const decodedContent = yaml.parse(folderContent)
const collectionKey = Object.keys(decodedContent.collections)[0]
return decodedContent.collections[collectionKey]
Expand Down

0 comments on commit 61ea027

Please sign in to comment.