import React from "react"; import { graphql, Link } from "gatsby"; import { connect } from "react-redux"; import { pushNewPage, pushNewQuery } from "../state/app"; import Shell from "../components/Shell"; import Meta from "../components/Meta"; import Search from "../components/Search"; import SnippetCard from "../components/SnippetCard"; import SimpleCard from "../components/SimpleCard"; // =================================================== // Home page (splash and search) // =================================================== const IndexPage = props => { const snippets = props.data.allSnippet.edges; const [searchQuery, setSearchQuery] = React.useState(props.searchQuery); const [searchResults, setSearchResults] = React.useState(snippets); React.useEffect(() => { props.dispatch(pushNewQuery(searchQuery)); let q = searchQuery.toLowerCase(); let results = snippets; if (q.trim().length) results = snippets.filter( ({ node }) => node.tags.all.filter(t => t.indexOf(q) !== -1).length || node.title.toLowerCase().indexOf(q) !== -1 ); setSearchResults(results); }, [searchQuery]); React.useEffect(() => { props.dispatch(pushNewPage("Search", "/search")); }, []); return ( <> Logo

{props.data.site.siteMetadata.title}

{props.data.site.siteMetadata.description}

{searchQuery.length === 0 ? ( <>

Start typing a keyword to see matching snippets or{" "} click to view the whole list.

) : searchResults.length === 0 ? ( <>

We couldn't find any results for the keyword{" "} {searchQuery}.

) : ( <>

Click on a snippet card to view the snippet.

Search results

{searchResults.map(({ node }) => ( ))} )}

30 seconds provides high-quality learning resources for developers of all skill levels in the form of snippet collections in various programming languages since its inception in 2017. Today, 30 seconds consists of a community of over 250 contributors and more than 10 maintainers, dedicated to creating the best short-form learning resources for software developers. Our goal is to make software development more accessible and help the open-source community grow by helping people learn to code for free.

Read more...

    {[ { name: "30 seconds of CSS", url: "https://css.30secondsofcode.org/" }, { name: "30 seconds of Python", url: "https://python.30secondsofcode.org/" }, { name: "30 seconds of React", url: "https://react.30secondsofcode.org/" }, { name: "30 seconds of PHP", url: "https://php.30secondsofcode.org/" }, { name: "30 seconds of Interviews", url: "https://30secondsofinterviews.org/" }, { name: "30 seconds of Knowledge", url: "https://chrome.google.com/webstore/detail/30-seconds-of-knowledge/mmgplondnjekobonklacmemikcnhklla" } ].map(v => (
  • {v.name}
  • ))}
); }; export default connect( state => ({ isDarkMode: state.app.isDarkMode, lastPageTitle: state.app.lastPageTitle, lastPageUrl: state.app.lastPageUrl, searchQuery: state.app.searchQuery }), null )(IndexPage); export const indexPageQuery = graphql` query snippetList { site { siteMetadata { title description author } } file(relativePath: { eq: "30s-icon.png" }) { id childImageSharp { original { src } } } allSnippet { edges { node { title html { text } tags { all } id } } } } `;