-
-
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.
Project list page use shared components
- Loading branch information
Showing
11 changed files
with
219 additions
and
193 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
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,71 @@ | ||
import styles from '../styles/components/tabs.module.css'; | ||
import { PluginType, PluginTypes, ProjectType, ProjectTypes } from '@studiorack/core'; | ||
import { useRouter } from 'next/router'; | ||
import { ChangeEvent } from 'react'; | ||
|
||
type TabsProps = { | ||
items: PluginTypes | ProjectTypes; | ||
}; | ||
|
||
type TabsItem = PluginType | ProjectType; | ||
type TabsKey = keyof PluginTypes & keyof ProjectTypes; | ||
|
||
const Tabs = ({ items }: TabsProps) => { | ||
const router = useRouter(); | ||
let category: string = (router.query['category'] as string) || 'all'; | ||
const search: string = (router.query['search'] as string) || ''; | ||
|
||
const isSelected = (path: string) => { | ||
return category === path ? 'selected' : ''; | ||
}; | ||
|
||
const onSearch = (event: ChangeEvent) => { | ||
const el: HTMLInputElement = event.target as HTMLInputElement; | ||
router.query['search'] = el.value ? el.value.toLowerCase() : ''; | ||
router.push({ | ||
pathname: router.pathname, | ||
query: router.query, | ||
}); | ||
}; | ||
|
||
const selectCategory = (event: any) => { | ||
category = (event.target as HTMLTextAreaElement).getAttribute('data-category') || ''; | ||
router.query['category'] = category || ''; | ||
router.push({ | ||
pathname: router.pathname, | ||
query: router.query, | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className={styles.tabs}> | ||
<ul className={styles.tabsCategory}> | ||
<li> | ||
<a data-category="all" onClick={selectCategory} className={isSelected('all')}> | ||
All | ||
</a> | ||
</li> | ||
{Object.keys(items).map((key: string, index: number) => ( | ||
<li key={`${key}-${index}`}> | ||
<a data-category={key} onClick={selectCategory} className={isSelected(key)}> | ||
{(items[key as TabsKey] as TabsItem).name} | ||
</a> | ||
</li> | ||
))} | ||
<li> | ||
<input | ||
className={styles.tabsSearch} | ||
placeholder="Keyword" | ||
type="search" | ||
id="search" | ||
name="search" | ||
value={search} | ||
onChange={onSearch} | ||
/> | ||
</li> | ||
</ul> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Tabs; |
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,19 @@ | ||
import { ProjectTypes, ProjectVersionLocal } from '@studiorack/core'; | ||
import { ProjectTypes, ProjectVersion } from '@studiorack/core'; | ||
import { NextRouter } from 'next/router'; | ||
|
||
export function filterProjects( | ||
category: string, | ||
projects: ProjectVersionLocal[], | ||
projectTypes: ProjectTypes, | ||
query: string, | ||
): ProjectVersionLocal[] { | ||
console.log('filterProjects', category, projectTypes, query); | ||
return projects.filter((project: ProjectVersionLocal) => { | ||
export function filterProjects(projectTypes: ProjectTypes, projects: ProjectVersion[], router: NextRouter) { | ||
const category: string = (router.query['category'] as string) || 'all'; | ||
const search: string = router.query['search'] as string; | ||
return projects.filter((project: ProjectVersion) => { | ||
if (category !== 'all' && project.type?.ext !== projectTypes[category as keyof ProjectTypes]?.ext) return false; | ||
if ( | ||
(category === 'all' || project.type?.ext === projectTypes[category as keyof ProjectTypes]?.ext) && | ||
(project.author.toLowerCase().indexOf(query) !== -1 || | ||
project.id?.toLowerCase().indexOf(query) !== -1 || | ||
project.name.toLowerCase().indexOf(query) !== -1 || | ||
project.description.toLowerCase().indexOf(query) !== -1 || | ||
project.tags.includes(query)) | ||
) { | ||
return project; | ||
} | ||
return false; | ||
search && | ||
project.id?.toLowerCase().indexOf(search.toLowerCase()) === -1 && | ||
project.name?.toLowerCase().indexOf(search.toLowerCase()) === -1 && | ||
project.description?.toLowerCase().indexOf(search.toLowerCase()) === -1 && | ||
project.tags?.indexOf(search.toLowerCase()) === -1 | ||
) | ||
return false; | ||
return project; | ||
}); | ||
} |
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
Oops, something went wrong.