2024-04-05 15:14:56 +00:00
|
|
|
// This project is not supposed to be cross-platform,
|
2024-04-04 16:15:30 +00:00
|
|
|
// so we don't care about this warning
|
|
|
|
// ignore: avoid_web_libraries_in_flutter
|
2024-04-04 14:35:33 +00:00
|
|
|
import 'dart:html';
|
|
|
|
|
2024-03-26 16:17:04 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-04-05 15:14:56 +00:00
|
|
|
import 'package:softplayer_web/api/grpc/accounts.dart';
|
2024-04-04 14:35:33 +00:00
|
|
|
import 'package:softplayer_web/components/sign_in_form.dart';
|
2024-04-04 21:40:00 +00:00
|
|
|
import 'package:softplayer_web/components/sign_up_form.dart';
|
2024-03-26 16:17:04 +00:00
|
|
|
|
2024-03-27 21:07:53 +00:00
|
|
|
class MenuPanel extends StatefulWidget implements PreferredSizeWidget {
|
2024-03-26 16:17:04 +00:00
|
|
|
final TabName tab;
|
2024-04-05 15:14:56 +00:00
|
|
|
final AccountsGrpc accountsGrpc;
|
|
|
|
const MenuPanel({
|
|
|
|
super.key,
|
|
|
|
required this.tab,
|
|
|
|
required this.accountsGrpc,
|
|
|
|
}) : preferredSize = const Size.fromHeight(kToolbarHeight);
|
2024-03-26 16:17:04 +00:00
|
|
|
@override
|
2024-04-04 16:15:30 +00:00
|
|
|
final Size preferredSize;
|
2024-03-26 16:17:04 +00:00
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _MenuPanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
enum TabName { home, catalog, about }
|
|
|
|
|
|
|
|
class _MenuPanel extends State<MenuPanel> {
|
2024-04-04 14:35:33 +00:00
|
|
|
bool isSignedIn() {
|
|
|
|
return window.localStorage.containsKey("token");
|
|
|
|
}
|
2024-04-04 16:15:30 +00:00
|
|
|
|
2024-04-04 14:35:33 +00:00
|
|
|
List<Widget> accountActions() {
|
|
|
|
if (isSignedIn()) {
|
|
|
|
return [
|
|
|
|
IconButton(
|
|
|
|
onPressed: () => print("acc"),
|
|
|
|
icon: const Icon(Icons.account_circle))
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
return <Widget>[
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
2024-04-05 15:14:56 +00:00
|
|
|
builder: (BuildContext context) => SignInForm(
|
|
|
|
accountsGrpc: widget.accountsGrpc,
|
|
|
|
));
|
2024-04-04 14:35:33 +00:00
|
|
|
},
|
|
|
|
child: const Text("sign in")),
|
2024-04-04 16:15:30 +00:00
|
|
|
TextButton(
|
2024-04-04 21:40:00 +00:00
|
|
|
onPressed: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
2024-04-05 15:14:56 +00:00
|
|
|
builder: (BuildContext context) => SignUpForm(
|
2024-04-19 11:19:44 +00:00
|
|
|
accountsGrpc: widget.accountsGrpc,
|
|
|
|
));
|
2024-04-04 21:40:00 +00:00
|
|
|
},
|
|
|
|
child: const Text("sign up")),
|
2024-04-04 14:35:33 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-26 16:17:04 +00:00
|
|
|
@override
|
|
|
|
PreferredSizeWidget build(BuildContext context) {
|
|
|
|
return AppBar(
|
2024-03-27 21:07:53 +00:00
|
|
|
title: Row(children: [
|
2024-03-26 16:17:04 +00:00
|
|
|
TextButton(
|
|
|
|
child: const Text("Softplayer"),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pushNamed(context, "/");
|
|
|
|
}),
|
2024-03-27 21:07:53 +00:00
|
|
|
]),
|
2024-04-04 21:40:00 +00:00
|
|
|
backgroundColor: const Color.fromRGBO(46, 51, 78, 1.0),
|
2024-04-04 14:35:33 +00:00
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
actions: accountActions(),
|
2024-03-27 21:07:53 +00:00
|
|
|
);
|
2024-03-26 16:17:04 +00:00
|
|
|
}
|
|
|
|
}
|