Skip to content

Commit

Permalink
feat: project tab remembers expanded state
Browse files Browse the repository at this point in the history
  • Loading branch information
Benimautner committed Oct 1, 2024
1 parent cb3dde5 commit 087e39f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
27 changes: 24 additions & 3 deletions lib/pages/project/overview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,33 @@ class _ProjectOverviewPageState extends State<ProjectOverviewPage>
? _projects[_selectedDrawerIndex]
: null;

List<int> expandedList = [];

@override
void afterFirstLayout(BuildContext context) {
_loadProjects();
VikunjaGlobal.of(context)
.settingsManager
.getExpandedProjects()
.then((val) => setState(() {
expandedList = val ?? [];
print("Setting expanded list in setup to $expandedList");
}));
}

List<int> expandedList = [];
void updateExpandedList() {
VikunjaGlobal.of(context).settingsManager.setExpandedProjects(expandedList);
}

void addToExpandedList(int id) {
expandedList.add(id);
updateExpandedList();
}

void removeFromExpandedList(int id) {
expandedList.remove(id);
updateExpandedList();
}

Widget createProjectTile(Project project, int level) {
EdgeInsets insets = EdgeInsets.fromLTRB(level * 10 + 10, 0, 0, 0);
Expand Down Expand Up @@ -65,9 +86,9 @@ class _ProjectOverviewPageState extends State<ProjectOverviewPage>
? () {
setState(() {
if (expanded)
expandedList.remove(project.id);
removeFromExpandedList(project.id);
else
expandedList.add(project.id);
addToExpandedList(project.id);
});
}
: null,
Expand Down
14 changes: 12 additions & 2 deletions lib/service/services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class SettingsManager {
"landing-page-due-date-tasks": "1",
"sentry-enabled": "0",
"sentry-modal-shown": "0",
"expanded-projects": "[]",
};

void applydefaults() {
Expand Down Expand Up @@ -325,11 +326,20 @@ class SettingsManager {
}

Future<void> setPastServers(List<String>? server) {
var val = jsonEncode(server);
print("val: $val");
return _storage.write(key: "recent-servers", value: jsonEncode(server));
}

Future<List<int>?> getExpandedProjects() async {
String jsonString = await _storage.read(key: "expanded-projects") ?? "[]";
List<dynamic> server = jsonDecode(jsonString);
return server.map((e) => e as int).toList();
}

Future<void> setExpandedProjects(List<int>? expandedProjects) {
return _storage.write(
key: "expanded-projects", value: jsonEncode(expandedProjects));
}

Future<FlutterThemeMode> getThemeMode() async {
String? theme_mode = await _storage.read(key: "theme_mode");
if (theme_mode == null) setThemeMode(FlutterThemeMode.system);
Expand Down

0 comments on commit 087e39f

Please sign in to comment.