From 96388a9beaf06b7a8911ac0d79453390370498f7 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Thu, 20 Jul 2023 13:25:16 +0300 Subject: [PATCH] Fixed userPage story preview link to use actual filter Related to #27 --- front/src/components/StoriesPreview.tsx | 8 ++++---- front/src/utils/filters.ts | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/front/src/components/StoriesPreview.tsx b/front/src/components/StoriesPreview.tsx index 24b8ffe..8871be0 100644 --- a/front/src/components/StoriesPreview.tsx +++ b/front/src/components/StoriesPreview.tsx @@ -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) => (
  • {ann.src?.endsWith('mp4') ? ( diff --git a/front/src/utils/filters.ts b/front/src/utils/filters.ts index 30a821f..ca4b6f0 100644 --- a/front/src/utils/filters.ts +++ b/front/src/utils/filters.ts @@ -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') ) )