Skip to content

Commit

Permalink
feat: sort categories by alphabetical order
Browse files Browse the repository at this point in the history
* Update main.lua

Make the Categories show up alphabetical

* Update client/main.lua

* Update main.lua

* sort categories

---------

Co-authored-by: Antony <[email protected]>
  • Loading branch information
Nukulargamer and TonybynMp4 authored Apr 10, 2024
1 parent 1ccd616 commit 1d9fa8e
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ local function openVehCatsMenu(category, targetVehicle)
end
end

table.sort(vehMenu, function(a, b)
local _, aName = string.strsplit(' ', string.upper(a.title), 2)
local _, bName = string.strsplit(' ', string.upper(b.title), 2)
return aName < bName
end)

lib.registerContext({
id = 'openVehCats',
title = config.shops[insideShop].categories[category],
Expand All @@ -230,12 +236,26 @@ end
---@param args table<string, any>
local function openVehicleCategoryMenu(args)
local categoryMenu = {}
for k, v in pairs(config.shops[insideShop].categories) do
local sortedCategories = {}
local categories = config.shops[insideShop].categories

for k, v in pairs(categories) do
sortedCategories[#sortedCategories + 1] = {
category = k,
label = v
}
end

table.sort(sortedCategories, function(a, b)
return string.upper(a.label) < string.upper(b.label)
end)

for i = 1, #sortedCategories do
categoryMenu[#categoryMenu + 1] = {
title = v,
title = sortedCategories[i].label,
arrow = true,
onSelect = function()
openVehCatsMenu(k, args.targetVehicle)
openVehCatsMenu(sortedCategories[i].category, args.targetVehicle)
end
}
end
Expand Down

0 comments on commit 1d9fa8e

Please sign in to comment.