Skip to content

Commit

Permalink
fix: issuesreported in sonar cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
yld-weng committed Nov 8, 2022
1 parent 2beedab commit 5671495
Show file tree
Hide file tree
Showing 34 changed files with 393 additions and 347 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const connectionLineStyle = { stroke: "#fff" };
* Return flowchart
* @returns
*************************/
const flowChart = () => {
const FlowChart = () => {
const [displayChart, setDisplayChart] = useState(false);
const [showAll, toggleShowAll] = useState(false);
const [centreOnClick, toggleCentre] = useState(true);
Expand Down Expand Up @@ -629,4 +629,4 @@ const flowChart = () => {
);
};

export default flowChart;
export default FlowChart;
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const DatasetSummary = ({ currentDataset }) => {
};

if (loading) {
<div>Loading...</div>;
return <div>Loading...</div>;
}

return (
Expand Down
4 changes: 2 additions & 2 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
});

const POSTS_PER_PAGE = 12;
var numPages = posts.length;
let numPages = posts.length;
const categories = [];
const tags = [];

Expand All @@ -341,7 +341,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {

// Call `createPage` for each result/post
posts.forEach(({ node }, index, arr) => {
var excluded = false;
let excluded = false;

// For each post, add their tags/categories to arrays
node.frontmatter.category &&
Expand Down
12 changes: 7 additions & 5 deletions src/components/blog/menuTag.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { FaTags, FaAngleDown } from "react-icons/fa";
import { FiSearch } from "react-icons/fi";
import { useLocation } from "@gatsbyjs/reach-router";

const menuTag = ({ pageContext, handleTagMenu, tagMenu }) => {
const MenuTag = ({ pageContext, handleTagMenu, tagMenu }) => {
const [filterTag, setfilterTag] = useState(pageContext.allTags);

var { href } = useLocation();
let { href } = useLocation();
if (!href) href = "";

function searchTag(e) {
Expand Down Expand Up @@ -86,8 +86,10 @@ const menuTag = ({ pageContext, handleTagMenu, tagMenu }) => {
);
};

export default menuTag;
export default MenuTag;

menuTag.propTypes = {
pageContext: PropTypes.any
MenuTag.propTypes = {
pageContext: PropTypes.any,
handleTagMenu: PropTypes.func,
tagMenu: PropTypes.bool
};
16 changes: 10 additions & 6 deletions src/components/blog/menuTagSlide.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { FiSearch } from "react-icons/fi";
import { IoMdClose } from "react-icons/io";
import { useLocation } from "@gatsbyjs/reach-router";

const menuTagSlide = ({ pageContext, handleTagMenu, tagMenu }) => {
const MenuTagSlide = ({ pageContext, handleTagMenu, tagMenu }) => {
const BUTTON_STYLES = `bg-brand-blue text-brand-black hover:bg-brand-black hover:text-white`;
const [filterTag, setfilterTag] = useState(pageContext.allTags);
var { href } = useLocation();
let { href } = useLocation();
if (!href) href = "";

function handleChange(e) {
Expand Down Expand Up @@ -61,7 +61,9 @@ const menuTagSlide = ({ pageContext, handleTagMenu, tagMenu }) => {
title="Close the menu"
aria-label="Close the slide tag menu"
>
<div className={`${BUTTON_STYLES} px-3 py-3 transition duration-500 font-bold`}>
<div
className={`${BUTTON_STYLES} px-3 py-3 transition duration-500 font-bold`}
>
<IoMdClose />
</div>
</button>
Expand Down Expand Up @@ -117,8 +119,10 @@ const menuTagSlide = ({ pageContext, handleTagMenu, tagMenu }) => {
);
};

export default menuTagSlide;
export default MenuTagSlide;

menuTagSlide.propTypes = {
pageContext: PropTypes.any
MenuTagSlide.propTypes = {
pageContext: PropTypes.any,
handleTagMenu: PropTypes.func,
tagMenu: PropTypes.bool
};
2 changes: 1 addition & 1 deletion src/components/blog/postPagination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PostPagination extends React.Component {
const displayShareButtons = this.props.displayShareButtons ?? true;
const { githubLink, shareLink, shareMessage } = shareLinks;

var mdxType = mdx.frontmatter.type || "blog";
let mdxType = mdx.frontmatter.type || "blog";

let prevTitle = prev ? shortenText(prev.node.frontmatter.title, 6) : "";
let nextTitle = next ? shortenText(next.node.frontmatter.title, 6) : "";
Expand Down
6 changes: 3 additions & 3 deletions src/components/home/eventNotice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Fade from "react-reveal/Fade";
import { shortenText, calculateUserLocalTime } from "../../utils/shared";
import NoThumb from "../../images/no_thumbnail.png";

const eventNotice = ({ eventBrite }) => {
const EventNotice = ({ eventBrite }) => {
const UPDATE_TIME_MS = 30000;
const [currentDate, setDate] = useState(
moment().format("ddd DD MMMM YYYY, hh:mm A")
Expand Down Expand Up @@ -114,8 +114,8 @@ const eventNotice = ({ eventBrite }) => {
);
};

export default eventNotice;
export default EventNotice;

eventNotice.propTypes = {
EventNotice.propTypes = {
eventBrite: PropTypes.any
};
2 changes: 1 addition & 1 deletion src/components/home/latestPost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getImageSource, shortenText } from "../../utils/shared";
import { GatsbyImage } from "gatsby-plugin-image";

const latestPost = ({ post }) => {
var count = 0;
let count = 0;

return (
<>
Expand Down
6 changes: 3 additions & 3 deletions src/components/home/searchHome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ class SearchHome extends Component {
}

getSearchResults(query) {
var index = window.__FLEXSEARCH__.en.index;
var store = window.__FLEXSEARCH__.en.store;
let index = window.__FLEXSEARCH__.en.index;
let store = window.__FLEXSEARCH__.en.store;
if (!query || !index) {
return [];
} else {
var results = [];
let results = [];
// search the indexed fields
Object.keys(index).forEach((idx) => {
results.push(...index[idx].values.search(query)); // more search options at https://github.com/nextapps-de/flexsearch#index.search
Expand Down
17 changes: 9 additions & 8 deletions src/components/shared/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ const Header = () => {
const [isScroll, toggleScrolled] = useState(false);
const [isOpen, toggleOpen] = useState(false);
const location = useLocation();
var currentPagePath = location.pathname;
let currentPagePath = location.pathname;

// close mobile menu on route change
if (typeof window !== "undefined" && window.screen.width <= 1200) {
useEffect(() => {
useEffect(() => {
if (typeof window !== "undefined" && window.screen.width <= 1200) {
toggleExpansion(false);
}, [location]);
}
}
toggleExpansion(false);
}, [location]);

// monitor page scroll
useEffect(() => {
Expand Down Expand Up @@ -99,7 +100,7 @@ const Header = () => {
*/
const NavLink = (props) => {
function navColourClass(mobile = false) {
var className = "transition duration-300 relative "; // don't remove space
let className = "transition duration-300 relative "; // don't remove space

if (mobile == "true") {
if (isScroll) {
Expand Down Expand Up @@ -176,7 +177,7 @@ const Header = () => {
};

function mobileMenuIconClass() {
var className =
let className =
"px-3 py-2 flex items-center border rounded outline-none transition duration-300 group-hover:border-gray-700 group-hover:text-gray-700";

if (isExpanded || isScroll || currentPagePath === "/") {
Expand All @@ -189,7 +190,7 @@ const Header = () => {

function copyRssLink() {
toggleOpen(true);
var copyText = document.querySelector("#rssLink");
let copyText = document.querySelector("#rssLink");
copyText.select();
copyText.setSelectionRange(0, 9999);
document.execCommand("copy");
Expand Down
30 changes: 16 additions & 14 deletions src/components/shared/scrollTop.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import React from 'react'
import PropTypes from "prop-types"
import { IoIosArrowUp } from "react-icons/io"
import { trackScrollPosition } from "../../utils/hooks/trackScrollPosition"
import React from "react";
import PropTypes from "prop-types";
import { IoIosArrowUp } from "react-icons/io";
import { useTrackScrollPosition } from "../../utils/hooks/trackScrollPosition";

const scrollTop = () => {

trackScrollPosition("scrollTop-btn");
useTrackScrollPosition("scrollTop-btn");

return (
<div id="scrollTop-btn" className="scrollTop-btn cursor-pointer group" onClick={() => window.scrollTo({ top: 0, behavior: 'smooth' })}>
<IoIosArrowUp className="scrollTopArrow absolute font-bold text-3xl text-gray-500 group-hover:text-white" />
<div
id="scrollTop-btn"
className="scrollTop-btn cursor-pointer group"
onClick={() => window.scrollTo({ top: 0, behavior: "smooth" })}
>
<IoIosArrowUp className="scrollTopArrow absolute font-bold text-3xl text-gray-500 group-hover:text-white" />
</div>
)
}
);
};

export default scrollTop
export default scrollTop;

scrollTop.propTypes = {
pageContext: PropTypes.any,

}
pageContext: PropTypes.any
};
50 changes: 23 additions & 27 deletions src/components/shared/search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class Search extends Component {
componentDidMount = () => {
setTimeout(() => {
if (this.props.location.state && this.props.location.state.searchWord) {
var queryHome = this.props.location.state.searchWord;
var input = document.getElementById("pageSearch");
let queryHome = this.props.location.state.searchWord;
let input = document.getElementById("pageSearch");
this.setState({ query: queryHome });
input.setAttribute("value", queryHome);
this.searchFunction(queryHome);
Expand All @@ -31,34 +31,30 @@ class Search extends Component {

render() {
const ResultList = () => {
// query length changed from 2 to 0
if (this.state.results.length > 0 && this.state.query.length > 0) {
const data = useStaticQuery(graphql`
query postList {
allMdx(
sort: { fields: [frontmatter___date], order: DESC }
filter: { frontmatter: { published: { ne: false } } }
) {
edges {
node {
id
frontmatter {
date(formatString: "ddd, DD MMM YYYY")
thumbnail {
childImageSharp {
gatsbyImageData(
placeholder: BLURRED
layout: FULL_WIDTH
)
}
const data = useStaticQuery(graphql`
query postList {
allMdx(
sort: { fields: [frontmatter___date], order: DESC }
filter: { frontmatter: { published: { ne: false } } }
) {
edges {
node {
id
frontmatter {
date(formatString: "ddd, DD MMM YYYY")
thumbnail {
childImageSharp {
gatsbyImageData(placeholder: BLURRED, layout: FULL_WIDTH)
}
}
}
}
}
}
`);

}
`);
// query length changed from 2 to 0
if (this.state.results.length > 0 && this.state.query.length > 0) {
return (
<div>
<div className="bg-gray-50 text-gray-900 py-2">
Expand Down Expand Up @@ -252,13 +248,13 @@ class Search extends Component {
//index - a flexsearch index instance (variables set in gatsby-config)
//store - object that stores the indexed gatsby nodes where the id of each node corresponds to the id the filter, according with flexsearch.js best practices (https://github.com/nextapps-de/flexsearch#best-practices)).

var index = window.__FLEXSEARCH__.en.index;
var store = window.__FLEXSEARCH__.en.store;
let index = window.__FLEXSEARCH__.en.index;
let store = window.__FLEXSEARCH__.en.store;

if (!query || !index) {
return [];
} else {
var results = [];
let results = [];
// search the indexed fields
Object.keys(index).forEach((idx) => {
results.push(
Expand Down
Loading

0 comments on commit 5671495

Please sign in to comment.