Skip to content

Commit

Permalink
adding typesense and instantsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredoloce committed May 7, 2024
1 parent e717716 commit 3455d86
Show file tree
Hide file tree
Showing 20 changed files with 2,230 additions and 612 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
browser: true,
commonjs: true,
es6: true,
node: true,
},

// Base config
Expand Down
67 changes: 67 additions & 0 deletions app/core/components/HitsInstantSearch/ProjectApplicantHits.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import ProposalCard from "../ProposalCard";
import { Grid } from "@mui/material";
import "instantsearch.css/themes/satellite.css";
import { connectHits } from "react-instantsearch-core";

const initials = (preferredName: string, lastName: string) => {
return preferredName.substring(0, 1) + lastName.substring(0, 1);
};

interface SearchProjectsOutput {
id: string;
name: string;
createdAt: string;
updatedAt: string;
description: string;
preferredName: string;
lastName: string;
avatarUrl: string;
status: string;
color?: string;
searchSkills?: { name: string }[];
votesCount: number;
projectMembers: number;
owner?: string;
tierName?: string;
latest_pmw: boolean;
resourcesCount?: number;
}

interface HitProps {
hits: SearchProjectsOutput[];
}

function HitApplicants({ hits }: HitProps) {
return hits.map((hit, i) => {
const skillsname = hit.searchSkills?.map((skillName: any) => ({

Check warning on line 36 in app/core/components/HitsInstantSearch/ProjectApplicantHits.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

Unexpected any. Specify a different type
name: skillName.name,
}));

return (
<>
<Grid item xs={12} sm={6} lg={4} key={i}>
<ProposalCard
id={hit.id}
title={hit.name}
picture={hit.avatarUrl}
initials={initials(hit.preferredName, hit.lastName)}
date={new Intl.DateTimeFormat([], {
year: "numeric",
month: "long",
day: "2-digit",
}).format(new Date(hit.createdAt))}
description={hit.description}
status={hit.status}
skills={skillsname}
color={hit.color}
votesCount={Number(hit.votesCount)}
tierName={hit.tierName}
projectMembers={Number(hit.projectMembers)}
/>
</Grid>
</>
);
});
}

export default connectHits(HitApplicants);
67 changes: 67 additions & 0 deletions app/core/components/HitsInstantSearch/ProjectHits.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import ProposalCard from "../ProposalCard";
import { Grid } from "@mui/material";
import "instantsearch.css/themes/satellite.css";
import { connectHits } from "react-instantsearch-core";

const initials = (preferredName: string, lastName: string) => {
return preferredName.substring(0, 1) + lastName.substring(0, 1);
};

interface SearchProjectsOutput {
id: string;
name: string;
createdAt: string;
updatedAt: string;
description: string;
preferredName: string;
lastName: string;
avatarUrl: string;
status: string;
color?: string;
searchSkills?: { name: string }[];
votesCount: number;
projectMembers: number;
owner?: string;
tierName?: string;
latest_pmw: boolean;
resourcesCount?: number;
}

interface HitProps {
hits: SearchProjectsOutput[];
}

function HitsA({ hits }: HitProps) {
return hits.map((hit, i) => {
const skillsname = hit.searchSkills?.map((skillName: any) => ({

Check warning on line 36 in app/core/components/HitsInstantSearch/ProjectHits.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

Unexpected any. Specify a different type
name: skillName.name,
}));

return (
<>
<Grid item xs={12} sm={6} lg={4} key={i}>
<ProposalCard
id={hit.id}
title={hit.name}
picture={hit.avatarUrl}
initials={initials(hit.preferredName, hit.lastName)}
date={new Intl.DateTimeFormat([], {
year: "numeric",
month: "long",
day: "2-digit",
}).format(new Date(hit.createdAt))}
description={hit.description}
status={hit.status}
skills={skillsname}
color={hit.color}
votesCount={Number(hit.votesCount)}
tierName={hit.tierName}
projectMembers={Number(hit.projectMembers)}
/>
</Grid>
</>
);
});
}

export default connectHits(HitsA);
77 changes: 77 additions & 0 deletions app/core/components/HitsInstantSearch/TableHits.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { Chip } from "@mui/material";
import TableCell from "@mui/material/TableCell";
import TableRow from "@mui/material/TableRow";
import "instantsearch.css/themes/satellite.css";
import { connectHits } from "react-instantsearch-core";

