Fixed userPage story preview link to use actual filter

Related to #27
This commit is contained in:
Dmitriy Shishkov 2023-07-20 13:25:16 +03:00
parent 58d1996ce3
commit 96388a9bea
Signed by: dm1sh
GPG Key ID: 027994B0AA357688
2 changed files with 11 additions and 5 deletions

View File

@ -1,12 +1,13 @@
import { Link } from 'react-router-dom'
import { CSSProperties, useEffect, useMemo, useRef, useState } from 'react'
import { Button } from 'react-bootstrap'
import { UserCategory, userCategoriesInfos } from '../assets/userCategories'
import { UserCategory, composeUserCategoriesFilters, userCategoriesInfos } from '../assets/userCategories'
import { Announcement } from '../api/announcement/types'
import { categoryGraphics, categoryNames } from '../assets/category'
import { URLEncodeFilters } from '../utils/filters'
import rightAngleIcon from '../assets/rightAngle.svg'
import { Button } from 'react-bootstrap'
type StoriesPreviewProps = {
announcements: Announcement[],
@ -113,8 +114,7 @@ function StoriesPreview({ announcements, category }: StoriesPreviewProps) {
{useMemo(() => announcements.map((ann, i) => (
<li key={`${category}${i}`}>
<Link to={'/?' + new URLSearchParams({
userId: Number(-1).toString(),
userCat: category,
...URLEncodeFilters(composeUserCategoriesFilters[category]()),
storyIndex: i.toString()
}).toString()} style={styles.link}>
{ann.src?.endsWith('mp4') ? (

View File

@ -10,7 +10,13 @@ const defaultFilters: FiltersType = { userId: undefined, category: undefined, me
const URLEncodeFilters = (filters: FiltersType) => (
Object.fromEntries(
filterNames.map(
fName => [fName, filters[fName]?.toString()]
fName => {
const v = filters[fName]
if (v) {
return [fName, encodeURIComponent(v)]
}
return [fName, undefined]
}
).filter((p): p is [string, string] => typeof p[1] !== 'undefined')
)
)