This commit is contained in:
parent
64fa4bc88e
commit
762d28f9ea
2 changed files with 27 additions and 8 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
import { useState } from "react"
|
|
||||||
import { Quote } from "./pocketbase-types"
|
import { Quote } from "./pocketbase-types"
|
||||||
|
|
||||||
interface QuoteInfoProps {
|
interface QuoteInfoProps {
|
||||||
|
|
@ -8,7 +7,7 @@ export default function QuoteInfo({ quote }: QuoteInfoProps) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
//TODO: Bettes Colors
|
//TODO: Bettes Colors
|
||||||
<div className="dark:bg-slate-800 shadow-(--box) m-1 p-2 cursor-pointer" onClick={(e) => console.log(quote.id)}>
|
<div className="dark:bg-slate-800 shadow-(--box) m-1 p-2 cursor-pointer">
|
||||||
<p className="border-4 border-black bg-slate-300 text-black p-1 my-1 cursor-text">{quote.quote}</p>
|
<p className="border-4 border-black bg-slate-300 text-black p-1 my-1 cursor-text">{quote.quote}</p>
|
||||||
{quote.context && <p className="border-4 border-black bg-slate-300 text-slate-600 p-1 my-1 cursor-text">{quote.context}</p>}
|
{quote.context && <p className="border-4 border-black bg-slate-300 text-slate-600 p-1 my-1 cursor-text">{quote.context}</p>}
|
||||||
<div className="flex flex-row">
|
<div className="flex flex-row">
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,25 @@ export default function QuoteList() {
|
||||||
const [error, setError] = useState<Error | null>(null)
|
const [error, setError] = useState<Error | null>(null)
|
||||||
const [collection, setCollection] = useState<Collections | null>(Collections.QtBit)
|
const [collection, setCollection] = useState<Collections | null>(Collections.QtBit)
|
||||||
const [searchItem, setSearchItem] = useState<string | null>(null)
|
const [searchItem, setSearchItem] = useState<string | null>(null)
|
||||||
|
const [searchFilter, setSearchFilter] = useState<string | null>("quote")
|
||||||
|
|
||||||
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
|
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
const searchTerm = e.target.value;
|
const searchTerm = e.target.value;
|
||||||
setSearchItem(searchTerm)
|
setSearchItem(searchTerm)
|
||||||
|
let filteredItems;
|
||||||
const filteredItems = quotes?.filter((quote) => quote.quote.toLowerCase().includes(searchTerm.toLowerCase()));
|
switch (searchFilter) {
|
||||||
|
case "quote":
|
||||||
|
filteredItems = quotes?.filter((quote) => quote.quote.toLowerCase().includes(searchTerm.toLowerCase()));
|
||||||
|
break;
|
||||||
|
case "context":
|
||||||
|
filteredItems = quotes?.filter((quote) => quote.context?.toLowerCase().includes(searchTerm.toLowerCase()));
|
||||||
|
break;
|
||||||
|
case "author":
|
||||||
|
filteredItems = quotes?.filter((quote) => quote.author.toLowerCase().includes(searchTerm.toLowerCase()));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
setFilteredQuotes(filteredItems!)
|
setFilteredQuotes(filteredItems!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,13 +83,20 @@ export default function QuoteList() {
|
||||||
<div className='pl-2 flex flex-row'>
|
<div className='pl-2 flex flex-row'>
|
||||||
<input
|
<input
|
||||||
title='Search for quote'
|
title='Search for quote'
|
||||||
placeholder='Search...'
|
placeholder={'Search for ' + searchFilter as string}
|
||||||
value={searchItem as string}
|
value={searchItem as string}
|
||||||
onChange={e => handleInputChange(e)}
|
onChange={e => handleInputChange(e)}
|
||||||
className='placeholder:text-slate-400 bg-slate-700' />
|
className='placeholder:text-slate-400 bg-slate-700' />
|
||||||
<button type="button" className='cursor-pointer' title='Filter search'>
|
<p className='text-lime-500'>|</p>
|
||||||
<FilterIcon className="w-5 mx-1 active:text-lime-500" />
|
<select
|
||||||
</button>
|
title='Filter search'
|
||||||
|
className='pr-1 bg-slate-700'
|
||||||
|
value={searchFilter as string}
|
||||||
|
onChange={e => setSearchFilter(e.target.value as string)}>
|
||||||
|
<option value="quote">Quote</option>
|
||||||
|
<option value="context">Context</option>
|
||||||
|
<option value="author">Author</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<p className='text-lime-500'>|</p>
|
<p className='text-lime-500'>|</p>
|
||||||
<button type='button' className='cursor-pointer ml-auto' title='Add new quote'>
|
<button type='button' className='cursor-pointer ml-auto' title='Add new quote'>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue