Skip to content

Commit

Permalink
Couple of type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Studio384 committed Feb 18, 2024
1 parent dbfbaf3 commit 0aabc8b
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions docs/src/app/Icons.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react';
import { useLocation, useSearchParams } from 'react-router-dom';
import { useSearchParams } from 'react-router-dom';

import {
Box,
Expand Down Expand Up @@ -29,18 +29,15 @@ import IconCard from './Components/IconCard';
import Pagination from './Components/Pagination';

export default function Icons() {
const location = useLocation();

const [searchParams, setSearchParams] = useSearchParams();

const [searchCategories, searchQuery, searchPage]: [string[], string, number] = useMemo(() => {
const params = new URLSearchParams(location.search);
const categories = params.get('category');
const query = params.get('search');
const page = Number(params.get('page') ?? 1);
const categories = searchParams.get('category');
const query = searchParams.get('search');
const page = Number(searchParams.get('page') ?? 1);

return [categories?.split(',').filter((item) => item !== '') ?? [], query ?? '', page ?? 1];
}, [location.search]);
}, [searchParams]);

const searchableList = useMemo(() => {
if (searchCategories.length >= 1) {
Expand All @@ -55,9 +52,9 @@ export default function Icons() {
// c: categories
// q: query
// p: page
function setSearchQuery(type: 'q' | 'c' | 'p', value: string) {
function setSearchQuery(type: 'q' | 'c' | 'p', value: string | number) {
let search = searchParams.get('search');
let page = searchParams.get('page');
let page = Number(searchParams.get('page'));
let category =
searchParams
.get('category')
Expand All @@ -66,6 +63,8 @@ export default function Icons() {

switch (type) {
case 'c': {
if (typeof(value) === 'number') return;

if (category.includes(value)) {
category = category.filter((item) => item !== value);
} else {
Expand All @@ -74,10 +73,14 @@ export default function Icons() {
break;
}
case 'q': {
if (typeof(value) === 'number') return;

search = value;
break;
}
case 'p': {
if (typeof(value) === 'string') return;

page = value;
break;
}
Expand Down

0 comments on commit 0aabc8b

Please sign in to comment.