diff --git a/ltx_flutter/lib/appwrite/categories_api.dart b/ltx_flutter/lib/appwrite/categories_api.dart new file mode 100644 index 0000000..4ac80c1 --- /dev/null +++ b/ltx_flutter/lib/appwrite/categories_api.dart @@ -0,0 +1,71 @@ +import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/models.dart'; +import 'package:ltx_flutter/constants/constants.dart'; +import 'package:flutter/widgets.dart'; +import 'package:ltx_flutter/appwrite/appwrite.dart'; + +class CategoriesAPI extends ChangeNotifier { + Client client = Client(); + late final Account account; + late final Databases databases; + late final String userId; + final AuthAPI auth = AuthAPI(); + + // Constructor + CategoriesAPI() { + init(); + } + + // loadUser() async { + // try { + // user = await account.get(); + // notifyListeners(); + // } catch (e) { + // print(e); + // notifyListeners(); + // } + // } + + init() { + client.setEndpoint(APPWRITE_URL).setProject(APPWRITE_PROJECT_ID); + account = Account(client); + databases = Databases(client); + } + + Future getCategories() { + print("Getting categories"); + return databases.listDocuments( + databaseId: CATEGORIES_DB, + collectionId: COLLECTION, + queries: [ + Query.orderAsc("number"), + ]); + } + + Future addCategory({ + required String name, + required double number, + required String color, + String? description, + int? parentId, + }) { + return databases.createDocument( + databaseId: CATEGORIES_DB, + collectionId: COLLECTION, + documentId: "category-${number.toString()}", + data: { + 'name': name, + 'number': number, + 'color': color, + 'parent': parentId, + 'description': description, + }); + } + + Future deleteCategory({required double number}) { + return databases.deleteDocument( + databaseId: CATEGORIES_DB, + collectionId: COLLECTION, + documentId: "category-${number.toString()}"); + } +} diff --git a/ltx_flutter/lib/constants/constants.dart b/ltx_flutter/lib/constants/constants.dart index 4b0ca33..8ed417e 100644 --- a/ltx_flutter/lib/constants/constants.dart +++ b/ltx_flutter/lib/constants/constants.dart @@ -1,4 +1,5 @@ const String APPWRITE_PROJECT_ID = "lifetracker"; const String APPWRITE_DATABASE_ID = "lifetracker-db"; +const String CATEGORIES_DB = "categories"; const String APPWRITE_URL = "https://db.ryanpandya.com/v1"; const String COLLECTION = "ryan"; diff --git a/ltx_flutter/lib/pages/table_page.dart b/ltx_flutter/lib/pages/table_page.dart index f693d3d..3b72949 100644 --- a/ltx_flutter/lib/pages/table_page.dart +++ b/ltx_flutter/lib/pages/table_page.dart @@ -61,7 +61,7 @@ class _TablePageState extends State { title: hourTitle, field: "hours[$e]", type: PlutoColumnType.number(), - width: 65, + width: 70, enableContextMenu: false, enableDropToResize: false, textAlign: PlutoColumnTextAlign.center, @@ -75,23 +75,22 @@ class _TablePageState extends State { field: 'date', type: PlutoColumnType.text(), readOnly: true, - width: 110, - frozen: PlutoColumnFrozen.start, + width: 70, enableContextMenu: false, enableDropToResize: false, textAlign: PlutoColumnTextAlign.center, titleTextAlign: PlutoColumnTextAlign.center, + frozen: PlutoColumnFrozen.start, + ), + PlutoColumn( + title: 'DAY', + field: 'day', + type: PlutoColumnType.text(), + readOnly: true, + width: 53, + enableContextMenu: false, + enableDropToResize: false, ), - // PlutoColumn( - // title: 'DAY', - // field: 'day', - // type: PlutoColumnType.text(), - // readOnly: true, - // width: 50, - // frozen: PlutoColumnFrozen.start, - // enableContextMenu: false, - // enableDropToResize: false, - // ), ] + hourCols + [ @@ -117,23 +116,27 @@ class _TablePageState extends State { var cells = { 'date': PlutoCell( value: formatDate( - format: "MM/DD E", + format: "MM/DD", + dateISO: e.data['date'], + ), + ), + 'day': PlutoCell( + value: formatDate( + format: "E", dateISO: e.data['date'], ), ), - // 'day': PlutoCell( - // value: formatDate( - // format: "E", - // dateISO: e.data['date'], - // ), - // ), 'mood': PlutoCell(value: e.data['mood']), 'comments': PlutoCell(value: e.data['comments']), }; var hours = {}; for (int i = 0; i < 24; i++) { hours.putIfAbsent( - "hours[$i]", () => PlutoCell(value: e.data['hours'][i])); + "hours[$i]", + () => PlutoCell( + value: e.data['hours'][i], + ), + ); } cells.addEntries(hours.entries); @@ -159,8 +162,7 @@ class _TablePageState extends State { child: entries!.isEmpty ? Center(child: const CircularProgressIndicator()) : Scaffold( - body: Container( - padding: const EdgeInsets.all(0), + body: InteractiveViewer( child: PlutoGrid( columns: columns, rows: rows, diff --git a/ltx_flutter/lib/pages/tabs_page.dart b/ltx_flutter/lib/pages/tabs_page.dart index 2dd7587..3459a4f 100644 --- a/ltx_flutter/lib/pages/tabs_page.dart +++ b/ltx_flutter/lib/pages/tabs_page.dart @@ -1,6 +1,9 @@ import 'package:ltx_flutter/pages/table_page.dart'; import 'package:ltx_flutter/pages/account_page.dart'; +import 'package:ltx_flutter/pages/categories_page.dart'; +import 'package:ltx_flutter/pages/today_page.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; class TabsPage extends StatefulWidget { const TabsPage({Key? key}) : super(key: key); @@ -12,7 +15,7 @@ class TabsPage extends StatefulWidget { class _TabsPageState extends State { int _selectedIndex = 0; - static const _widgets = [TablePage(), AccountPage()]; + static const _widgets = [TodayPage(), CategoriesPage(), AccountPage()]; void _onItemTapped(int index) { setState(() { @@ -24,13 +27,15 @@ class _TabsPageState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text("Lifetracker"), + title: Text("LTX Android"), ), body: _widgets.elementAt(_selectedIndex), bottomNavigationBar: BottomNavigationBar( items: const [ BottomNavigationBarItem( - icon: Icon(Icons.table_chart_outlined), label: "Tracker"), + icon: Icon(Icons.today_outlined), label: "Today"), + BottomNavigationBarItem( + icon: Icon(Icons.category_outlined), label: "Categories"), BottomNavigationBarItem( icon: Icon(Icons.account_circle_outlined), label: "Account") ], diff --git a/ltx_flutter/lib/pages/today_page.dart b/ltx_flutter/lib/pages/today_page.dart new file mode 100644 index 0000000..d850f83 --- /dev/null +++ b/ltx_flutter/lib/pages/today_page.dart @@ -0,0 +1,57 @@ +import 'package:appwrite/appwrite.dart'; +import 'package:ltx_flutter/appwrite/appwrite.dart'; +import 'package:ltx_flutter/appwrite/database_api.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:appwrite/models.dart'; +import 'package:intl/intl.dart'; + +class TodayPage extends StatefulWidget { + const TodayPage({Key? key}) : super(key: key); + + @override + _TodayPageState createState() => _TodayPageState(); +} + +class _TodayPageState extends State { + final database = DatabaseAPI(); + late List? entries = []; + + AuthStatus authStatus = AuthStatus.uninitialized; + + @override + void initState() { + super.initState(); + final AuthAPI appwrite = context.read(); + authStatus = appwrite.status; + loadEntries(); + } + + loadEntries() async { + try { + final value = await database.getEntries(limit: 25); + setState(() { + entries = value.documents; + }); + } catch (e) { + print(e); + } + } + + String formatDate({String format = "", String? dateISO}) { + final DateFormat dateFormatter = DateFormat(format); + final date = dateISO!.isEmpty ? DateTime.now() : DateTime.parse(dateISO); + return dateFormatter.format(date); + } + + @override + Widget build(BuildContext context) { + return Center( + child: Column( + children: [ + Text("Entries: ${entries?.length}"), + ], + ), + ); + } +} diff --git a/ltx_flutter/pubspec.yaml b/ltx_flutter/pubspec.yaml index 3683046..cd149e3 100644 --- a/ltx_flutter/pubspec.yaml +++ b/ltx_flutter/pubspec.yaml @@ -17,6 +17,7 @@ dependencies: flutter_svg: ^2.0.6 intl: ^0.18.1 pluto_grid: ^7.0.2 + string_to_hex: ^0.2.2 dev_dependencies: flutter_test: