Skip to content

Commit

Permalink
Merge pull request #386 from rishabh7923/main
Browse files Browse the repository at this point in the history
Fixed & Improved The Google Summer of Code Screen Performance
  • Loading branch information
andoriyaprashant authored Oct 28, 2024
2 parents 220d288 + cc7c36f commit aecdac2
Show file tree
Hide file tree
Showing 7 changed files with 66,185 additions and 36,716 deletions.
18,603 changes: 12,252 additions & 6,351 deletions assets/projects/gsoc_org/gsoc2020org.json

Large diffs are not rendered by default.

19,693 changes: 13,195 additions & 6,498 deletions assets/projects/gsoc_org/gsoc2021org.json

Large diffs are not rendered by default.

18,780 changes: 12,328 additions & 6,452 deletions assets/projects/gsoc_org/gsoc2022org.json

Large diffs are not rendered by default.

19,136 changes: 12,501 additions & 6,635 deletions assets/projects/gsoc_org/gsoc2023org.json

Large diffs are not rendered by default.

26,454 changes: 15,835 additions & 10,619 deletions assets/projects/gsoc_org/gsoc2024org.json

Large diffs are not rendered by default.

234 changes: 73 additions & 161 deletions lib/programs screen/google_summer_of_code_screen.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:opso/modals/book_mark_model.dart';
import 'package:opso/programs_info_pages/gsoc_info.dart';
import 'package:opso/widgets/gsoc/GsocProjectWidget.dart';
import 'package:multi_select_flutter/multi_select_flutter.dart';
import '../modals/GSoC/Gsoc.dart';
import '../services/ApiService.dart';
import '../widgets/year_button.dart';

