Skip to content

Commit

Permalink
Apply commodity filters to exports, and to nearby importers and expor…
Browse files Browse the repository at this point in the history
…ters
  • Loading branch information
iaincollins committed Sep 7, 2024
1 parent 6d6dc81 commit 576e54e
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 12 deletions.
1 change: 1 addition & 0 deletions components/commodity-export-orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 3 additions & 2 deletions components/commodity-import-orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
26 changes: 24 additions & 2 deletions components/nearby-commodity-exporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
26 changes: 24 additions & 2 deletions components/nearby-commodity-importers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
4 changes: 2 additions & 2 deletions components/tab-options/commodities.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export default ({ onChange }) => {
}}>
<option value='1'>No minimum</option>
<option value='100'>100 T</option>
<option value='1000'>1000 T</option>
<option value='10000'>10000 T</option>
<option value='1000'>1,000 T</option>
<option value='10000'>10,000 T</option>
</select>
</label>
</form>
Expand Down
4 changes: 2 additions & 2 deletions lib/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ardent-www",
"version": "0.42.0",
"version": "0.43.0",
"description": "Ardent Industry",
"main": "index.js",
"scripts": {
Expand Down
18 changes: 17 additions & 1 deletion pages/commodity/[commodity-name]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit 576e54e

Please sign in to comment.