diff --git a/components/commodity-export-orders.js b/components/commodity-export-orders.js index 454c1f5..f7f4508 100644 --- a/components/commodity-export-orders.js +++ b/components/commodity-export-orders.js @@ -13,6 +13,7 @@ import NearbyCommodityExporters from './nearby-commodity-exporters' async function getExportsForCommodityBySystem (systemName, commodityName) { const res = await fetch(`${API_BASE_URL}/v1/system/name/${systemName}/commodities/exports`) const exports = await res.json() + if (!exports || exports.error) return [] // Handle system not found return exports.filter(c => c.commodityName === commodityName) } diff --git a/components/commodity-import-orders.js b/components/commodity-import-orders.js index 74c8345..0c7d237 100644 --- a/components/commodity-import-orders.js +++ b/components/commodity-import-orders.js @@ -12,8 +12,9 @@ import NearbyCommodityExporters from './nearby-commodity-exporters' async function getImportsForCommodityBySystem (systemName, commodityName) { const res = await fetch(`${API_BASE_URL}/v1/system/name/${systemName}/commodities/imports`) - const exports = await res.json() - return exports.filter(c => c.commodityName === commodityName) + const imports = await res.json() + if (!imports || imports.error) return [] // Handle system not found + return imports.filter(c => c.commodityName === commodityName) } export default ({ commodities }) => { diff --git a/components/nearby-commodity-exporters.js b/components/nearby-commodity-exporters.js index 464eada..23fedf0 100644 --- a/components/nearby-commodity-exporters.js +++ b/components/nearby-commodity-exporters.js @@ -4,12 +4,34 @@ import Table from 'rc-table' import { timeBetweenTimestamps } from 'lib/utils/dates' import TradeBracketIcon from './trade-bracket' import StationIcon from './station-icon' -import { API_BASE_URL } from 'lib/consts' +import { + API_BASE_URL, + COMMODITY_FILTER_MAX_DAYS_AGO_DEFAULT, + COMMODITY_FILTER_FLEET_CARRIER_DEFAULT, + COMMODITY_FILTER_MIN_VOLUME_DEFAULT +} from 'lib/consts' + const MAX_ROWS_TO_DISPLAY = 10 async function getNearbyExportersOfCommodity (systemName, commodityName) { - const res = await fetch(`${API_BASE_URL}/v1/system/name/${systemName}/commodity/name/${commodityName}/nearby/exports`) + let url = `${API_BASE_URL}/v1/system/name/${systemName}/commodity/name/${commodityName}/nearby/exports` + let options = [] + + const lastUpdatedFilterValue = window.localStorage?.getItem('lastUpdatedFilter') ?? COMMODITY_FILTER_MAX_DAYS_AGO_DEFAULT + const minVolumeFilterValue = window.localStorage?.getItem('minVolumeFilter') ?? COMMODITY_FILTER_MIN_VOLUME_DEFAULT + const fleetCarrierFilterValue = window.localStorage?.getItem('fleetCarrierFilter') ?? COMMODITY_FILTER_FLEET_CARRIER_DEFAULT + + options.push(`maxDaysAgo=${lastUpdatedFilterValue}`) + options.push(`minVolume=${minVolumeFilterValue}`) + if (fleetCarrierFilterValue === 'excluded') options.push('fleetCarriers=false') + if (fleetCarrierFilterValue === 'only') options.push('fleetCarriers=true') + + if (options.length > 0) { + url += `?${options.join('&')}` + } + + const res = await fetch(url) return await res.json() } diff --git a/components/nearby-commodity-importers.js b/components/nearby-commodity-importers.js index bdf8fbc..39e8162 100644 --- a/components/nearby-commodity-importers.js +++ b/components/nearby-commodity-importers.js @@ -4,12 +4,34 @@ import Table from 'rc-table' import { timeBetweenTimestamps } from 'lib/utils/dates' import TradeBracketIcon from './trade-bracket' import StationIcon from './station-icon' -import { API_BASE_URL } from 'lib/consts' +import { + API_BASE_URL, + COMMODITY_FILTER_MAX_DAYS_AGO_DEFAULT, + COMMODITY_FILTER_FLEET_CARRIER_DEFAULT, + COMMODITY_FILTER_MIN_VOLUME_DEFAULT +} from 'lib/consts' + const MAX_ROWS_TO_DISPLAY = 10 async function getNearbyImportersOfCommodity (systemName, commodityName) { - const res = await fetch(`${API_BASE_URL}/v1/system/name/${systemName}/commodity/name/${commodityName}/nearby/imports`) + let url = `${API_BASE_URL}/v1/system/name/${systemName}/commodity/name/${commodityName}/nearby/imports` + let options = [] + + const lastUpdatedFilterValue = window.localStorage?.getItem('lastUpdatedFilter') ?? COMMODITY_FILTER_MAX_DAYS_AGO_DEFAULT + const minVolumeFilterValue = window.localStorage?.getItem('minVolumeFilter') ?? COMMODITY_FILTER_MIN_VOLUME_DEFAULT + const fleetCarrierFilterValue = window.localStorage?.getItem('fleetCarrierFilter') ?? COMMODITY_FILTER_FLEET_CARRIER_DEFAULT + + options.push(`maxDaysAgo=${lastUpdatedFilterValue}`) + options.push(`minVolume=${minVolumeFilterValue}`) + if (fleetCarrierFilterValue === 'excluded') options.push('fleetCarriers=false') + if (fleetCarrierFilterValue === 'only') options.push('fleetCarriers=true') + + if (options.length > 0) { + url += `?${options.join('&')}` + } + + const res = await fetch(url) return await res.json() } diff --git a/components/tab-options/commodities.js b/components/tab-options/commodities.js index a1ddf2d..a5110dc 100644 --- a/components/tab-options/commodities.js +++ b/components/tab-options/commodities.js @@ -62,8 +62,8 @@ export default ({ onChange }) => { }}> - - + + diff --git a/lib/consts.js b/lib/consts.js index 4ccc07a..c528412 100644 --- a/lib/consts.js +++ b/lib/consts.js @@ -8,8 +8,8 @@ const API_BASE_URL = process?.env?.NODE_ENV === 'development' const SOL_COORDINATES = [0, 0, 0] const COLONIA_COORDINATES = [-9530.5, -910.28125, 19808.125] -const COMMODITY_FILTER_MAX_DAYS_AGO_DEFAULT = '30' -const COMMODITY_FILTER_FLEET_CARRIER_DEFAULT = 'excluded' +const COMMODITY_FILTER_MAX_DAYS_AGO_DEFAULT = '7' +const COMMODITY_FILTER_FLEET_CARRIER_DEFAULT = 'included' const COMMODITY_FILTER_MIN_VOLUME_DEFAULT = 1000 module.exports = { diff --git a/package.json b/package.json index dfc863e..ddcd22c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ardent-www", - "version": "0.42.0", + "version": "0.43.0", "description": "Ardent Industry", "main": "index.js", "scripts": { diff --git a/pages/commodity/[commodity-name]/index.js b/pages/commodity/[commodity-name]/index.js index 3d83ddf..ba00e38 100644 --- a/pages/commodity/[commodity-name]/index.js +++ b/pages/commodity/[commodity-name]/index.js @@ -235,7 +235,23 @@ async function getCommodity (commodityName) { } async function getExports (commodityName) { - const res = await fetch(`${API_BASE_URL}/v1/commodity/name/${commodityName}/exports`) + let url = `${API_BASE_URL}/v1/commodity/name/${commodityName}/exports` + let options = [] + + const lastUpdatedFilterValue = window.localStorage?.getItem('lastUpdatedFilter') ?? COMMODITY_FILTER_MAX_DAYS_AGO_DEFAULT + const minVolumeFilterValue = window.localStorage?.getItem('minVolumeFilter') ?? COMMODITY_FILTER_MIN_VOLUME_DEFAULT + const fleetCarrierFilterValue = window.localStorage?.getItem('fleetCarrierFilter') ?? COMMODITY_FILTER_FLEET_CARRIER_DEFAULT + + options.push(`maxDaysAgo=${lastUpdatedFilterValue}`) + options.push(`minVolume=${minVolumeFilterValue}`) + if (fleetCarrierFilterValue === 'excluded') options.push('fleetCarriers=false') + if (fleetCarrierFilterValue === 'only') options.push('fleetCarriers=true') + + if (options.length > 0) { + url += `?${options.join('&')}` + } + + const res = await fetch(url) return await res.json() }