class GoogleSummerOfCodeScreen extends StatefulWidget {
Expand All @@ -18,16 +20,19 @@ class GoogleSummerOfCodeScreen extends StatefulWidget {

class _GoogleSummerOfCodeScreenState extends State<GoogleSummerOfCodeScreen> {
bool _isRefreshing = false;

bool isBookmarked = true;
String currentPage = "/google_summer_of_code";
String currentProject = "Google Summer of Code";
String selectedOrg = ''; // Ensure this is defined

int selectedYear = 2024;
List<String> selectedProposals = ['All'];

List<Organization> gsoc2024 = [];
List<Organization> gsoc2023 = [];
List<Organization> gsoc2022 = [];
List<Organization> gsoc2021 = [];
int selectedYear = 2024;

List<String> languages = [
'All',
'js',
Expand All @@ -46,128 +51,94 @@ class _GoogleSummerOfCodeScreenState extends State<GoogleSummerOfCodeScreen> {
'flutter',
'Dart'
];

List<Organization> orgList = [];
List<String> selectedLanguages = [];
List<String> allOrganizations = [];
List<String> selectedOrganizations = [];

late Future<void> _dataFetchFuture;

@override
void initState() {
super.initState();
_refresh();
_dataFetchFuture = getProjectData();
_dataFetchFuture = initializeProjectLists();
_checkBookmarkStatus();
}

Future<List<Organization>> loadOrganizations(int year) async {
setState(() { _isRefreshing = true; });
String path = 'assets/projects/gsoc_org/gsoc${year}org.json';
String response = await rootBundle.loadString(path);

setState(() { _isRefreshing = false; });
var decodedResponse = json.decode(response) as List;
return decodedResponse.map((org) => Organization.fromJson(org)).toList();
}

Future<void> _checkBookmarkStatus() async {
bool bookmarkStatus = await HandleBookmark.isBookmarked(currentProject);
setState(() {
isBookmarked = bookmarkStatus;
});
}

Future<void> getProjectData() async {
ApiService apiService = ApiService();
try {
Gsoc orgData2021 = await apiService.getOrgByYear('2021');
Gsoc orgData2022 = await apiService.getOrgByYear('2022');
Gsoc orgData2023 = await apiService.getOrgByYear('2023');
Gsoc orgData2024 = await apiService.getOrgByYear('2024');
void filterProjects() async {
orgList = await _getOrganizationsByYear(selectedYear);

setState(() {
gsoc2021 = orgData2021.organizations ?? [];
gsoc2022 = orgData2022.organizations ?? [];
gsoc2023 = orgData2023.organizations ?? [];
gsoc2024 = orgData2024.organizations ?? [];
orgList = gsoc2024; // Default to the latest year
allOrganizations = [...orgList.map((org) => org.name).toSet()];
});
} catch (e) {
if (kDebugMode) {
print('Error: $e');
}
}
}

void filterProjects() {
orgList = _getOrganizationsByYear(selectedYear);
if (selectedLanguages.length >= 2) {
selectedLanguages.removeAt(0);
}
if (selectedOrganizations.length >= 2) {
selectedOrganizations.removeAt(0);
}

if (!selectedLanguages.contains('All')) {
orgList = orgList
.where((project) => selectedLanguages.every(
(language) => project.technologies.contains(language) == true))
.toList();
}

if (!selectedOrganizations.contains('All')) {
orgList = orgList
.where((project) => selectedOrganizations.contains(project.name))
.toList();
}

// Update organization filter based on selected languages
allOrganizations = [
..._getOrganizationsByYear(selectedYear)
.where((org) =>
selectedLanguages.contains('All') ||
org.technologies.any(selectedLanguages.contains) == true)
.map((org) => org.name)
.toSet()
];

setState(() {});
}

List<Organization> _getOrganizationsByYear(int year) {
Future<List<Organization>> _getOrganizationsByYear(int year) async {
switch (year) {
case 2021:
if (gsoc2021.isEmpty) gsoc2021 = await loadOrganizations(year);
return gsoc2021;
case 2022:
if (gsoc2022.isEmpty) gsoc2022 = await loadOrganizations(year);
return gsoc2022;
case 2023:
if (gsoc2023.isEmpty) gsoc2023 = await loadOrganizations(year);
return gsoc2023;
case 2024:
if (gsoc2024.isEmpty) gsoc2024 = await loadOrganizations(year);
return gsoc2024;
default:
return [];
}
}

Future<void> _refresh() async {
setState(() {
_isRefreshing = true;
});
await getProjectData();
setState(() {
initializeProjectLists();
selectedYear = 2024;
selectedLanguages = ['All'];
selectedOrganizations = ['All'];
filterProjects();
_isRefreshing = false;
});
}

// Add this method to the _GoogleSummerOfCodeScreenState class
void search(String searchText) {
setState(() {
selectedOrg = 'All'; // Reset selectedOrg to avoid mismatch
if (searchText.isEmpty) {
orgList = _getOrganizationsByYear(selectedYear);
} else {
orgList = _getOrganizationsByYear(selectedYear)
.where((element) =>
element.name.toLowerCase().contains(searchText.toLowerCase()) ==
true)
.toList();
}
});
void search(String searchText) async {
orgList = await _getOrganizationsByYear(selectedYear);

if (searchText.isNotEmpty) {
orgList = orgList
.where((element) =>
element.name.toLowerCase().contains(searchText.toLowerCase()) ==
true)
.toList();
}

setState(() {});
}

@override
Expand Down Expand Up @@ -223,9 +194,7 @@ class _GoogleSummerOfCodeScreenState extends State<GoogleSummerOfCodeScreen> {
body: FutureBuilder<void>(
future: _dataFetchFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
} else if (snapshot.hasError) {
if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'));
} else {
return SingleChildScrollView(
Expand Down Expand Up @@ -290,66 +259,20 @@ class _GoogleSummerOfCodeScreenState extends State<GoogleSummerOfCodeScreen> {
mainAxisSpacing: 15,
),
children: [
YearButton(
year: "2021",
isEnabled: selectedYear == 2021,
onTap: () {
setState(() {
selectedYear = 2021;
selectedLanguages = [];
selectedOrganizations = [];
filterProjects();
});
},
backgroundColor: selectedYear == 2021
? Colors.white
: const Color.fromRGBO(255, 183, 77, 1),
),
YearButton(
year: "2022",
isEnabled: selectedYear == 2022,
onTap: () {
setState(() {
selectedYear = 2022;
selectedLanguages = [];
selectedOrganizations = [];
filterProjects();
});
},
backgroundColor: selectedYear == 2022
? Colors.white
: const Color.fromRGBO(255, 183, 77, 1),
),
YearButton(
year: "2023",
isEnabled: selectedYear == 2023,
onTap: () {
setState(() {
selectedYear = 2023;
selectedLanguages = [];
selectedOrganizations = [];
filterProjects();
});
},
backgroundColor: selectedYear == 2023
? Colors.white
: const Color.fromRGBO(255, 183, 77, 1),
),
YearButton(
isEnabled: selectedYear == 2024,
year: "2024",
onTap: () {
setState(() {
selectedYear = 2024;
selectedLanguages = [];
selectedOrganizations = [];
filterProjects();
});
},
backgroundColor: selectedYear == 2024
? Colors.white
: const Color.fromRGBO(255, 183, 77, 1),
),
for (int year = 2021; year <= 2024; year++)
YearButton(
year: year.toString(),
isEnabled: selectedYear == year,
onTap: () {
setState(() {
selectedYear = year;
filterProjects();
});
},
backgroundColor: selectedYear == year
? Colors.white
: const Color.fromRGBO(255, 183, 77, 1),
),
],
),
),
Expand All @@ -371,34 +294,21 @@ class _GoogleSummerOfCodeScreenState extends State<GoogleSummerOfCodeScreen> {
},
),
const SizedBox(height: 20),
orgList.isEmpty
? _isRefreshing
? const Column(
_isRefreshing
? const Column(
children: [
SizedBox(height: 50),
Center(
child: Column(
children: [
Center(
child: Column(
children: [
CircularProgressIndicator(),
SizedBox(height: 10),
Text('Refreshing...'),
],
)),
SizedBox(height: 20),
CircularProgressIndicator(),
SizedBox(height: 10),
Text('Loading...'),
],
)
: Column(
children: [
const Center(
child: Text('No projects found')),
const SizedBox(height: 20),
TextButton(
onPressed: () {
_refresh();
},
child: const Text('Refresh'),
),
],
)
)),
SizedBox(height: 20),
],
)
: ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
Expand Down Expand Up @@ -464,6 +374,8 @@ class _GoogleSummerOfCodeScreenState extends State<GoogleSummerOfCodeScreen> {
),
);
}

void initializeProjectLists() {}

Future<void> initializeProjectLists() async {
orgList = await _getOrganizationsByYear(selectedYear);
}
}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ flutter:
- assets/no-results.png
- assets/projects/osoc/osoc2021.json
- assets/projects/osoc/osoc2022.json
- assets/projects/gsoc_org/

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
Expand Down

0 comments on commit aecdac2

Please sign in to comment.