shuffle-topic-fix-2

This commit is contained in:
Untone 2024-05-06 13:50:15 +03:00
parent 28022607e3
commit 3f8d495076
2 changed files with 1 additions and 2 deletions

View File

@ -69,7 +69,7 @@ export const Header = (props: Props) => {
let windowScrollTop = 0 let windowScrollTop = 0
createEffect(() => { createEffect(() => {
setRandomTopics(getRandomTopicsFromArray(topics())) if (topics()) setRandomTopics(getRandomTopicsFromArray(topics()))
}) })
createEffect(() => { createEffect(() => {

View File

@ -2,7 +2,6 @@ import { RANDOM_TOPICS_COUNT } from '../components/Views/Home'
import { Topic } from '../graphql/schema/core.gen' import { Topic } from '../graphql/schema/core.gen'
export const getRandomTopicsFromArray = (topics: Topic[], count: number = RANDOM_TOPICS_COUNT): Topic[] => { export const getRandomTopicsFromArray = (topics: Topic[], count: number = RANDOM_TOPICS_COUNT): Topic[] => {
if (!topics) return []
const shuffledTopics = [...topics].sort(() => 0.5 - Math.random()) const shuffledTopics = [...topics].sort(() => 0.5 - Math.random())
return shuffledTopics.slice(0, count) return shuffledTopics.slice(0, count)
} }