Added empty ann list message on stories preview

Converted to use css module
This commit is contained in:
Dmitriy Shishkov 2023-08-12 01:33:38 +03:00
parent b12f19ac51
commit a4a6f620fb
Signed by: dm1sh
GPG Key ID: 027994B0AA357688
2 changed files with 95 additions and 80 deletions

View File

@ -1,5 +1,5 @@
import { Link } from 'react-router-dom'
import { CSSProperties, useEffect, useMemo, useRef, useState } from 'react'
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import { Button } from 'react-bootstrap'
import { UserCategory, composeUserCategoriesFilters, userCategoriesInfos } from '../assets/userCategories'
@ -9,64 +9,37 @@ import { URLEncodeFilters } from '../utils/filters'
import rightAngleIcon from '../assets/rightAngle.svg'
import styles from '../styles/StoriesPreview.module.css'
type StoriesPreviewProps = {
announcements: Announcement[],
category: UserCategory,
}
const styles = {
container: {
transform: 'translateX(0)',
} as CSSProperties,
ul: {
display: 'flex',
gap: 10,
listStyleType: 'none',
overflow: 'scroll',
paddingLeft: 0,
scrollBehavior: 'smooth',
} as CSSProperties,
link: {
textDecoration: 'none',
color: 'var(--bs-body-color)',
maxWidth: 'calc(25vh * 9 / 16)',
display: 'inline-block',
} as CSSProperties,
image: {
height: '25vh',
objectFit: 'contain',
borderRadius: 12,
marginBottom: 5,
maxWidth: 'inherit',
} as CSSProperties,
title: {
overflow: 'hidden',
textOverflow: 'ellipsis',
marginBottom: 5,
} as CSSProperties,
scrollButton: {
position: 'fixed',
right: 0,
top: 0,
zIndex: 100,
background: 'linear-gradient(to right, rgba(17, 17, 17, 0) 0%, rgba(17, 17, 17, 255) 100%)',
display: 'block',
height: '100%',
width: '10%',
border: 'none',
cursor: 'default',
borderRadius: 0,
} as CSSProperties,
leftScrollButton: {
left: 0,
transform: 'scaleX(-1)',
} as CSSProperties,
rightScrollButton: {
right: 0,
} as CSSProperties,
}
const StoriesPreview = ({ announcements, category }: StoriesPreviewProps) => (
announcements.map((ann, i) => (
<li key={`${category}${i}`}>
<Link to={'/?' + new URLSearchParams({
...URLEncodeFilters(composeUserCategoriesFilters[category]()),
storyIndex: i.toString(),
}).toString()} className={styles.link}>
{ann.src?.endsWith('mp4') ? (
<video src={ann.src} className={styles.image} />
) : (
<img
src={ann.src || categoryGraphics[ann.category]}
alt={'Изображение' + (ann.src ? 'предмета' : categoryNames[ann.category])}
className={styles.image}
/>
)}
<p className={styles.title}>{ann.name}</p>
<p className={styles.title}>{userCategoriesInfos[category](ann)}</p>
</Link>
</li>
))
)
function StoriesPreview({ announcements, category }: StoriesPreviewProps) {
function StoriesPreviewCarousel({ announcements, category }: StoriesPreviewProps) {
const ulElement = useRef<HTMLUListElement | null>(null)
const [showScrollButtons, setShowScrollButtons] = useState({ left: false, right: false })
@ -90,7 +63,7 @@ function StoriesPreview({ announcements, category }: StoriesPreviewProps) {
}
}, [])
useEffect(() => {
useLayoutEffect(() => {
const ul = ulElement.current
if (ul) {
@ -106,40 +79,26 @@ function StoriesPreview({ announcements, category }: StoriesPreviewProps) {
}
}
return <div style={styles.container}>
return <div className={styles.container}>
{showScrollButtons.left &&
<Button onClick={doScroll(false)} style={{ ...styles.scrollButton, ...styles.leftScrollButton }}>
<Button onClick={doScroll(false)} className={`${styles.scrollButton} ${styles.leftScrollButton}`}>
<img src={rightAngleIcon} alt='Показать ещё' />
</Button>
}
<ul style={styles.ul} className='StoriesPreview_ul' ref={ulElement}>
{useMemo(() => announcements.map((ann, i) => (
<li key={`${category}${i}`}>
<Link to={'/?' + new URLSearchParams({
...URLEncodeFilters(composeUserCategoriesFilters[category]()),
storyIndex: i.toString(),
}).toString()} style={styles.link}>
{ann.src?.endsWith('mp4') ? (
<video src={ann.src} style={styles.image} />
) : (
<img
src={ann.src || categoryGraphics[ann.category]}
alt={'Изображение' + (ann.src ? 'предмета' : categoryNames[ann.category])}
style={styles.image}
/>
)}
<p style={styles.title}>{ann.name}</p>
<p style={styles.title}>{userCategoriesInfos[category](ann)}</p>
</Link>
</li>
)), [announcements, category])}
</ul>
{announcements.length > 0 ? (
<ul className={styles.list} ref={ulElement}>
<StoriesPreview announcements={announcements} category={category} />
</ul>
) : (
<p>Здесь пока пусто</p>
)}
{showScrollButtons.right &&
<Button onClick={doScroll(true)} style={{ ...styles.scrollButton, ...styles.rightScrollButton }}>
<Button onClick={doScroll(true)} className={`${styles.scrollButton} ${styles.rightScrollButton}`}>
<img src={rightAngleIcon} alt='Показать ещё' />
</Button>
}
</div>
}
export default StoriesPreview
export default StoriesPreviewCarousel

View File

@ -0,0 +1,56 @@
.container {
transform: translateX(0);
}
.list {
display: flex;
gap: 10px;
list-style-type: none;
overflow: scroll;
padding-left: 0;
scroll-behavior: smooth;
}
.link {
text-decoration: none;
color: var(--bs-body-color);
max-width: calc(25vh * 9 / 16);
display: inline-block;
}
.image {
height: 25vh;
object-fit: contain;
border-radius: 12px;
margin-bottom: 5px;
max-width: inherit;
}
.title {
overflow: hidden;
text-overflow: ellipsis;
margin-bottom: 5px;
}
.scrollButton {
position: fixed;
right: 0;
top: 0;
z-index: 100;
background: linear-gradient(to right, rgba(17, 17, 17, 0) 0%, rgba(17, 17, 17, 255) 100%);
display: block;
height: 100%;
width: 10%;
border: none;
cursor: default;
border-radius: 0;
}
.leftScrollButton {
left: 0;
transform: scaleX(-1);
}
.rightScrollButton {
right: 0;
}