Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/enums/api_call_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
enum ApiCallState {
idle,
loading,
success,
error,
}
125 changes: 67 additions & 58 deletions lib/pages/home/page/home_v2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:clashbot_flutter/pages/errorPages/whoops_page.dart';
import 'package:clashbot_flutter/pages/home/page/widgets/calendar_widget.dart';
import 'package:clashbot_flutter/pages/home/page/widgets/events_widget.dart';
import 'package:clashbot_flutter/pages/home/page/widgets/server_chip_list.dart';
import 'package:clashbot_flutter/stores/application_details.store.dart';
import 'package:clashbot_flutter/stores/discord_details.store.dart';
import 'package:clashbot_flutter/stores/v2-stores/clash.store.dart';
import 'package:clashbot_flutter/stores/v2-stores/error_handler.store.dart';
Expand Down Expand Up @@ -94,66 +95,74 @@ class _HomeV2State extends State<HomeV2> {
ClashStore clashStore = context.read<ClashStore>();
DiscordDetailsStore discordDetailsStore =
context.read<DiscordDetailsStore>();
ErrorHandlerStore errorHandlerStore = context.read<ErrorHandlerStore>();
ApplicationDetailsStore applicationDetailsStore =
context.read<ApplicationDetailsStore>();
return Scaffold(
body: Observer(
builder: (_) => errorHandlerStore.irreconcilable
? const WhoopsPage()
: LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth > 500) {
return Row(
children: [
Flexible(
flex: 1,
child: Flex(direction: Axis.vertical, children: [
const ServerChipList(),
CalendarWidget(
focusedDay: _focusedDay,
selectedDay: _selectedDay,
clashStore: clashStore,
discordDetailsStore: discordDetailsStore),
Expanded(
child: Card.filled(
color: Theme.of(context).brightness ==
Brightness.dark
? Colors.blueGrey
: Colors.blueAccent,
margin: const EdgeInsets.all(16.0),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: SvgPicture.asset(
'svgs/ClashBot-HomePage.svg',
semanticsLabel: 'Clash Bot Home Page',
width: 100,
height: 600,
),
),
),
),
]),
body: LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth > 500) {
return Row(
children: [
Flexible(
flex: 1,
child: Flex(direction: Axis.vertical, children: [
ServerChipList(
appStore: applicationDetailsStore,
discordDetailsStore: discordDetailsStore,
clashStore: clashStore),
CalendarWidget(
focusedDay: _focusedDay,
selectedDay: _selectedDay,
clashStore: clashStore,
discordDetailsStore: discordDetailsStore),
Expanded(
child: Card.filled(
color: Theme.of(context).brightness == Brightness.dark
? Colors.blueGrey
: Colors.blueAccent,
margin: const EdgeInsets.all(16.0),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: SvgPicture.asset(
'svgs/ClashBot-HomePage.svg',
semanticsLabel: 'Clash Bot Home Page',
width: 100,
height: 600,
),
),
const Flexible(
flex: 2,
child: EventsListWidget(),
),
],
);
} else {
return Column(
children: [
ServerChipList(),
CalendarWidget(
focusedDay: _focusedDay,
selectedDay: _selectedDay,
clashStore: clashStore,
discordDetailsStore: discordDetailsStore),
EventsListWidget(),
],
);
}
},
),
),
),
]),
),
Flexible(
flex: 2,
child: EventsListWidget(
clashStore: clashStore,
applicationDetailsStore: applicationDetailsStore,
discordDetailStore: discordDetailsStore),
),
],
);
} else {
return Column(
children: [
ServerChipList(
appStore: applicationDetailsStore,
discordDetailsStore: discordDetailsStore,
clashStore: clashStore),
CalendarWidget(
focusedDay: _focusedDay,
selectedDay: _selectedDay,
clashStore: clashStore,
discordDetailsStore: discordDetailsStore),
EventsListWidget(
clashStore: clashStore,
applicationDetailsStore: applicationDetailsStore,
discordDetailStore: discordDetailsStore),
],
);
}
},
),
floatingActionButton: Observer(
builder: (_) => clashStore.canCreateTeam
Expand Down
154 changes: 104 additions & 50 deletions lib/pages/home/page/widgets/calendar_widget.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import 'package:clashbot_flutter/enums/api_call_state.dart';
import 'package:clashbot_flutter/pages/home/page/home_v2.dart';
import 'package:clashbot_flutter/pages/shimmer_loading_page.dart';
import 'package:clashbot_flutter/stores/discord_details.store.dart';
import 'package:clashbot_flutter/stores/v2-stores/clash.store.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:intl/intl.dart';
import 'package:mobx/mobx.dart';
import 'package:provider/provider.dart';
import 'package:table_calendar/table_calendar.dart';
import 'dart:developer' as developer;

/// This widget requires the following providers:
///
Expand Down Expand Up @@ -61,36 +65,39 @@ class _CalendarWidgetState extends State<CalendarWidget> {
Widget build(BuildContext context) {
bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
return Observer(
builder: (_) => widget.clashStore.isRefreshingData
? SizedBox(
width: 1000.0, child: LoadingCalendar(focusedDay: _focusedDay))
: SizedBox(
width: 1000.0,
child: Container(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
CalendarHeader(
focusedDay: _focusedDay,
onMonthChanged: onMonthChanged,
),
CalendarBody(
focusedDay: _focusedDay,
hoveredDay: _hoveredDay,
isDarkMode: isDarkMode,
discordDetailsStore: widget.discordDetailsStore,
clashStore: widget.clashStore,
onDaySelected: onDaySelected,
onHoveredDayChanged: (day) {
setState(() {
_hoveredDay = day;
});
},
builder: (_) =>
widget.clashStore.tournamentsApiCallState == ApiCallState.loading
? SizedBox(
width: 1000.0,
child: LoadingCalendar(focusedDay: _focusedDay))
: SizedBox(
width: 1000.0,
child: Container(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
CalendarHeader(
focusedDay: _focusedDay,
onMonthChanged: onMonthChanged,
clashStore: widget.clashStore,
),
CalendarBody(
focusedDay: _focusedDay,
hoveredDay: _hoveredDay,
isDarkMode: isDarkMode,
discordDetailsStore: widget.discordDetailsStore,
clashStore: widget.clashStore,
onDaySelected: onDaySelected,
onHoveredDayChanged: (day) {
setState(() {
_hoveredDay = day;
});
},
),
],
),
],
),
),
));
),
));
}
}

