Skip to content

Commit

Permalink
feat: checkpoint (done for today)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sembauke committed Jul 18, 2023
1 parent 326edda commit 0649e20
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
7 changes: 6 additions & 1 deletion mobile-app/lib/ui/views/learn/block/block_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,13 @@ class ChallengeTile extends StatelessWidget {

String url = LearnService.baseUrl;

String fullUrl =
'$url/challenges/${block.superBlock.dashedName}/${block.dashedName}/$challengeId.json';

model.setLastVisitedChallenge(fullUrl);

model.routeToChallengeView(
'$url/challenges/${block.superBlock.dashedName}/${block.dashedName}/$challengeId.json',
fullUrl,
block,
challengeId,
);
Expand Down
5 changes: 5 additions & 0 deletions mobile-app/lib/ui/views/learn/block/block_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ class BlockViewModel extends BaseViewModel {
notifyListeners();
}

void setLastVisitedChallenge(String url) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('lastVisitedChallenge', url);
}

void routeToChallengeView(String url, Block block, String challengeId) {
_navigationService.navigateTo(
Routes.challengeView,
Expand Down
11 changes: 9 additions & 2 deletions mobile-app/lib/ui/views/learn/landing/landing_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class LearnLandingView extends StatelessWidget {
);
},
),
const ContinueLearningButton(),
ContinueLearningButton(
model: model,
),
const SizedBox(height: 16),
FutureBuilder<List<SuperBlockButtonData>>(
future: model.superBlockButtons,
Expand Down Expand Up @@ -195,8 +197,11 @@ class LearnLandingView extends StatelessWidget {
class ContinueLearningButton extends StatelessWidget {
const ContinueLearningButton({
Key? key,
required this.model,
}) : super(key: key);

final LearnLandingViewModel model;

@override
Widget build(BuildContext context) {
return Container(
Expand All @@ -206,7 +211,9 @@ class ContinueLearningButton extends StatelessWidget {
),
height: 80,
child: ElevatedButton(
onPressed: () {},
onPressed: () {
model.fastRouteToChallenge();
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color.fromRGBO(0x3b, 0x3b, 0x4f, 1),
side: const BorderSide(
Expand Down
29 changes: 29 additions & 0 deletions mobile-app/lib/ui/views/learn/landing/landing_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:freecodecamp/service/learn/learn_offline_service.dart';
import 'package:freecodecamp/service/learn/learn_service.dart';
import 'package:freecodecamp/ui/widgets/setup_dialog_ui.dart';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';

Expand All @@ -34,6 +35,12 @@ class LearnLandingViewModel extends BaseViewModel {

Future<List<SuperBlockButtonData>>? superBlockButtons;

String _challengeUrl = '';
String get challengeUrl => _challengeUrl;

bool _hasLastVisitedChallenge = false;
bool get hasLastVisitedChallenge => _hasLastVisitedChallenge;

bool _isLoggedIn = false;
bool get isLoggedIn => _isLoggedIn;

Expand All @@ -42,14 +49,36 @@ class LearnLandingViewModel extends BaseViewModel {
notifyListeners();
}

set setHasLastVisitedChallenge(value) {
_hasLastVisitedChallenge = value;
notifyListeners();
}

set setChallengeUrl(value) {
_challengeUrl = value;
notifyListeners();
}

void init(BuildContext context) async {
setupDialogUi();
retrieveNewQuote();
initLoggedInListener();

setSuperBlockButtons = getSuperBlocks();

retrieveLastVisitedChallenge();
}

void retrieveLastVisitedChallenge() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
setHasLastVisitedChallenge =
prefs.getString('lastVisitedChallenge')?.isNotEmpty ?? false;
setChallengeUrl = prefs.getString('lastVisitedChallenge') ?? '';
notifyListeners();
}

void fastRouteToChallenge() async {}

Future<List<SuperBlockButtonData>> getSuperBlocks() async {
return await _learnOfflineService.hasInternet()
? requestSuperBlocks()
Expand Down

0 comments on commit 0649e20

Please sign in to comment.