mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Can reload survey
This commit is contained in:
parent
e0d69ab504
commit
b337e632bd
@ -8,6 +8,13 @@ import 'package:meta/meta.dart';
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
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
|
||||
Future<bool> cancelResponse(Survey survey) async {
|
||||
return (await APIRequest(
|
||||
|
@ -34,7 +34,7 @@ class Post implements LikeElement {
|
||||
bool userLike;
|
||||
final UserAccessLevels access;
|
||||
final CommentsList comments;
|
||||
final Survey survey;
|
||||
Survey survey;
|
||||
|
||||
Post(
|
||||
{@required this.id,
|
||||
|
@ -341,6 +341,7 @@ class _PostTileState extends State<PostTile> {
|
||||
Widget _buildPostSurvey() {
|
||||
return SurveyWidget(
|
||||
survey: widget.post.survey,
|
||||
onUpdated: (s) => setState(() => widget.post.survey = s),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,14 @@ import 'package:pie_chart/pie_chart.dart';
|
||||
|
||||
class SurveyWidget extends StatefulWidget {
|
||||
final Survey survey;
|
||||
final Function(Survey) onUpdated;
|
||||
|
||||
const SurveyWidget({Key key, @required this.survey})
|
||||
: assert(survey != null),
|
||||
const SurveyWidget({
|
||||
Key key,
|
||||
@required this.survey,
|
||||
@required this.onUpdated,
|
||||
}) : assert(survey != null),
|
||||
assert(onUpdated != null),
|
||||
super(key: key);
|
||||
|
||||
@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
|
||||
void _createNewChoices() async {
|
||||
try {
|
||||
@ -176,7 +189,7 @@ class _SurveyWidgetState extends SafeState<SurveyWidget> {
|
||||
|
||||
await SurveyHelper.createNewChoice(survey.postID, newChoice);
|
||||
|
||||
// TODO : reload survey
|
||||
await _reloadSurvey();
|
||||
} catch (e, s) {
|
||||
print("Could not create new survey choice! $e\n$s");
|
||||
showSimpleSnack(
|
||||
|
Loading…
Reference in New Issue
Block a user