webapp/src/components/Feed/Row2.tsx

73 lines
2.0 KiB
TypeScript
Raw Normal View History

2022-09-09 11:53:35 +00:00
import type { Shout } from '../../graphql/types.gen'
import { createComputed, createSignal, Show, For } from 'solid-js'
2023-05-01 18:32:32 +00:00
import { ArticleCard } from './ArticleCard'
import { ArticleCardProps } from './ArticleCard/ArticleCard'
2022-09-09 11:53:35 +00:00
const x = [
2023-03-10 17:42:48 +00:00
['12', '12'],
['8', '16'],
['16', '8'],
2022-09-09 11:53:35 +00:00
]
export const Row2 = (props: {
articles: Shout[]
isEqual?: boolean
nodate?: boolean
noAuthorLink?: boolean
noauthor?: boolean
}) => {
2022-09-09 11:53:35 +00:00
const [y, setY] = createSignal(0)
// FIXME: random can break hydration
2022-09-09 11:53:35 +00:00
createComputed(() => setY(Math.floor(Math.random() * x.length)))
return (
2023-08-12 10:36:21 +00:00
<Show when={props.articles && props.articles.length > 0}>
<div class="floor">
<div class="wide-container">
<div class="row">
<For each={props.articles}>
{(a, i) => {
// FIXME: refactor this, too ugly now
const className = `col-md-${props.isEqual ? '12' : x[y()][i()]}`
let desktopCoverSize: ArticleCardProps['desktopCoverSize']
switch (className) {
case 'col-md-8': {
desktopCoverSize = 'S'
break
}
case 'col-md-12': {
desktopCoverSize = 'M'
break
}
default: {
desktopCoverSize = 'L'
}
}
2023-08-12 10:36:21 +00:00
return (
<div class={className}>
<ArticleCard
article={a}
settings={{
isWithCover: props.isEqual || x[y()][i()] === '16',
nodate: props.isEqual || props.nodate,
noAuthorLink: props.noAuthorLink,
noauthor: props.noauthor,
}}
desktopCoverSize={desktopCoverSize}
/>
</div>
2023-08-12 10:36:21 +00:00
)
}}
</For>
</div>
2022-11-20 21:23:12 +00:00
</div>
2022-09-09 11:53:35 +00:00
</div>
2023-08-12 10:36:21 +00:00
</Show>
2022-09-09 11:53:35 +00:00
)
}