Expand Down Expand Up @@ -142,36 +149,83 @@ class LoadingCalendar extends StatelessWidget {
class CalendarHeader extends StatelessWidget {
final DateTime focusedDay;
final ValueChanged<DateTime> onMonthChanged;
final ClashStore clashStore;

const CalendarHeader({
Key? key,
required this.focusedDay,
required this.onMonthChanged,
required this.clashStore,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
onMonthChanged(DateTime(focusedDay.year, focusedDay.month - 1));
},
),
Text(
DateFormat('MMMM yyyy').format(focusedDay),
style: const TextStyle(fontSize: 20.0),
),
IconButton(
icon: const Icon(Icons.arrow_forward),
onPressed: () {
onMonthChanged(DateTime(focusedDay.year, focusedDay.month + 1));
},
),
],
);
return Observer(builder: (_) {
developer.log(
"CalendarHeader: Api Status${clashStore.tournamentsApiCallState}");
InputChip chip;
switch (clashStore.tournamentsApiCallState) {
case ApiCallState.loading:
chip = InputChip(
label: const CircularProgressIndicator(),
backgroundColor: Theme.of(context).colorScheme.secondary,
tooltip: 'Loading...',
);
case ApiCallState.success:
chip = InputChip(
label: const Icon(Icons.check),
backgroundColor: Theme.of(context).colorScheme.primary,
tooltip: "Data up to date",
);
break;
case ApiCallState.error:
chip = InputChip(
label: const Icon(Icons.refresh),
onPressed: () {
clashStore
.refreshClashTournaments(clashStore.clashBotUser.discordId!);
},
backgroundColor: Theme.of(context).colorScheme.error,
tooltip: 'Data failed to load, tap to retry',
);
break;
default:
chip = InputChip(
label: const Text('N/A'),
onPressed: () {},
backgroundColor: Theme.of(context).colorScheme.onSurface,
tooltip: 'N/A',
);
break;
}
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
onMonthChanged(DateTime(focusedDay.year, focusedDay.month - 1));
},
),
Wrap(
spacing: 10,
children: [
Text(
DateFormat('MMMM yyyy').format(focusedDay),
style: const TextStyle(fontSize: 20.0),
),
chip,
],
),
IconButton(
icon: const Icon(Icons.arrow_forward),
onPressed: () {
onMonthChanged(DateTime(focusedDay.year, focusedDay.month + 1));
},
),
],
);
});
}
}

Expand Down
Loading