diff --git a/src/App.js b/src/App.js index 4fa5d18..8168693 100644 --- a/src/App.js +++ b/src/App.js @@ -1,21 +1,21 @@ -import React, { Component } from 'react'; -import './App.css'; -import './components/utils/css/grid.css'; -import ItemList from './components/ItemList'; -import LanguagesOption from './components/utils/js/LanguagesOption'; +import React, { Component } from "react"; +import "./App.css"; +import "./components/utils/css/grid.css"; +import ItemList from "./components/ItemList"; +import LanguagesOption from "./components/utils/js/LanguagesOption"; class App extends Component { - constructor() { - super() + super(); this.state = { search: "", source: "all", language: "all", sort: "all", order: "all", - go_search: false - } + go_search: false, + collapseFilters: false, // Add state to handle show/hide filters + }; this.refText = React.createRef(); } @@ -23,14 +23,12 @@ class App extends Component { * * @param {*} event */ - handle_change(event){ - if (event.key === 'Enter') - this.setState({go_search: true}); - else - this.setState({go_search: false}); - this.setState({search: event.target.value}); + handle_change(event) { + if (event.key === "Enter") this.setState({ go_search: true }); + else this.setState({ go_search: false }); + this.setState({ search: event.target.value }); - this.setState({search: event.target.value}); + this.setState({ search: event.target.value }); } /** @@ -38,134 +36,184 @@ class App extends Component { * @param {*} event * @param {*} type */ - handle_change_option(event, type){ - if (["source", "language", "sort", "order"].indexOf(type) !== -1){ - let toUpdate = {"go_search": true} - toUpdate[type] = event.target.value !== '' ? event.target.value : 'all' - this.setState(toUpdate); + handle_change_option(event, type) { + if (["source", "language", "sort", "order"].indexOf(type) !== -1) { + let toUpdate = { go_search: true }; + toUpdate[type] = event.target.value !== "" ? event.target.value : "all"; + this.setState(toUpdate); } } /** * */ - go_search_change(){ + go_search_change() { this.setState({ - go_search: !this.state.go_search + go_search: !this.state.go_search, }); } + /** + * + */ + // handle hide/show filters on Click + handleClick() { + this.setState((prevState) => ({ + ...prevState, + collapseFilters: !prevState.collapseFilters, + })); + } + // get query parameter - getQueryStringValue (key) { + getQueryStringValue(key) { return decodeURIComponent( - window.location.search.replace( - new RegExp( - "^(?:.*[&\\?]" + - encodeURIComponent(key).replace(/[.+*]/g, "\\$&") + - "(?:\\=([^&]*))?)?.*$", "i" - ), "$1" - ) + window.location.search.replace( + new RegExp( + "^(?:.*[&\\?]" + + encodeURIComponent(key).replace(/[.+*]/g, "\\$&") + + "(?:\\=([^&]*))?)?.*$", + "i" + ), + "$1" + ) ); } - componentDidMount(){ + componentDidMount() { const searchText = this.getQueryStringValue("q"); - if (searchText !== ''){ + if (searchText !== "") { this.setState({ search: searchText, - go_search: true + go_search: true, }); } this.refText.current.focus(); } - render(){ - const linkStyleNone = {"color": "white", "textDecoration": "none"}; + render() { + const linkStyleNone = { color: "white", textDecoration: "none" }; return (
- Zz0ll0
-
- Search open-source projects on github / gitlab / bitbucket.
-
-
-
- [Project-link]
-
-
+
+ Zz0ll0
+
+
+ Search open-source projects on github / gitlab / bitbucket.
+
+
+
+
+ [Project-link]
+
+