interface SearchProjectsOutput {
sort: number;
id: string;
name: string;
createdAt: string;
updatedAt: string;
description: string;
preferredName: string;
lastName: string;
avatarUrl: string;
status: string;
color?: string;
searchSkills?: { name: string }[];
votesCount: number;
projectMembers: number;
owner?: string;
tierName?: string;
latest_pmw: boolean;
resourcesCount?: number;
}

interface HitProps {
hits: SearchProjectsOutput[];
}

function TableHits({ hits }: HitProps) {
return hits.map((hit) => {
return (
<TableRow key={hit.sort - 1}>
<TableCell>
<a
href={`/projects/${hit.id}`}
style={{ color: "inherit", textDecoration: "none" }}
>
{hit.name}
</a>
</TableCell>
<TableCell>
<Chip
component="a"
href={`/projects?tier=${hit.tierName}`}
clickable
rel="noreferrer"
label={hit.tierName}
/>
</TableCell>
<TableCell>
<a
href={`/projects/${hit.id}`}
style={{ color: "inherit", textDecoration: "none" }}
>
{hit.status}
</a>
</TableCell>
<TableCell>{hit.projectMembers}</TableCell>
<TableCell>{hit.votesCount}</TableCell>
<TableCell>
<a
href={`/projects/${hit.id}`}
style={{ color: "inherit", textDecoration: "none" }}
>
{"Code"}
</a>
</TableCell>
<TableCell>{hit.resourcesCount}</TableCell>
</TableRow>
);
});
}

export default connectHits(TableHits);
56 changes: 56 additions & 0 deletions app/core/components/HitsInstantSearch/TableHitsApplicant.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import TableCell from "@mui/material/TableCell";
import TableRow from "@mui/material/TableRow";
import "instantsearch.css/themes/satellite.css";
import { connectHits } from "react-instantsearch-core";

interface SearchProjectsOutput {
sort: number;
id: string;
name: string;
createdAt: string;
updatedAt: string;
description: string;
preferredName: string;
lastName: string;
avatarUrl: string;
status: string;
color?: string;
searchSkills?: { name: string }[];
votesCount: number;
projectMembers: number;
owner?: string;
tierName?: string;
latest_pmw: boolean;
resourcesCount?: number;
}

interface HitProps {
hits: SearchProjectsOutput[];
}

function TableHitsApplicant({ hits }: HitProps) {
return hits.map((hit) => {
return (
<TableRow key={hit.sort - 1}>
<TableCell>
<a
href={`/projects/${hit.id}`}
style={{ color: "inherit", textDecoration: "none" }}
>
{hit.name}
</a>
</TableCell>
<TableCell>
<a
href={`/projects/${hit.id}`}
style={{ color: "inherit", textDecoration: "none" }}
>
{"Code"}
</a>
</TableCell>
</TableRow>
);
});
}

export default connectHits(TableHitsApplicant);
29 changes: 10 additions & 19 deletions app/core/components/Search/index.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
import SearchIcon from "@mui/icons-material/Search";
import { InputAdornment, TextField } from "@mui/material";
import { useNavigate, useSearchParams } from "@remix-run/react";
import { useState } from "react";

export const Search = () => {
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const searchQuery =
searchParams.get("q") !== "myProposals" && searchParams.get("q")
? searchParams.get("q")
: "";
const [searchValue, setSearchValue] = useState(searchQuery);
const projectsSearch = "/projects";
const handleEnterKeyPress = (e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.key === "Enter") {
navigate(`${projectsSearch}?q=${searchValue}`);
}
const Search = ({ onSearch }: { onSearch: (value: string) => void }) => {
const [searchValue, setSearchValue] = useState("");

const handleSearchChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { value } = event.target;
setSearchValue(value);
onSearch(value);
};

return (
<TextField
label="Search Project Name"
value={searchValue}
onChange={(e) => setSearchValue(e.target.value)}
size="small"
placeholder="Search in header..."
value={searchValue}
onChange={handleSearchChange}
sx={{ width: "200px" }}
onKeyPress={(e) => {
handleEnterKeyPress(e);
}}
InputProps={{
startAdornment: (
<InputAdornment position="start">
Expand Down
Loading

0 comments on commit 3455d86

Please sign in to comment.