Comment post

This commit is contained in:
LittleSheep 2024-03-24 12:22:29 +08:00
parent c4157c3e23
commit eb01942e2d
6 changed files with 206 additions and 82 deletions

View File

@ -1,39 +0,0 @@
{
"project_info": {
"project_number": "659822066072",
"project_id": "smartsheep-hydrogen",
"storage_bucket": "smartsheep-hydrogen.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:659822066072:android:39e699282c97a7cfc013ed",
"android_client_info": {
"package_name": "dev.solsynth.solaragent"
}
},
"oauth_client": [
{
"client_id": "659822066072-dde0aqiocn28bc1gk9p5k8oaqe1jpi0l.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyBLPaAK4CVW9umXIdUoGOGHO42jKnwZkKo"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "659822066072-dde0aqiocn28bc1gk9p5k8oaqe1jpi0l.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}

View File

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>API_KEY</key>
<string>AIzaSyBQB4u2KKe1P5jMG_zWGiUFtpcjQKhG3jY</string>
<key>GCM_SENDER_ID</key>
<string>659822066072</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>dev.solsynth.solaragent</string>
<key>PROJECT_ID</key>
<string>smartsheep-hydrogen</string>
<key>STORAGE_BUCKET</key>
<string>smartsheep-hydrogen.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:659822066072:ios:90dff099ef47fc8fc013ed</string>
</dict>
</plist>

View File

@ -1,7 +0,0 @@
{
"file_generated_by": "FlutterFire CLI",
"purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory",
"GOOGLE_APP_ID": "1:659822066072:ios:90dff099ef47fc8fc013ed",
"FIREBASE_PROJECT_ID": "smartsheep-hydrogen",
"GCM_SENDER_ID": "659822066072"
}

View File

@ -1,7 +1,9 @@
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:solaragent/models/feed.dart';
import 'package:solaragent/screens/account.dart'; import 'package:solaragent/screens/account.dart';
import 'package:solaragent/screens/explore.dart'; import 'package:solaragent/screens/explore.dart';
import 'package:solaragent/screens/notifications.dart'; import 'package:solaragent/screens/notifications.dart';
import 'package:solaragent/screens/publish/comment_editor.dart';
import 'package:solaragent/screens/publish/moment_editor.dart'; import 'package:solaragent/screens/publish/moment_editor.dart';
final router = GoRouter( final router = GoRouter(
@ -18,10 +20,14 @@ final router = GoRouter(
path: '/account', path: '/account',
builder: (context, state) => const AccountScreen(), builder: (context, state) => const AccountScreen(),
), ),
GoRoute( GoRoute(
path: '/post/moments', path: '/post/moments',
builder: (context, state) => const MomentEditorScreen(), builder: (context, state) => const MomentEditorScreen(),
), ),
GoRoute(
path: '/post/comments',
builder: (context, state) =>
CommentEditorScreen(parent: state.extra as Feed),
),
], ],
); );

View File

