forked from aws-samples/amplify-next-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from cabcookie:improve-search
Einfacher Suchen (Projekte/Personen)
- Loading branch information
Showing
14 changed files
with
434 additions
and
99 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useContextContext } from "@/contexts/ContextContext"; | ||
import { FC } from "react"; | ||
import PeopleSelector from "../ui-elements/selectors/people-selector"; | ||
import { Label } from "../ui/label"; | ||
import { CreateMeetingProps } from "./useMeetingFilter"; | ||
|
||
type CreateOneOnOneMeetingProps = { | ||
createMeeting: (props: CreateMeetingProps) => void; | ||
}; | ||
|
||
const CreateOneOnOneMeeting: FC<CreateOneOnOneMeetingProps> = ({ | ||
createMeeting, | ||
}) => { | ||
const { context } = useContextContext(); | ||
|
||
return ( | ||
<div> | ||
<Label className="font-semibold">Create 1:1 Meeting:</Label> | ||
<PeopleSelector | ||
placeholder="Select person for 1:1…" | ||
value="" | ||
onChange={(personId) => | ||
createMeeting({ | ||
topic: "", | ||
participantId: personId ?? undefined, | ||
context, | ||
}) | ||
} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CreateOneOnOneMeeting; |
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,31 @@ | ||
import { cn } from "@/lib/utils"; | ||
import { FC } from "react"; | ||
import ButtonGroup from "../ui-elements/btn-group/btn-group"; | ||
import { | ||
PROJECT_FILTERS, | ||
ProjectFilters, | ||
useProjectFilter, | ||
} from "./useProjectFilter"; | ||
|
||
type ProjectFilterBtnGrpProps = { | ||
className?: string; | ||
}; | ||
|
||
const ProjectFilterBtnGrp: FC<ProjectFilterBtnGrpProps> = ({ className }) => { | ||
const { isSearchActive, projectFilter, setProjectFilter } = | ||
useProjectFilter(); | ||
|
||
return ( | ||
!isSearchActive && ( | ||
<div className={cn(className)}> | ||
<ButtonGroup | ||
values={PROJECT_FILTERS as ProjectFilters[]} | ||
selectedValue={projectFilter} | ||
onSelect={setProjectFilter} | ||
/> | ||
</div> | ||
) | ||
); | ||
}; | ||
|
||
export default ProjectFilterBtnGrp; |
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,103 @@ | ||
import { useAccountsContext } from "@/api/ContextAccounts"; | ||
import { Project, useProjectsContext } from "@/api/ContextProjects"; | ||
import { filterAndSortProjects } from "@/helpers/projects"; | ||
import { | ||
ComponentType, | ||
createContext, | ||
FC, | ||
useContext, | ||
useEffect, | ||
useState, | ||
} from "react"; | ||
import { SearchProvider, useSearch } from "../search/useSearch"; | ||
|
||
export const PROJECT_FILTERS = ["WIP", "On Hold", "Done"]; | ||
const PROJECT_FILTERS_CONST = ["WIP", "On Hold", "Done"] as const; | ||
export type ProjectFilters = (typeof PROJECT_FILTERS_CONST)[number]; | ||
|
||
export const isValidProjectFilter = ( | ||
filter: string | ||
): filter is ProjectFilters => | ||
PROJECT_FILTERS_CONST.includes(filter as ProjectFilters); | ||
|
||
interface ProjectFilterType { | ||
projects: Project[]; | ||
loadingProjects: ReturnType<typeof useProjectsContext>["loadingProjects"]; | ||
errorProjects: ReturnType<typeof useProjectsContext>["errorProjects"]; | ||
isSearchActive: boolean; | ||
projectFilter: ProjectFilters; | ||
setProjectFilter: (filter: string) => void; | ||
} | ||
|
||
const ProjectFilter = createContext<ProjectFilterType | null>(null); | ||
|
||
export const useProjectFilter = () => { | ||
const searchContext = useContext(ProjectFilter); | ||
if (!searchContext) | ||
throw new Error( | ||
"useProjectFilter must be used within ProjectFilterProvider" | ||
); | ||
return searchContext; | ||
}; | ||
|
||
interface ProjectFilterProviderProps { | ||
children: React.ReactNode; | ||
accountId?: string; | ||
} | ||
|
||
export const ProjectFilterProvider: FC<ProjectFilterProviderProps> = ({ | ||
children, | ||
accountId, | ||
}) => { | ||
const { projects, loadingProjects, errorProjects } = useProjectsContext(); | ||
const { accounts } = useAccountsContext(); | ||
const [filteredProjects, setFilteredProjects] = useState<Project[]>([]); | ||
const { searchText, isSearchActive } = useSearch(); | ||
const [filter, setFilter] = useState<ProjectFilters>("WIP"); | ||
|
||
const onFilterChange = (newFilter: string) => | ||
isValidProjectFilter(newFilter) && setFilter(newFilter); | ||
|
||
useEffect(() => { | ||
if (!projects) return setFilteredProjects([]); | ||
setFilteredProjects( | ||
filterAndSortProjects({ | ||
projects, | ||
accountId, | ||
projectFilter: filter, | ||
accounts, | ||
searchText, | ||
}) | ||
); | ||
}, [accountId, accounts, filter, projects, searchText]); | ||
|
||
return ( | ||
<ProjectFilter.Provider | ||
value={{ | ||
isSearchActive, | ||
setProjectFilter: onFilterChange, | ||
projectFilter: filter, | ||
projects: filteredProjects, | ||
loadingProjects, | ||
errorProjects, | ||
}} | ||
> | ||
{children} | ||
</ProjectFilter.Provider> | ||
); | ||
}; | ||
|
||
export function withProjectFilter<Props extends object>( | ||
Component: ComponentType<Props> | ||
) { | ||
return function WrappedProvider(componentProps: Props) { | ||
return ( | ||
<SearchProvider> | ||
<ProjectFilterProvider> | ||
<Component {...componentProps} /> | ||
</ProjectFilterProvider> | ||
; | ||
</SearchProvider> | ||
); | ||
}; | ||
} |
Oops, something went wrong.