2024-04-14 10:38:44 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:solian/models/post.dart';
|
|
|
|
import 'package:solian/providers/auth.dart';
|
|
|
|
import 'package:solian/router.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2024-04-16 12:36:47 +00:00
|
|
|
import 'package:solian/screens/posts/comment_editor.dart';
|
2024-05-03 05:39:52 +00:00
|
|
|
import 'package:solian/widgets/posts/post_deletion.dart';
|
2024-04-14 10:38:44 +00:00
|
|
|
|
|
|
|
class PostItemAction extends StatelessWidget {
|
|
|
|
final Post item;
|
|
|
|
final Function? onUpdate;
|
2024-04-15 15:08:32 +00:00
|
|
|
final Function? onDelete;
|
2024-04-14 10:38:44 +00:00
|
|
|
|
2024-04-15 15:08:32 +00:00
|
|
|
const PostItemAction({
|
|
|
|
super.key,
|
|
|
|
required this.item,
|
|
|
|
this.onUpdate,
|
|
|
|
this.onDelete,
|
|
|
|
});
|
2024-04-14 10:38:44 +00:00
|
|
|
|
2024-04-16 12:36:47 +00:00
|
|
|
void viewEditor() async {
|
|
|
|
bool ok = false;
|
|
|
|
switch (item.modelType) {
|
|
|
|
case 'article':
|
2024-05-03 05:39:52 +00:00
|
|
|
ok = await SolianRouter.router.pushNamed(
|
2024-04-16 12:36:47 +00:00
|
|
|
'posts.articles.editor',
|
|
|
|
extra: item,
|
|
|
|
) as bool;
|
|
|
|
case 'moment':
|
2024-05-03 05:39:52 +00:00
|
|
|
ok = await SolianRouter.router.pushNamed(
|
2024-04-16 12:36:47 +00:00
|
|
|
'posts.moments.editor',
|
|
|
|
extra: item,
|
|
|
|
) as bool;
|
|
|
|
case 'comment':
|
2024-05-03 05:39:52 +00:00
|
|
|
ok = await SolianRouter.router.pushNamed(
|
2024-04-16 12:36:47 +00:00
|
|
|
'posts.comments.editor',
|
|
|
|
extra: CommentPostArguments(editing: item),
|
|
|
|
) as bool;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ok == true && onUpdate != null) {
|
|
|
|
onUpdate!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-14 10:38:44 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final auth = context.read<AuthProvider>();
|
|
|
|
|
|
|
|
return SizedBox(
|
2024-04-14 15:00:04 +00:00
|
|
|
height: 320,
|
2024-04-14 10:38:44 +00:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Container(
|
2024-05-10 15:42:59 +00:00
|
|
|
padding: const EdgeInsets.only(left: 20, top: 20, bottom: 8),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
AppLocalizations.of(context)!.action,
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'#${item.id.toString().padLeft(8, '0')}',
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
],
|
2024-04-14 10:38:44 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: FutureBuilder(
|
2024-04-14 15:00:04 +00:00
|
|
|
future: auth.getProfiles(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
final authorizedItems = [
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Icons.edit),
|
|
|
|
title: Text(AppLocalizations.of(context)!.edit),
|
2024-04-16 12:36:47 +00:00
|
|
|
onTap: () => viewEditor(),
|
2024-04-14 15:00:04 +00:00
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Icons.delete),
|
|
|
|
title: Text(AppLocalizations.of(context)!.delete),
|
|
|
|
onTap: () {
|
|
|
|
final dataset = '${item.modelType}s';
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => ItemDeletionDialog(
|
|
|
|
item: item,
|
|
|
|
dataset: dataset,
|
|
|
|
),
|
2024-04-18 15:39:48 +00:00
|
|
|
).then((did) {
|
|
|
|
if (did == true && onDelete != null) onDelete!();
|
|
|
|
});
|
2024-04-14 15:00:04 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
];
|
|
|
|
|
|
|
|
return ListView(
|
|
|
|
children: [
|
2024-04-20 04:06:16 +00:00
|
|
|
...(snapshot.data['id'] == item.author.externalId
|
2024-04-14 15:00:04 +00:00
|
|
|
? authorizedItems
|
|
|
|
: List.empty()),
|
2024-04-14 10:38:44 +00:00
|
|
|
ListTile(
|
2024-04-14 15:00:04 +00:00
|
|
|
leading: const Icon(Icons.report),
|
|
|
|
title: Text(AppLocalizations.of(context)!.report),
|
|
|
|
onTap: () {},
|
2024-04-14 10:38:44 +00:00
|
|
|
)
|
2024-04-14 15:00:04 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2024-04-14 10:38:44 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|