add page for aur search
install aur package by button click
This commit is contained in:
		@@ -26,6 +26,15 @@ class _APIBuilderState<T extends BaseProvider, K, DTO>
 | 
			
		||||
    extends State<APIBuilder<T, K, DTO>> {
 | 
			
		||||
  Timer? timer;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void didUpdateWidget(APIBuilder<T, K, DTO> oldWidget) {
 | 
			
		||||
    if (oldWidget.dto != widget.dto) {
 | 
			
		||||
      Provider.of<T>(context, listen: false)
 | 
			
		||||
          .loadFuture(context, dto: widget.dto);
 | 
			
		||||
    }
 | 
			
		||||
    super.didUpdateWidget(oldWidget);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
    super.initState();
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										56
									
								
								frontend/lib/components/aur_search_table.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								frontend/lib/components/aur_search_table.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,56 @@
 | 
			
		||||
import 'package:aurcache/api/packages.dart';
 | 
			
		||||
import 'package:aurcache/models/aur_package.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:go_router/go_router.dart';
 | 
			
		||||
import '../api/API.dart';
 | 
			
		||||
import '../constants/color_constants.dart';
 | 
			
		||||
import 'confirm_popup.dart';
 | 
			
		||||
 | 
			
		||||
class AurSearchTable extends StatelessWidget {
 | 
			
		||||
  const AurSearchTable({super.key, required this.data});
 | 
			
		||||
  final List<AurPackage> data;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return DataTable(
 | 
			
		||||
        horizontalMargin: 0,
 | 
			
		||||
        columnSpacing: defaultPadding,
 | 
			
		||||
        columns: const [
 | 
			
		||||
          DataColumn(
 | 
			
		||||
            label: Text("Package Name"),
 | 
			
		||||
          ),
 | 
			
		||||
          DataColumn(
 | 
			
		||||
            label: Text("Version"),
 | 
			
		||||
          ),
 | 
			
		||||
          DataColumn(
 | 
			
		||||
            label: Text("Action"),
 | 
			
		||||
          ),
 | 
			
		||||
        ],
 | 
			
		||||
        rows:
 | 
			
		||||
            data.map((e) => buildDataRow(e, context)).toList(growable: false));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  DataRow buildDataRow(AurPackage package, BuildContext context) {
 | 
			
		||||
    return DataRow(
 | 
			
		||||
      cells: [
 | 
			
		||||
        DataCell(Text(package.name)),
 | 
			
		||||
        DataCell(Text(package.version.toString())),
 | 
			
		||||
        DataCell(
 | 
			
		||||
          TextButton(
 | 
			
		||||
            child: const Text("Install", style: TextStyle(color: greenColor)),
 | 
			
		||||
            onPressed: () async {
 | 
			
		||||
              final confirmResult = await showConfirmationDialog(
 | 
			
		||||
                  context,
 | 
			
		||||
                  "Install Package?",
 | 
			
		||||
                  "Are you sure to install Package: ${package.name}", () async {
 | 
			
		||||
                await API.addPackage(name: package.name);
 | 
			
		||||
                context.go("/");
 | 
			
		||||
              }, null);
 | 
			
		||||
              if (!confirmResult) return;
 | 
			
		||||
            },
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
      ],
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,6 +1,12 @@
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
Future<bool> showDeleteConfirmationDialog(BuildContext context) async {
 | 
			
		||||
Future<bool> showConfirmationDialog(
 | 
			
		||||
  BuildContext context,
 | 
			
		||||
  String title,
 | 
			
		||||
  String content,
 | 
			
		||||
  void Function() successCallback,
 | 
			
		||||
  void Function()? errorCallback,
 | 
			
		||||
) async {
 | 
			
		||||
  return (await showDialog<bool>(
 | 
			
		||||
    context: context,
 | 
			
		||||
    barrierDismissible: false,
 | 
			
		||||
@@ -17,20 +23,24 @@ Future<bool> showDeleteConfirmationDialog(BuildContext context) async {
 | 
			
		||||
          ),
 | 
			
		||||
          // Delete confirmation dialog
 | 
			
		||||
          AlertDialog(
 | 
			
		||||
            title: Text('Confirm Delete'),
 | 
			
		||||
            content: Text('Are you sure you want to delete this item?'),
 | 
			
		||||
            title: Text(title),
 | 
			
		||||
            content: Text(content),
 | 
			
		||||
            actions: <Widget>[
 | 
			
		||||
              TextButton(
 | 
			
		||||
                onPressed: () {
 | 
			
		||||
                  Navigator.of(context).pop(true);
 | 
			
		||||
                  successCallback();
 | 
			
		||||
                },
 | 
			
		||||
                child: Text('Yes, Delete'),
 | 
			
		||||
                child: const Text('Yes'),
 | 
			
		||||
              ),
 | 
			
		||||
              TextButton(
 | 
			
		||||
                onPressed: () {
 | 
			
		||||
                  Navigator.of(context).pop(false); // Dismiss dialog
 | 
			
		||||
                  if (errorCallback != null) {
 | 
			
		||||
                    errorCallback();
 | 
			
		||||
                  }
 | 
			
		||||
                },
 | 
			
		||||
                child: Text('Cancel'),
 | 
			
		||||
                child: const Text('Cancel'),
 | 
			
		||||
              ),
 | 
			
		||||
            ],
 | 
			
		||||
          ),
 | 
			
		||||
 
 | 
			
		||||
@@ -87,19 +87,18 @@ class PackagesTable extends StatelessWidget {
 | 
			
		||||
                child: const Text("Delete",
 | 
			
		||||
                    style: TextStyle(color: Colors.redAccent)),
 | 
			
		||||
                onPressed: () async {
 | 
			
		||||
                  final confirmResult =
 | 
			
		||||
                      await showDeleteConfirmationDialog(context);
 | 
			
		||||
                  if (!confirmResult) return;
 | 
			
		||||
 | 
			
		||||
                  final succ = await API.deletePackage(package.id);
 | 
			
		||||
                  if (succ) {
 | 
			
		||||
                    Provider.of<PackagesProvider>(context, listen: false)
 | 
			
		||||
                        .refresh(context);
 | 
			
		||||
                    Provider.of<BuildsProvider>(context, listen: false)
 | 
			
		||||
                        .refresh(context);
 | 
			
		||||
                    Provider.of<StatsProvider>(context, listen: false)
 | 
			
		||||
                        .refresh(context);
 | 
			
		||||
                  }
 | 
			
		||||
                  await showConfirmationDialog(context, "Delete Package",
 | 
			
		||||
                      "Are you sure to delete this Package?", () async {
 | 
			
		||||
                    final succ = await API.deletePackage(package.id);
 | 
			
		||||
                    if (succ) {
 | 
			
		||||
                      Provider.of<PackagesProvider>(context, listen: false)
 | 
			
		||||
                          .refresh(context);
 | 
			
		||||
                      Provider.of<BuildsProvider>(context, listen: false)
 | 
			
		||||
                          .refresh(context);
 | 
			
		||||
                      Provider.of<StatsProvider>(context, listen: false)
 | 
			
		||||
                          .refresh(context);
 | 
			
		||||
                    }
 | 
			
		||||
                  }, null);
 | 
			
		||||
                },
 | 
			
		||||
              ),
 | 
			
		||||
            ],
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,4 @@
 | 
			
		||||
import 'package:aurcache/screens/aur_screen.dart';
 | 
			
		||||
import 'package:aurcache/screens/build_screen.dart';
 | 
			
		||||
import 'package:aurcache/screens/builds_screen.dart';
 | 
			
		||||
import 'package:aurcache/screens/dashboard_screen.dart';
 | 
			
		||||
@@ -40,6 +41,10 @@ final appRouter = GoRouter(
 | 
			
		||||
          path: '/packages',
 | 
			
		||||
          builder: (context, state) => const PackagesScreen(),
 | 
			
		||||
        ),
 | 
			
		||||
        GoRoute(
 | 
			
		||||
          path: '/aur',
 | 
			
		||||
          builder: (context, state) => AurScreen(),
 | 
			
		||||
        ),
 | 
			
		||||
        GoRoute(
 | 
			
		||||
          path: '/package/:id',
 | 
			
		||||
          builder: (context, state) {
 | 
			
		||||
 
 | 
			
		||||
@@ -43,12 +43,16 @@ class SideMenu extends StatelessWidget {
 | 
			
		||||
            DrawerListTile(
 | 
			
		||||
              title: "Builds",
 | 
			
		||||
              svgSrc: "assets/icons/menu_tran.svg",
 | 
			
		||||
              press: () {},
 | 
			
		||||
              press: () {
 | 
			
		||||
                context.go("/builds");
 | 
			
		||||
              },
 | 
			
		||||
            ),
 | 
			
		||||
            DrawerListTile(
 | 
			
		||||
              title: "AUR",
 | 
			
		||||
              svgSrc: "assets/icons/menu_task.svg",
 | 
			
		||||
              press: () {},
 | 
			
		||||
              press: () {
 | 
			
		||||
                context.go("/aur");
 | 
			
		||||
              },
 | 
			
		||||
            ),
 | 
			
		||||
            DrawerListTile(
 | 
			
		||||
              title: "Settings",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user