feat(ui): added ability to search countries on premium countries page by country code

This commit is contained in:
Mitternacht822
2026-02-19 21:28:15 +04:00
parent 1414f0ee84
commit d474d251bf
@@ -1,7 +1,6 @@
import QtQuick import QtQuick
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Layouts import QtQuick.Layouts
import QtQuick.Dialogs
import SortFilterProxyModel 0.2 import SortFilterProxyModel 0.2
@@ -114,15 +113,21 @@ PageType {
return result; return result;
} }
function isCountryMatchingSearch(countryName) { function isCountryMatchingSearch(countryName, regionCountryCode, sourceCountryCode) {
const normalizedSearchText = normalizeSearchComparableText(searchText); const normalizedSearchText = normalizeSearchComparableText(searchText);
if (normalizedSearchText === "") { if (normalizedSearchText === "") {
return true; return true;
} }
const normalizedCountryName = normalizeSearchComparableText(countryName); const normalizedCountryName = normalizeSearchComparableText(countryName);
const searchRegexp = new RegExp("^" + normalizedSearchText.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")); const normalizedRegionCountryCode = normalizeCountryCode(regionCountryCode).toLowerCase();
return searchRegexp.test(normalizedCountryName); const normalizedSourceCountryCode = normalizeCountryCode(sourceCountryCode).toLowerCase();
const nameMatch = normalizedCountryName.startsWith(normalizedSearchText);
const regionCodeMatch = normalizedRegionCountryCode.startsWith(normalizedSearchText);
const sourceCodeMatch = normalizedSourceCountryCode.startsWith(normalizedSearchText);
return nameMatch || regionCodeMatch || sourceCodeMatch;
} }
function getDisplayCountryName(countryName) { function getDisplayCountryName(countryName) {
@@ -149,12 +154,13 @@ PageType {
} }
const modelCode = normalizeCountryCode(country.countryCode); const modelCode = normalizeCountryCode(country.countryCode);
const modelIsoCode = extractCountryIsoCode(country.countryCode);
const modelName = normalizeCountryName(country.countryName); const modelName = normalizeCountryName(country.countryName);
if (expectedName !== "" && modelName === expectedName) { if (expectedName !== "" && modelName === expectedName) {
return i; return i;
} }
if (expectedCode !== "" && modelCode === expectedCode) { if (expectedCode !== "" && (modelCode === expectedCode || modelIsoCode === expectedCode)) {
return i; return i;
} }
} }
@@ -165,21 +171,31 @@ PageType {
function rebuildRegionModel() { function rebuildRegionModel() {
let regions = []; let regions = [];
for (let regionIndex = 0; regionIndex < regionDefinitions.length; ++regionIndex) { for (let regionNameIndex = 0; regionNameIndex < regionDefinitions.length; ++regionNameIndex) {
regions.push({ regions.push({
"regionName": regionDefinitions[regionIndex].regionName, "regionName": regionDefinitions[regionNameIndex].regionName,
"countries": [] "countries": []
}); });
} }
let usedIndices = {}; let usedIndices = {};
for (let regionIndex = 0; regionIndex < regionDefinitions.length; ++regionIndex) { for (let regionDefIndex = 0; regionDefIndex < regionDefinitions.length; ++regionDefIndex) {
const regionDefinition = regionDefinitions[regionIndex]; const regionDefinition = regionDefinitions[regionDefIndex];
for (let countryIndex = 0; countryIndex < regionDefinition.countries.length; ++countryIndex) { for (let countryIndex = 0; countryIndex < regionDefinition.countries.length; ++countryIndex) {
const countryRef = regionDefinition.countries[countryIndex]; const countryRef = regionDefinition.countries[countryIndex];
const sourceIndex = findCountryIndexByRef(countryRef, usedIndices); const sourceIndex = findCountryIndexByRef(countryRef, usedIndices);
if (sourceIndex < 0) { if (sourceIndex < 0) {
if (isCountryMatchingSearch(countryRef.name, countryRef.code, countryRef.code)) {
regions[regionDefIndex].countries.push({
"sourceIndex": -1,
"countryName": getDisplayCountryName(countryRef.name),
"sourceCountryName": countryRef.name,
"countryCode": countryRef.code,
"countryImageCode": extractCountryIsoCode(countryRef.code),
"isAvailable": false
});
}
continue; continue;
} }
@@ -189,16 +205,17 @@ PageType {
} }
const displayCountryName = getDisplayCountryName(sourceCountry.countryName); const displayCountryName = getDisplayCountryName(sourceCountry.countryName);
if (!isCountryMatchingSearch(displayCountryName)) { if (!isCountryMatchingSearch(displayCountryName, countryRef.code, sourceCountry.countryCode)) {
continue; continue;
} }
regions[regionIndex].countries.push({ regions[regionDefIndex].countries.push({
"sourceIndex": sourceIndex, "sourceIndex": sourceIndex,
"countryName": displayCountryName, "countryName": displayCountryName,
"sourceCountryName": sourceCountry.countryName, "sourceCountryName": sourceCountry.countryName,
"countryCode": sourceCountry.countryCode, "countryCode": sourceCountry.countryCode,
"countryImageCode": extractCountryIsoCode(sourceCountry.countryImageCode) "countryImageCode": extractCountryIsoCode(sourceCountry.countryImageCode),
"isAvailable": true
}); });
usedIndices[sourceIndex] = true; usedIndices[sourceIndex] = true;
} }
@@ -489,10 +506,13 @@ PageType {
imageSource: "qrc:/images/controls/download.svg" imageSource: "qrc:/images/controls/download.svg"
checked: countryData.sourceIndex === ApiCountryModel.currentIndex checked: countryData.sourceIndex >= 0 && countryData.sourceIndex === ApiCountryModel.currentIndex
checkable: !ConnectionController.isConnected checkable: countryData.isAvailable && !ConnectionController.isConnected
onClicked: { onClicked: {
if (!countryData.isAvailable) {
return
}
if (ConnectionController.isConnectionInProgress) { if (ConnectionController.isConnectionInProgress) {
PageController.showNotificationMessage(qsTr("Unable change server location while trying to make an active connection")) PageController.showNotificationMessage(qsTr("Unable change server location while trying to make an active connection"))
return return