Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,28 @@ import { useQuery } from '@tanstack/react-query';
import axios from 'axios';
import { useSelector } from 'react-redux';
import styles from './EnhancedPopularityTimelineChart.module.css';
import { ENDPOINTS } from '../../utils/URL';

/**
* Enhanced Popularity Timeline Chart Component
*/

// --- Data Fetching Functions ---
const fetchEnhancedPopularityData = async ({ range, roles = [], includeLowVolume }) => {
const params = {
groupByRole: 'true',
includeLowVolume: includeLowVolume.toString(),
};

if (roles.length > 0 && !roles.includes('All Roles')) {
params.roles = roles.join(',');
}

if (range && range !== 'all') {
params.range = range;
}
const url = ENDPOINTS.ENHANCED_POPULARITY(
range,
roles,
null, // start (optional)
null, // end (optional)
includeLowVolume,
);

const { data } = await axios.get('http://localhost:4500/api/popularity-enhanced/timeline', {
params,
});
const { data } = await axios.get(url);
return data;
};

const fetchEnhancedRoles = async () => {
const { data } = await axios.get('http://localhost:4500/api/popularity-enhanced/roles-enhanced');
const { data } = await axios.get(ENDPOINTS.ENHANCED_POPULARITY_ROLES);
return data;
};

Expand Down
6 changes: 3 additions & 3 deletions src/utils/URL.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const ENDPOINTS = {
POPULARITY_ROLES: `${APIEndpoint}/popularity/roles`,

ENHANCED_POPULARITY: (range, roles, start, end, includeLowVolume) => {
let url = `${APIEndpoint}/api/popularity-enhanced/timeline?`;
let url = `${APIEndpoint}/popularity-enhanced/timeline?`;
if (range) url += `range=${range}&`;
if (roles && roles.length > 0) {
url += `roles=${encodeURIComponent(roles.join(','))}&`;
Expand All @@ -181,9 +181,9 @@ ENHANCED_POPULARITY: (range, roles, start, end, includeLowVolume) => {
if (includeLowVolume !== undefined) url += `includeLowVolume=${includeLowVolume}&`;
return url.slice(0, -1);
},
ENHANCED_POPULARITY_ROLES: `${APIEndpoint}/api/popularity-enhanced/roles-enhanced`,
ENHANCED_POPULARITY_ROLES: `${APIEndpoint}/popularity-enhanced/roles-enhanced`,
ENHANCED_POPULARITY_PAIRS: (roles) =>
`${APIEndpoint}/api/popularity-enhanced/role-pairs?roles=${encodeURIComponent(roles.join(','))}`,
`${APIEndpoint}/popularity-enhanced/role-pairs?roles=${encodeURIComponent(roles.join(','))}`,

// titles endpoints
TITLES: () => `${APIEndpoint}/title`,
Expand Down
Loading