Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3b3fe10
developed child safe organisation resources page
MoeBuTa Dec 15, 2023
0e63b39
rename file name to make it shorter
MoeBuTa Dec 15, 2023
45d4f35
rename image name
MoeBuTa Dec 15, 2023
6f5efb3
fixing format issues
MoeBuTa Dec 15, 2023
037db31
fixing variable typos
MoeBuTa Dec 15, 2023
619ee2b
fixing function format issue
MoeBuTa Dec 15, 2023
66d6fe3
fixing argument issue and formatting code
MoeBuTa Dec 15, 2023
a6fa150
refactored previous code based on the new style guide
MoeBuTa Dec 16, 2023
9d05eef
removed import React
MoeBuTa Dec 16, 2023
e10cfbf
removed import React
MoeBuTa Dec 16, 2023
20081b3
resolve file name typo
MoeBuTa Dec 16, 2023
d68c35d
remove unnecessary comment
MoeBuTa Dec 16, 2023
bd47977
run format prettier
MoeBuTa Dec 16, 2023
863e3da
fix apostrophes issue and missing space issue
MoeBuTa Dec 16, 2023
c1fa502
extract json objects from original pages to fix DRY issue.
MoeBuTa Dec 16, 2023
29e0ba5
Merge branch 'main' into issue-16-Paypal_donation_component
MoeBuTa Dec 16, 2023
8c3adb9
run prettier format
MoeBuTa Dec 16, 2023
f1ca74d
Merge branch 'issue-16-Paypal_donation_component' into issue-8-Suppor…
MoeBuTa Dec 16, 2023
ad7314c
Merge branch 'issue-42-Child_Safe_Resources_Page' into issue-8-Suppor…
MoeBuTa Dec 16, 2023
99e8f06
refactor: fix dry issue
MoeBuTa Dec 17, 2023
0b8615b
refactor: further fix dry issue by extracting child-safe-list from mu…
MoeBuTa Dec 17, 2023
bf1fe42
Merge branch 'issue-42-Child_Safe_Resources_Page' into issue-8-Suppor…
MoeBuTa Dec 17, 2023
2403784
Merge branch 'main' of https://github.com/codersforcauses/starick int…
MoeBuTa Dec 17, 2023
27ddfab
extract disclaimer component
MoeBuTa Dec 17, 2023
2149271
Merge branch 'main' into issue-8-Support_us_pages
MoeBuTa Dec 17, 2023
b3e8638
merge main into the branch
MoeBuTa Jan 4, 2024
3658a07
Merge branch 'main' into issue-13-Website_search_bar
MoeBuTa Feb 24, 2024
3d30dcd
try implement basic searchbar functionality
MoeBuTa Mar 4, 2024
c8e7d48
add notes for future works
MoeBuTa Mar 4, 2024
1b3085d
Merge branch 'main' of https://github.com/codersforcauses/starick int…
Aifert Mar 15, 2024
9bf9b1c
searchbar
seraph1201 Apr 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
358 changes: 358 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
"prettier-plugin-tailwindcss": "^0.3.0",
"tailwindcss": "^3.3.2",
"ts-node": "^10.9.1",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"algoliasearch":"^4.22.1",
"react-instantsearch": "^7.6.0",
"react-instantsearch-router-nextjs": "^7.6.0"
}
}
8 changes: 8 additions & 0 deletions src/components/Header/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The implementation of the functionality of the web search bar may need to be integrated with headless WordPress.
Check out this blog:
https://www.datocms.com/blog/algolia-nextjs-how-to-add-algolia-instantsearch

and for algolia setup:

https://www.algolia.com/doc/guides/building-search-ui/going-further/server-side-rendering/react/#with-nextjs

