-
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 #345 from Alt-Org/kaisa/enhancement/327-replace-ga…
…llery-dropdown-with-a-sidebar Kaisa/enhancement/327 replace gallery dropdown with a sidebar
- Loading branch information
Showing
6 changed files
with
184 additions
and
5 deletions.
There are no files selected for viewing
15 changes: 12 additions & 3 deletions
15
frontend-next-migration/src/app/[lng]/(helper)/picture-galleries/layout.tsx
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
1 change: 1 addition & 0 deletions
1
frontend-next-migration/src/features/NavigateGalleries/index.ts
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 +1,2 @@ | ||
export { default as GalleryNavMenuAsDropdown } from './ui/GalleryNavMenuAsDropdown'; | ||
export { default as GalleryNavMenuAsSidebar } from './ui/GalleryNavMenuAsSidebar'; |
134 changes: 134 additions & 0 deletions
134
frontend-next-migration/src/features/NavigateGalleries/ui/GalleryNavMenuAsSidebar.tsx
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,134 @@ | ||
import { useParams, useRouter } from 'next/navigation'; | ||
import { getRouteGalleryCategoryPage } from '@/shared/appLinks/RoutePaths'; | ||
import { | ||
getLanguageCode, | ||
useGetDirectusGalleryImages, | ||
getCategoryTranslation, | ||
Category, | ||
} from '@/entities/Gallery'; | ||
import { useEffect, useState } from 'react'; | ||
import { useClientTranslation } from '@/shared/i18n'; | ||
import cls from './GalleyNavMenuAsSidebar.module.scss'; | ||
|
||
export interface SidebarProps { | ||
sidebarVisible: boolean; | ||
setSidebarVisible: (visible: boolean) => void; | ||
} | ||
|
||
const GalleryNavMenuAsSidebar = (props: SidebarProps) => { | ||
const params = useParams(); | ||
const router = useRouter(); | ||
const lng = params.lng as string; | ||
const currentCategory = params.category as string; | ||
const language = getLanguageCode(lng); | ||
const { categories } = useGetDirectusGalleryImages(language); | ||
const allCategory = lng === 'en' ? 'all' : 'kaikki'; | ||
const [selectedCategory, setSelectedCategory] = useState(currentCategory || allCategory); | ||
const { t } = useClientTranslation('picture-galleries'); | ||
const { sidebarVisible, setSidebarVisible } = props; | ||
|
||
useEffect(() => { | ||
const category = findCorrectCategory(categories); | ||
|
||
if (!category) { | ||
setSelectedCategory(allCategory); | ||
} else { | ||
setSelectedCategory(currentCategory); | ||
} | ||
}, [categories, currentCategory]); | ||
|
||
useEffect(() => { | ||
const category = findCorrectCategory(categories); | ||
|
||
if (category) { | ||
const translatedName = getCategoryTranslation(category.translations, language); | ||
|
||
if (translatedName && translatedName !== currentCategory) { | ||
handleRouteChange(translatedName); | ||
} | ||
} else { | ||
setSelectedCategory(allCategory); | ||
} | ||
}, [categories, lng]); | ||
|
||
const findCorrectCategory = (categories: Category[]) => { | ||
if (!categories) return null; | ||
const category = categories.find((cat) => | ||
cat.translations.some((t) => t.name === currentCategory), | ||
); | ||
return category ? category : null; | ||
}; | ||
|
||
const handleRouteChange = (category: string) => { | ||
const newPath = getRouteGalleryCategoryPage(category); | ||
router.replace(newPath); | ||
setSelectedCategory(category); | ||
}; | ||
|
||
const getCategory = (category: Category, index: number) => { | ||
const translatedCategory = getCategoryTranslation(category.translations, language); | ||
|
||
if (sidebarVisible) { | ||
return ( | ||
<div | ||
key={index} | ||
onClick={() => handleRouteChange(translatedCategory)} | ||
className={cls.Category} | ||
style={ | ||
selectedCategory === translatedCategory | ||
? { color: 'var(--secondary-color)' } | ||
: {} | ||
} | ||
> | ||
{translatedCategory.charAt(0).toUpperCase() + | ||
translatedCategory.slice(1).replace('-', ' ')} | ||
</div> | ||
); | ||
} else { | ||
return ( | ||
<div | ||
key={index} | ||
className={cls.Category} | ||
style={ | ||
selectedCategory === translatedCategory | ||
? { color: 'var(--secondary-color)' } | ||
: {} | ||
} | ||
> | ||
{translatedCategory.charAt(0).toUpperCase() + | ||
translatedCategory.slice(1).replace('-', ' ')} | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
const getList = ( | ||
<div className={cls.Text}> | ||
<h2>{t('category-menu-title')}</h2> | ||
|
||
<div | ||
className={cls.Category} | ||
onClick={() => handleRouteChange(allCategory)} | ||
style={selectedCategory === allCategory ? { color: 'var(--secondary-color)' } : {}} | ||
> | ||
{allCategory.charAt(0).toUpperCase() + allCategory.slice(1)} | ||
</div> | ||
|
||
{categories.map((cat, index) => getCategory(cat, index))} | ||
</div> | ||
); | ||
|
||
return ( | ||
<div className={cls.Box}> | ||
<div | ||
className={cls.Arrow} | ||
onClick={() => setSidebarVisible(!sidebarVisible)} | ||
> | ||
{sidebarVisible ? '<' : '>'} | ||
</div> | ||
{getList} | ||
</div> | ||
); | ||
}; | ||
|
||
export default GalleryNavMenuAsSidebar; |
33 changes: 33 additions & 0 deletions
33
frontend-next-migration/src/features/NavigateGalleries/ui/GalleyNavMenuAsSidebar.module.scss
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,33 @@ | ||
.Arrow { | ||
display: inline-block; | ||
position: absolute; | ||
top: 45%; | ||
color: var(--secondary-color); | ||
font-weight :bolder; | ||
font-size:1.5em; | ||
right: .3em; | ||
cursor: pointer; | ||
} | ||
|
||
.Box { | ||
width: 100%; | ||
position: relative; | ||
background: black; | ||
border-radius: 10px; | ||
} | ||
|
||
.Category { | ||
padding-left: 0.5em; | ||
width: fit-content; | ||
cursor: pointer; | ||
} | ||
|
||
.Text { | ||
padding: 1em; | ||
font-size: 26px; | ||
|
||
h2 { | ||
margin-bottom: 10px; | ||
text-align: center; | ||
} | ||
} |
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