mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-07 00:24:18 +00:00
chore: Merge pull request 'feat(location): Make flag getter a part of server provider location object' (#238) from country-flag into master
Reviewed-on: https://git.selfprivacy.org/SelfPrivacy/selfprivacy.org.app/pulls/238 Reviewed-by: Inex Code <inex.code@selfprivacy.org>
This commit is contained in:
commit
c0dbf4454c
|
@ -36,6 +36,43 @@ class DigitalOceanLocation {
|
|||
|
||||
static DigitalOceanLocation fromJson(final Map<String, dynamic> json) =>
|
||||
_$DigitalOceanLocationFromJson(json);
|
||||
|
||||
String get flag {
|
||||
String emoji = '';
|
||||
|
||||
switch (slug.substring(0, 3)) {
|
||||
case 'fra':
|
||||
emoji = '🇩🇪';
|
||||
break;
|
||||
|
||||
case 'ams':
|
||||
emoji = '🇳🇱';
|
||||
break;
|
||||
|
||||
case 'sgp':
|
||||
emoji = '🇸🇬';
|
||||
break;
|
||||
|
||||
case 'lon':
|
||||
emoji = '🇬🇧';
|
||||
break;
|
||||
|
||||
case 'tor':
|
||||
emoji = '🇨🇦';
|
||||
break;
|
||||
|
||||
case 'blr':
|
||||
emoji = '🇮🇳';
|
||||
break;
|
||||
|
||||
case 'nyc':
|
||||
case 'sfo':
|
||||
emoji = '🇺🇸';
|
||||
break;
|
||||
}
|
||||
|
||||
return emoji;
|
||||
}
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
|
|
|
@ -135,6 +135,24 @@ class HetznerLocation {
|
|||
|
||||
static HetznerLocation fromJson(final Map<String, dynamic> json) =>
|
||||
_$HetznerLocationFromJson(json);
|
||||
|
||||
String get flag {
|
||||
String emoji = '';
|
||||
switch (country.substring(0, 2)) {
|
||||
case 'DE':
|
||||
emoji = '🇩🇪';
|
||||
break;
|
||||
|
||||
case 'FI':
|
||||
emoji = '🇫🇮';
|
||||
break;
|
||||
|
||||
case 'US':
|
||||
emoji = '🇺🇸';
|
||||
break;
|
||||
}
|
||||
return emoji;
|
||||
}
|
||||
}
|
||||
|
||||
/// A Volume is a highly-available, scalable, and SSD-based block storage for Servers.
|
||||
|
|
|
@ -3,13 +3,11 @@ class ServerProviderLocation {
|
|||
required this.title,
|
||||
required this.identifier,
|
||||
this.description,
|
||||
this.flag,
|
||||
this.flag = '',
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String identifier;
|
||||
final String? description;
|
||||
|
||||
/// as emoji
|
||||
final String? flag;
|
||||
final String flag;
|
||||
}
|
||||
|
|
|
@ -293,43 +293,6 @@ class DigitalOceanServerProvider extends ServerProvider {
|
|||
return success;
|
||||
}
|
||||
|
||||
String? getEmojiFlag(final String query) {
|
||||
String? emoji;
|
||||
|
||||
switch (query.toLowerCase().substring(0, 3)) {
|
||||
case 'fra':
|
||||
emoji = '🇩🇪';
|
||||
break;
|
||||
|
||||
case 'ams':
|
||||
emoji = '🇳🇱';
|
||||
break;
|
||||
|
||||
case 'sgp':
|
||||
emoji = '🇸🇬';
|
||||
break;
|
||||
|
||||
case 'lon':
|
||||
emoji = '🇬🇧';
|
||||
break;
|
||||
|
||||
case 'tor':
|
||||
emoji = '🇨🇦';
|
||||
break;
|
||||
|
||||
case 'blr':
|
||||
emoji = '🇮🇳';
|
||||
break;
|
||||
|
||||
case 'nyc':
|
||||
case 'sfo':
|
||||
emoji = '🇺🇸';
|
||||
break;
|
||||
}
|
||||
|
||||
return emoji;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GenericResult<List<ServerProviderLocation>>>
|
||||
getAvailableLocations() async {
|
||||
|
@ -351,7 +314,7 @@ class DigitalOceanServerProvider extends ServerProvider {
|
|||
location = ServerProviderLocation(
|
||||
title: rawLocation.slug,
|
||||
description: rawLocation.name,
|
||||
flag: getEmojiFlag(rawLocation.slug),
|
||||
flag: rawLocation.flag,
|
||||
identifier: rawLocation.slug,
|
||||
);
|
||||
} catch (e) {
|
||||
|
@ -662,8 +625,7 @@ class DigitalOceanServerProvider extends ServerProvider {
|
|||
ServerMetadataEntity(
|
||||
type: MetadataType.location,
|
||||
trId: 'server.location',
|
||||
value:
|
||||
'${droplet['region']['name']} ${getEmojiFlag(droplet['region']['slug'].toString()) ?? ''}',
|
||||
value: '${droplet['region']['name']}',
|
||||
),
|
||||
ServerMetadataEntity(
|
||||
type: MetadataType.other,
|
||||
|
|
|
@ -335,26 +335,6 @@ class HetznerServerProvider extends ServerProvider {
|
|||
return result;
|
||||
}
|
||||
|
||||
String? getEmojiFlag(final String query) {
|
||||
String? emoji;
|
||||
|
||||
switch (query.toLowerCase()) {
|
||||
case 'de':
|
||||
emoji = '🇩🇪';
|
||||
break;
|
||||
|
||||
case 'fi':
|
||||
emoji = '🇫🇮';
|
||||
break;
|
||||
|
||||
case 'us':
|
||||
emoji = '🇺🇸';
|
||||
break;
|
||||
}
|
||||
|
||||
return emoji;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GenericResult<bool>> trySetServerLocation(
|
||||
final String location,
|
||||
|
@ -396,7 +376,7 @@ class HetznerServerProvider extends ServerProvider {
|
|||
location = ServerProviderLocation(
|
||||
title: rawLocation.city,
|
||||
description: rawLocation.description,
|
||||
flag: getEmojiFlag(rawLocation.country),
|
||||
flag: rawLocation.flag,
|
||||
identifier: rawLocation.name,
|
||||
);
|
||||
} catch (e) {
|
||||
|
|
|
@ -107,7 +107,7 @@ class SelectLocationPage extends StatelessWidget {
|
|||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${location.flag ?? ''} ${location.title}',
|
||||
'${location.flag} ${location.title}',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleMedium,
|
||||
|
|
Loading…
Reference in a new issue