Minor changes on match creation page, added version retrieval from api

This commit is contained in:
Mercurio 2024-12-25 12:08:09 +01:00
parent c872e40861
commit 4d27d3be11
2 changed files with 42 additions and 2 deletions

View file

@ -7,6 +7,9 @@ import 'views/joinmatch.dart';
import 'views/creatematch.dart'; import 'views/creatematch.dart';
import 'views/friendlist.dart'; import 'views/friendlist.dart';
import 'views/myprofile.dart'; import 'views/myprofile.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import '../globals.dart';
class HomePage extends StatefulWidget { class HomePage extends StatefulWidget {
@override @override
@ -16,7 +19,6 @@ class HomePage extends StatefulWidget {
class _HomePageState extends State<HomePage> { class _HomePageState extends State<HomePage> {
int _selectedIndex = 0; int _selectedIndex = 0;
// Define the pages for each section
final List<Widget> _pages = [ final List<Widget> _pages = [
LeaderboardPage(), LeaderboardPage(),
JoinMatchPage(), JoinMatchPage(),
@ -40,14 +42,46 @@ class _HomePageState extends State<HomePage> {
); );
} }
Future<Map<String, String>> fetchCommitHashes() async {
const apiUrl = '$apiurl/latest-commit-hashes';
try {
final response = await http.get(Uri.parse(apiUrl));
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
String formatHash(String? hash) {
if (hash == null) return 'Unknown';
return '#${hash.substring(0, 8).toUpperCase()}';
}
return {
'backend': formatHash(data['backend']),
'frontend': formatHash(data['frontend']),
};
} else {
throw Exception('Failed to fetch commit hashes');
}
} catch (e) {
return {
'backend': 'Error fetching hash',
'frontend': 'Error fetching hash',
};
}
}
Future<void> _showOpenSourceLicenses() async { Future<void> _showOpenSourceLicenses() async {
final commitHashes = await fetchCommitHashes();
showDialog( showDialog(
context: context, context: context,
builder: (BuildContext context) => AboutDialog( builder: (BuildContext context) => AboutDialog(
applicationIcon: const Icon(Icons.code), applicationIcon: const Icon(Icons.code),
applicationLegalese: '© 2024 Thomas Bassi @ Defence Tech.', applicationLegalese: '© 2024 Thomas Bassi @ Defence Tech.',
applicationName: 'DTHPP', applicationName: 'DTHPP',
applicationVersion: '#B22AF349A1', applicationVersion:
'API: ${commitHashes['backend']} - UI: ${commitHashes['frontend']}',
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.only(top: 16.0), padding: const EdgeInsets.only(top: 16.0),

View file

@ -90,6 +90,12 @@ class _CreateMatchPageState extends State<CreateMatchPage> {
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
SizedBox(height: 16), SizedBox(height: 16),
Text(
'Due to current limitations in how we handle matchmaking, only the joining player can control the match. This is only a temporary solution to a problem we are actively fixing.',
style: TextStyle(fontSize: 14),
textAlign: TextAlign.center,
),
SizedBox(height: 16),
_isLoading _isLoading
? CircularProgressIndicator() // Show loading spinner ? CircularProgressIndicator() // Show loading spinner
: ElevatedButton( : ElevatedButton(