Skip to content

Commit

Permalink
Merge pull request #72 from RobbinBaauw/dev
Browse files Browse the repository at this point in the history
Fixed duplicate search results
  • Loading branch information
RobbinBaauw authored Nov 8, 2018
2 parents 82a8c41 + 13c4134 commit e402413
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
70 changes: 37 additions & 33 deletions cshub-client/src/components/quill/Quill.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,16 @@
};
const finalizeCodeBlock = () => {
const newNode = document.createElement("pre");
newNode.innerHTML = `<code class="${prevElement.lang} hljsBlock">${prevElement.currString}</code>`;
if (prevElement.isCodeBlock) {
const newNode = document.createElement("pre");
newNode.innerHTML = `<code class="${prevElement.lang} hljsBlock">${prevElement.currString}</code>`;
prevElement.containerNode.after(newNode);
prevElement.containerNode.after(newNode);
prevElement = {
isCodeBlock: false
};
prevElement = {
isCodeBlock: false
};
}
};
const toBeDeletedNodes: HTMLElement[] = [];
Expand All @@ -262,39 +264,37 @@
if (domNode.classList.contains("ql-code-block-container")) {
toBeDeletedNodes.push(domNode);
prevElement.containerNode = domNode;
}
if (domNode.classList.contains("ql-code-block")) {
if (!prevElement.isCodeBlock) {
console.log(domNode.innerText)
const lang = domNode.attributes.getNamedItem("data-language") ? domNode.attributes.getNamedItem("data-language").value : "";
prevElement = {
...prevElement,
isCodeBlock: true,
lang,
currString: domNode.innerText
};
} else {
prevElement = {
...prevElement,
currString: prevElement.currString + "\n" + domNode.innerText
};
}
toBeDeletedNodes.push(domNode);
} else {
if (prevElement.isCodeBlock) {
finalizeCodeBlock();
}
domNode.childNodes.forEach((childNode: any) => {
if (childNode.classList.contains("ql-code-block")) {
if (!prevElement.isCodeBlock) {
const lang = childNode.attributes.getNamedItem("data-language") ? childNode.attributes.getNamedItem("data-language").value : "";
prevElement = {
...prevElement,
isCodeBlock: true,
lang,
currString: childNode.innerText
};
} else {
prevElement = {
...prevElement,
currString: prevElement.currString + "\n" + childNode.innerText
};
}
toBeDeletedNodes.push(childNode);
}
});
finalizeCodeBlock();
} else if (!domNode.classList.contains("ql-code-block")) {
finalizeCodeBlock();
}
} else if (domNode.tagName === "SELECT") {
} else if (domNode.tagName === "SELECT" || domNode.tagName === "OPTION") {
toBeDeletedNodes.push(domNode);
}
}
if (prevElement.isCodeBlock) {
finalizeCodeBlock();
}
toBeDeletedNodes.forEach((domNode: HTMLElement) => {
domNode.remove();
});
Expand Down Expand Up @@ -411,4 +411,8 @@
caret-color: #00A6D8 !important;
color: #00A6D8 !important;
}
.editor >>> .ql-code-block-container {
background-color: #b3b3b3;
}
</style>
1 change: 1 addition & 0 deletions cshub-client/src/registerServiceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if (process.env.NODE_ENV === "production") {
},
updated() {
console.log("New content is available; please refresh.");
window.location.reload(true);
},
offline() {
console.log("No internet connection found. App is running in offline mode.");
Expand Down
3 changes: 2 additions & 1 deletion cshub-server/src/components/pages/GetSearchPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ app.post(GetSearchPosts.getURL, (req: Request, res: Response) => {
INNER JOIN posts T2 ON T1.post = T2.id
WHERE htmlContent LIKE ?
AND (T2.author = ? OR (T2.approved = 1 AND T1.approved = 1) OR (SELECT admin FROM users WHERE id = ?) = 1)
GROUP BY hash
ORDER BY T2.upvotes DESC, T2.datetime DESC
LIMIT 5
`, `%${searchPostRequest.query}%`, userId, userId)
Expand All @@ -42,4 +43,4 @@ app.post(GetSearchPosts.getURL, (req: Request, res: Response) => {
res.status(500).send();
}

});
});

0 comments on commit e402413

Please sign in to comment.