@ -0,0 +1,167 @@
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:solaragent/auth.dart';
import 'package:solaragent/models/feed.dart';
import 'package:solaragent/router.dart';
import 'package:url_launcher/url_launcher.dart';
class CommentEditorScreen extends StatefulWidget {
final Feed parent;
const CommentEditorScreen({super.key, required this.parent});
@override
State<CommentEditorScreen> createState() => _CommentEditorScreenState();
}
class _CommentEditorScreenState extends State<CommentEditorScreen> {
final contentController = TextEditingController();
bool isSubmitting = false;
bool showRecommendationBanner = true;
Future<void> postComment() async {
if (!await authClient.isAuthorized()) return;
var dataset = "${widget.parent.modelType}s";
var alias = widget.parent.alias;
var uri = Uri.parse(
"https://co.solsynth.dev/api/p/$dataset/$alias/comments",
);
setState(() => isSubmitting = true);
var res = await authClient.client!.post(
uri,
headers: <String, String>{
'Content-Type': 'application/json',
},
body: jsonEncode(<String, dynamic>{
'content': contentController.value.text,
}),
);
if (res.statusCode != 200) {
var message = utf8.decode(res.bodyBytes);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Something went wrong... $message")),
);
} else {
if (router.canPop()) {
router.pop();
}
}
setState(() => isSubmitting = false);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Leave a comment"),
actions: <Widget>[
TextButton(
onPressed: !isSubmitting ? postComment : null,
child: const Text('POST'),
),
],
),
body: Column(
children: [
// Loading indicator
isSubmitting ? const LinearProgressIndicator() : Container(),
// Userinfo
FutureBuilder(
future: authClient.getProfiles(),
builder: (context, snapshot) {
if (snapshot.hasData) {
var userinfo = snapshot.data;
return Container(
color: Colors.grey[50],
margin: const EdgeInsets.only(bottom: 12),
child: ListTile(
title: Text(userinfo["nick"]),
subtitle: const Text("You will post this post as"),
leading: CircleAvatar(
backgroundImage: NetworkImage(userinfo["picture"]),
),
),
);
} else {
return Container();
}
}),
// Editor
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: TextField(
maxLines: null,
autofocus: true,
autocorrect: true,
keyboardType: TextInputType.multiline,
controller: contentController,
decoration: const InputDecoration.collapsed(
hintText: "What do you want to say?"),
),
),
),
// Recommend website banner
showRecommendationBanner
? FutureBuilder(
future: SharedPreferences.getInstance(),
builder: (context, snapshot) {
if (snapshot.hasData &&
snapshot.data?.getBool(
"editor.hide_website_recommendation") ==
null) {
snapshot.data
?.remove("editor.hide_website_recommendation");
return MaterialBanner(
padding: const EdgeInsets.all(20),
content: const Text(
'SolarAgent still in early stage development. Some features isn\'t available. We recommend use our website, also optimized for moblie!',
),
leading: const Icon(Icons.construction),
backgroundColor: const Color(0xFFE0E0E0),
actions: <Widget>[
TextButton(
child: const Text('OPEN'),
onPressed: () async {
await launchUrl(
Uri.parse("https://co.solsynth.dev"));
},
),
TextButton(
child: const Text('DISMISS'),
onPressed: () async {
await snapshot.data?.setBool(
"editor.hide_website_recommendation",
true,
);
setState(() {
showRecommendationBanner = false;
});
},
),
],
);
} else {
return Container();
}
})
: Container(),
],
),
);
}
@override
void dispose() {
contentController.dispose();
super.dispose();
}
}

View File

@ -3,8 +3,10 @@ import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:solaragent/auth.dart';
import 'package:solaragent/models/feed.dart'; import 'package:solaragent/models/feed.dart';
import 'package:solaragent/models/pagination.dart'; import 'package:solaragent/models/pagination.dart';
import 'package:solaragent/router.dart';
import 'package:solaragent/widgets/feed.dart'; import 'package:solaragent/widgets/feed.dart';
class CommentListWidget extends StatefulWidget { class CommentListWidget extends StatefulWidget {
@ -69,11 +71,36 @@ class _CommentListWidgetState extends State<CommentListWidget> {
children: [ children: [
Container( Container(
padding: const EdgeInsets.only(left: 10, right: 10, top: 20), padding: const EdgeInsets.only(left: 10, right: 10, top: 20),
child: ListTile( child: Row(
title: Text( mainAxisAlignment: MainAxisAlignment.spaceBetween,
'Comments', children: [
style: Theme.of(context).textTheme.headlineSmall, Padding(
), padding: const EdgeInsets.symmetric(
horizontal: 8.0,
vertical: 12.0,
),
child: Text(
'Comments',
style: Theme.of(context).textTheme.headlineSmall,
),
),
FutureBuilder(
future: authClient.isAuthorized(),
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data == true) {
return TextButton.icon(
icon: const Icon(Icons.edit),
label: const Text("LEAVE COMMENT"),
onPressed: () {
router.push("/post/comments", extra: widget.parent);
},
);
} else {
return Container();
}
},
),
],
), ),
), ),
Expanded( Expanded(