1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Can reload survey

This commit is contained in:
Pierre HUBERT 2020-05-18 19:15:16 +02:00
parent e0d69ab504
commit b337e632bd
4 changed files with 25 additions and 4 deletions

View File

@ -8,6 +8,13 @@ import 'package:meta/meta.dart';
/// @author Pierre HUBERT /// @author Pierre HUBERT
class SurveyHelper { class SurveyHelper {
/// Get information about a single survey
static Future<Survey> getSurveyInfo(int postID) async =>
apiToSurvey((await APIRequest.withLogin("surveys/get_info")
.addInt("postID", postID)
.execWithThrow())
.getObject());
/// Cancel the response of a user to a survey /// Cancel the response of a user to a survey
Future<bool> cancelResponse(Survey survey) async { Future<bool> cancelResponse(Survey survey) async {
return (await APIRequest( return (await APIRequest(

View File

@ -34,7 +34,7 @@ class Post implements LikeElement {
bool userLike; bool userLike;
final UserAccessLevels access; final UserAccessLevels access;
final CommentsList comments; final CommentsList comments;
final Survey survey; Survey survey;
Post( Post(
{@required this.id, {@required this.id,

View File

@ -341,6 +341,7 @@ class _PostTileState extends State<PostTile> {
Widget _buildPostSurvey() { Widget _buildPostSurvey() {
return SurveyWidget( return SurveyWidget(
survey: widget.post.survey, survey: widget.post.survey,
onUpdated: (s) => setState(() => widget.post.survey = s),
); );
} }

View File

@ -13,9 +13,14 @@ import 'package:pie_chart/pie_chart.dart';
class SurveyWidget extends StatefulWidget { class SurveyWidget extends StatefulWidget {
final Survey survey; final Survey survey;
final Function(Survey) onUpdated;
const SurveyWidget({Key key, @required this.survey}) const SurveyWidget({
: assert(survey != null), Key key,
@required this.survey,
@required this.onUpdated,
}) : assert(survey != null),
assert(onUpdated != null),
super(key: key); super(key: key);
@override @override
@ -160,6 +165,14 @@ class _SurveyWidgetState extends SafeState<SurveyWidget> {
}); });
} }
/// Reload survey information
///
/// Throws in case of failure
Future<void> _reloadSurvey() async {
final newSurvey = await SurveyHelper.getSurveyInfo(widget.survey.postID);
widget.onUpdated(newSurvey);
}
/// Create a new choice /// Create a new choice
void _createNewChoices() async { void _createNewChoices() async {
try { try {
@ -176,7 +189,7 @@ class _SurveyWidgetState extends SafeState<SurveyWidget> {
await SurveyHelper.createNewChoice(survey.postID, newChoice); await SurveyHelper.createNewChoice(survey.postID, newChoice);
// TODO : reload survey await _reloadSurvey();
} catch (e, s) { } catch (e, s) {
print("Could not create new survey choice! $e\n$s"); print("Could not create new survey choice! $e\n$s");
showSimpleSnack( showSimpleSnack(