2 changes: 1 addition & 1 deletion src/components/Header/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeEvent, KeyboardEvent, useState } from "react";
export default function Search({ prompt }: { prompt: string }) {
export default function ({ prompt }: { prompt: string }) {
const [value, setValue] = useState("Enter search...");
const searchHandler = (event: ChangeEvent<HTMLInputElement>) => {
const { target } = event;
Expand Down
29 changes: 28 additions & 1 deletion src/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from "react";
import {ChangeEvent, KeyboardEvent, useState} from "react";
import { useRouter } from "next/navigation";
import Link from "next/link";
import { FiSearch, FiX } from "react-icons/fi";

Expand All @@ -7,6 +8,30 @@ import PanicButton from "./PanicButton";

export default function Header() {
const [searchOpen, setSearchOpen] = useState(false);
const [inputValue, setInputValue] = useState("");
const router = useRouter()


const searchHandler = (event: ChangeEvent<HTMLInputElement>) => {
const { target } = event;
setInputValue(target.value);
};

const handleSearch = () => {

if (inputValue) return router.push(`/?q=${inputValue}`);

else return router.push("/")

}

const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
if (event.key === "Enter") {
setInputValue(inputValue);
return handleSearch()
}
};


return (
<header className="sticky top-0 z-50">
Expand Down Expand Up @@ -44,6 +69,8 @@ export default function Header() {
placeholder="Search..."
type="text"
className="relative inset-0 w-80 bg-transparent placeholder:text-starick-white placeholder:opacity-80 focus:outline-none"
onChange={searchHandler}
onKeyDown={handleKeyDown}
/>
<FiSearch className="inline" />
</div>
Expand Down
46 changes: 33 additions & 13 deletions src/components/SearchBar/search.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,61 @@
import { ChangeEvent, KeyboardEvent, useState } from "react";
import React from "react";

export default function Search({ prompt }: { prompt: string }) {
const [value, setValue] = useState("Enter search...");
const [value, setValue] = useState("");

const searchHandler = (event: ChangeEvent<HTMLInputElement>) => {
const { target } = event;
setValue(target.value);
setValue(event.target.value);
};

const handleClick = () => {
setValue(prompt);
// Function to handle the redirection to Google with site search
const redirectToGoogleSearch = () => {
// Trim the search value and check if it's not empty
const trimmedValue = value.trim();
if (trimmedValue) {
// Encode the search query and construct the Google search URL
const searchQuery = encodeURIComponent(trimmedValue);
const googleSearchUrl = `https://www.google.com/search?q=site:starick.org.au ${searchQuery}`;
// Redirect to the Google search page
window.location.href = googleSearchUrl;
}
};

// Event handler for the Enter key
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
if (event.key === "Enter") {
setValue(prompt);
event.preventDefault(); // Prevent form submission
redirectToGoogleSearch();
}
};

// Event handler for the search button click
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault(); // Prevent form submission
redirectToGoogleSearch();
};

return (
<div className="relative top-16 mx-auto mb-5 mt-8 w-1/2 text-gray-600">
<input
type="search"
name="search"
placeholder={value}
value={value} // Bind input to the state value
placeholder={prompt}
onChange={searchHandler}
onKeyDown={handleKeyDown}
className="h-10 w-full rounded-full bg-gray-300 px-5 pr-10 text-sm focus:outline-none"
/>
<button
onClick={handleClick}
className="absolute right-0 top-0 mr-4 mt-3"
onClick={handleClick}
className="absolute right-0 top-0 mt-3 mr-4"
type="submit"
>
<svg
xmlns="http://www.w3.org/2000/svg"
height="16"
width="16"
viewBox="0 0 512 512"
xmlns="http://www.w3.org/2000/svg"
height="16"
width="16"
viewBox="0 0 512 512"
>
<path d="M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6 .1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z" />
</svg>
Expand Down
52 changes: 52 additions & 0 deletions src/pages/search-page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { renderToString } from 'react-dom/server';
import algoliasearch from 'algoliasearch/lite';
import {
InstantSearch,
InstantSearchServerState,
InstantSearchSSRProvider,
getServerState, SearchBox, Hits,
} from 'react-instantsearch';

const searchClient = algoliasearch(process.env["NEXT_PUBLIC_ALGOLIA_ID"] as string, process.env["NEXT_PUBLIC_ALGOLIA_KEY"] as string);

type SearchPageProps = {
serverState?: InstantSearchServerState;
};

interface HitProps {
hit: {
title: string;
excerpt: string;
};
}

export function Hit({ hit }: HitProps) {
return (
<article>
<h1>{hit.title}</h1>
<p>${hit.excerpt}</p>
</article>
);
}

export default function SearchPage({ serverState }: SearchPageProps) {
return (
<InstantSearchSSRProvider {...serverState}>
<InstantSearch searchClient={searchClient} indexName="starick">
<SearchBox/>
<Hits hitComponent={Hit} />
</InstantSearch>
</InstantSearchSSRProvider>
);
}

export async function getStaticProps() {
const serverState = await getServerState(<SearchPage />, {
renderToString
});
return {
props: {
serverState,
},
};
}