now category filter is working properly
This commit is contained in:
parent
3e6d700063
commit
4e789ddce1
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
|
||||
import { XVideosCategories } from '@/meta/settings';
|
||||
import { Cookies, XVideosCategories } from '@/meta/settings';
|
||||
|
||||
import css from './Category.module.scss'
|
||||
|
||||
|
@ -19,12 +19,12 @@ const Category: React.FC<Props> = (props) => {
|
|||
|
||||
const { labels } = props
|
||||
|
||||
const [cookies] = useCookies(['category']);
|
||||
const [cookies] = useCookies([Cookies.category]);
|
||||
|
||||
const handleChange = async (event: React.ChangeEvent<HTMLSelectElement>) => {
|
||||
const value = event.target.value;
|
||||
|
||||
await setCookie('category', value)
|
||||
await setCookie(Cookies.category, value)
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
|
||||
import { Platforms } from '@/meta/settings';
|
||||
import { Cookies, Platforms } from '@/meta/settings';
|
||||
|
||||
import css from './Platform.module.scss'
|
||||
|
||||
|
@ -19,12 +19,12 @@ const Platform: React.FC<Props> = (props) => {
|
|||
|
||||
const { labels } = props
|
||||
|
||||
const [cookies] = useCookies(['platform']);
|
||||
const [cookies] = useCookies([Cookies.platform]);
|
||||
|
||||
const handleChange = async (event: React.ChangeEvent<HTMLSelectElement>) => {
|
||||
const value = event.target.value;
|
||||
|
||||
await setCookie('platform', value)
|
||||
await setCookie(Cookies.platform, value)
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import React from 'react';
|
||||
|
||||
import { TbMoon, TbSun } from 'react-icons/tb';
|
||||
import { DEFAULT_THEME, Themes } from '@/meta/settings';
|
||||
import { Cookies, DEFAULT_THEME, Themes } from '@/meta/settings';
|
||||
|
||||
import Icon from '../Icon';
|
||||
import { setCookie } from '@/utils/cookies/write';
|
||||
|
@ -11,13 +11,13 @@ import { useCookies } from 'react-cookie';
|
|||
|
||||
const Theme: React.FC = () => {
|
||||
|
||||
const [cookies] = useCookies(['theme']);
|
||||
const [cookies] = useCookies([Cookies.theme]);
|
||||
|
||||
const theme = cookies.theme ?? DEFAULT_THEME
|
||||
|
||||
const handleClick = async () => {
|
||||
const newTheme = theme == Themes.dark ? Themes.light : Themes.dark
|
||||
await setCookie('theme', newTheme)
|
||||
await setCookie(Cookies.theme, newTheme)
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export const XVIDEOS_BASE_URL: string = "https://www.xvideos.com"
|
||||
export const XVIDEOS_BASE_URL: string = "https://www.xvideos.com"
|
||||
export const XVIDEOS_BASE_URL_GAY: string = "https://www.xvideos.com/gay"
|
||||
export const XVIDEOS_BASE_URL_TRANS: string = "https://www.xvideos.com/shemale"
|
|
@ -1,8 +1,20 @@
|
|||
export enum Cookies {
|
||||
theme= 'theme',
|
||||
category= 'category',
|
||||
platform= 'platform'
|
||||
}
|
||||
|
||||
export enum Platforms {
|
||||
xvideos= 'xvideos',
|
||||
xnxx= 'xnxx'
|
||||
}
|
||||
|
||||
export enum XVideosCatQueryMap {
|
||||
etero= 'straight',
|
||||
gay= 'gay',
|
||||
trans= 'shemale'
|
||||
}
|
||||
|
||||
export enum XVideosCategories {
|
||||
etero= 'etero',
|
||||
gay= 'gay',
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { XVIDEOS_BASE_URL } from '@/constants/urls';
|
||||
import { GalleryData } from '@/meta/data';
|
||||
import axios, { AxiosError } from 'axios';
|
||||
|
||||
import * as cheerio from "cheerio";
|
||||
import { getHeaders } from '../headers';
|
||||
import { getXVideosQueryUrl } from './url';
|
||||
|
||||
interface FetchParams {
|
||||
baseUrl?: string
|
||||
|
@ -16,7 +16,7 @@ export const fetchGalleryData = async (params?: FetchParams): Promise<GalleryDat
|
|||
|
||||
const reqHeaders = getHeaders()
|
||||
|
||||
const queryUrl = `${(params && params.baseUrl) ?? XVIDEOS_BASE_URL}${params && params.query ? '/?k=' + params.query : ''}`
|
||||
const queryUrl = await getXVideosQueryUrl(params?.query)
|
||||
|
||||
await axios.get(queryUrl, reqHeaders)
|
||||
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
import { XVIDEOS_BASE_URL, XVIDEOS_BASE_URL_GAY, XVIDEOS_BASE_URL_TRANS } from '@/constants/urls';
|
||||
import { Cookies, XVideosCatQueryMap, XVideosCategories } from '@/meta/settings';
|
||||
import { getCookie } from '@/utils/cookies/read';
|
||||
|
||||
export const getXVideosQueryUrl = async (query?: string) => {
|
||||
|
||||
const category = await getCookie(Cookies.category)
|
||||
|
||||
if (!category && !query) {
|
||||
return XVIDEOS_BASE_URL
|
||||
}
|
||||
|
||||
if (!category && query) {
|
||||
return `${XVIDEOS_BASE_URL}/?k=${query}`
|
||||
}
|
||||
|
||||
if (category && !Object.values(XVideosCategories).includes(category.value as XVideosCategories)) {
|
||||
return XVIDEOS_BASE_URL
|
||||
}
|
||||
|
||||
if (category && !query) {
|
||||
switch (category.value) {
|
||||
case XVideosCategories.etero:
|
||||
return XVIDEOS_BASE_URL
|
||||
case XVideosCategories.gay:
|
||||
return XVIDEOS_BASE_URL_GAY
|
||||
case XVideosCategories.trans:
|
||||
return XVIDEOS_BASE_URL_TRANS
|
||||
default:
|
||||
return XVIDEOS_BASE_URL;
|
||||
}
|
||||
}
|
||||
|
||||
if (category && query) {
|
||||
return `${XVIDEOS_BASE_URL}/?k=${query}&typef=${XVideosCatQueryMap[category.value as XVideosCategories]}`
|
||||
}
|
||||
|
||||
return XVIDEOS_BASE_URL
|
||||
|
||||
}
|
Loading…
Reference in New Issue