-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14483a0
commit 2a51ea0
Showing
10 changed files
with
93 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
class CompaniesController < InertiaController | ||
include Filterameter::DeclarativeFilters | ||
include Pagy::Backend | ||
|
||
default_sort name: :asc | ||
|
||
filter :name, partial: true | ||
filter :city, name: :id, association: :city | ||
filter :region, name: :id, association: :region | ||
filter :country, name: :id, association: :country | ||
filter :continent, name: :id, association: :continent | ||
|
||
def index | ||
pagy, companies = pagy(company_scope.all) | ||
companies = build_query_from_filters(Company.with_all_associations) | ||
pagy, companies = pagy(companies) | ||
@companies = CompanySerializer.many(companies) | ||
|
||
paginate(pagy) | ||
@pagination = inertia_pagination(pagy) | ||
end | ||
|
||
def show | ||
company = company_scope.friendly.find(params[:id]) | ||
company = Company.with_all_associations.friendly.find(params[:id]) | ||
@company = CompanySerializer.one(company) | ||
end | ||
|
||
private | ||
|
||
def company_scope | ||
Company.includes(:technologies, :continent, :country, :region, :city) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useForm, usePage } from "@inertiajs/react"; | ||
import { Search } from "lucide-react"; | ||
|
||
import Link from "@/components/link"; | ||
import { Input } from "@/components/ui/input"; | ||
import { Spinner } from "@/components/ui/spinner"; | ||
|
||
function Header() { | ||
const { props } = usePage(); | ||
|
||
const { data, setData, get, processing } = useForm({ | ||
q: (props.q as string) || "", | ||
}); | ||
|
||
const handleSearch = (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
get("/companies", { | ||
preserveState: true, | ||
preserveScroll: true, | ||
}); | ||
}; | ||
|
||
const Icon = processing ? Spinner : Search; | ||
|
||
return ( | ||
<header className="bg-white shadow"> | ||
<div className="container mx-auto py-6"> | ||
<div className="flex flex-col sm:flex-row justify-between items-center"> | ||
<Link | ||
href="/" | ||
className="text-3xl font-bold text-red-600 mb-4 sm:mb-0" | ||
> | ||
Ruby Companies | ||
</Link> | ||
<form onSubmit={handleSearch} className="w-full sm:w-auto"> | ||
<div className="relative ml-auto flex-1 md:grow-0"> | ||
<Icon className="absolute left-2.5 top-3 h-4 w-4 text-muted-foreground" /> | ||
<Input | ||
type="search" | ||
placeholder="Search..." | ||
className="w-full rounded-lg bg-background pl-8 md:w-[200px] lg:w-[336px]" | ||
value={data.q} | ||
onChange={(event) => setData("q", event.target.value)} | ||
disabled={processing} | ||
/> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</header> | ||
); | ||
} | ||
|
||
Header.displayName = "layouts/application/header"; | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters