Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,30 @@
"poll": "Poll",
"addChoice": "Add choice",
"pollDuration": "Poll duration",
"pollDuration_minutes": "{count} {count, plural, =1{minute} other{minutes}}",
"@pollDuration_minutes": {
"placeholders": {
"count": {
"type": "int"
}
}
},
"pollDuration_hours": "{count} {count, plural, =1{hour} other{hours}}",
"@pollDuration_hours": {
"placeholders": {
"count": {
"type": "int"
}
}
},
"pollDuration_days": "{count} {count, plural, =1{day} other{days}}",
"@pollDuration_days": {
"placeholders": {
"count": {
"type": "int"
}
}
},
"pollMode": "Allow multiple selections",
"pollShowResults": "Show results",
"pollHideResults": "Hide results",
Expand All @@ -545,6 +569,38 @@
}
}
},
"pollExpiry_days": "{count} {count, plural, =1{day} other{days}} left",
"@pollExpiry_days": {
"placeholders": {
"count": {
"type": "int"
}
}
},
"pollExpiry_hours": "{count} {count, plural, =1{hour} other{hours}} left",
"@pollExpiry_hours": {
"placeholders": {
"count": {
"type": "int"
}
}
},
"pollExpiry_minutes": "{count} {count, plural, =1{minute} other{minutes}} left",
"@pollExpiry_minutes": {
"placeholders": {
"count": {
"type": "int"
}
}
},
"pollExpiry_seconds": "{count} {count, plural, =1{second} other{seconds}} left",
"@pollExpiry_seconds": {
"placeholders": {
"count": {
"type": "int"
}
}
},
"action_setLocation": "Set Action Location",
"action_hide": "Hide",
"action_appBar": "App Bar",
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/poll.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class PollModel with _$PollModel {

return PollModel(
postId: postId,
endPoll: DateTime.parse(json['end_poll'] as String),
endPoll: DateTime.parse(json['end_poll'] as String).toLocal(),
multiple: (json['mode'] as String) == 'multiple',
localOnly: json['local_only'] as bool,
choices: choices.map((choice) =>
Expand Down
64 changes: 41 additions & 23 deletions lib/src/screens/feed/create_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:any_link_preview/any_link_preview.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
Expand All @@ -21,6 +23,7 @@ import 'package:interstellar/src/widgets/tags/post_flairs.dart';
import 'package:interstellar/src/widgets/tags/tag_widget.dart';
import 'package:interstellar/src/widgets/selection_menu.dart';
import 'package:interstellar/src/widgets/text_editor.dart';
import 'package:interstellar/src/widgets/wrapper.dart';
import 'package:material_symbols_icons/symbols.dart';
import 'package:provider/provider.dart';

Expand Down Expand Up @@ -59,7 +62,7 @@ class _CreateScreenState extends State<CreateScreen> {
TextEditingController(text: 'Option 0'),
];
bool _pollModeMultiple = false;
Duration _pollDuration = Duration();
Duration _pollDuration = Duration(days: 3);

@override
void initState() {
Expand Down Expand Up @@ -241,21 +244,36 @@ class _CreateScreenState extends State<CreateScreen> {

Widget pollOptionsWidget() => Column(
children: [
..._pollOptions.map(
(option) => Padding(
padding: const EdgeInsets.all(5),
child: Row(
children: [
Expanded(child: TextEditor(option)),
IconButton(
onPressed: () => setState(() {
_pollOptions.remove(option);
}),
icon: const Icon(Symbols.delete_rounded),
),
],
ReorderableListView.builder(
shrinkWrap: true,
itemBuilder: (context, index) => ListTile(
key: Key(index.toString()),
title: TextEditor(_pollOptions[index]),
trailing: Wrapper(
shouldWrap: Platform.isIOS || Platform.isAndroid,
parentBuilder: (child) => Row(
mainAxisSize: MainAxisSize.min,
children: [
child,
const Icon(Symbols.drag_handle_rounded)
],
),
child: IconButton(
onPressed: () => setState(() {
_pollOptions.remove(_pollOptions[index]);
}),
icon: const Icon(Symbols.delete_rounded),
)
),
),
),
itemCount: _pollOptions.length,
onReorder: (int oldIndex, int newIndex) => setState(() {
if (oldIndex < newIndex) {
newIndex -= 1;
}
final item = _pollOptions.removeAt(oldIndex);
_pollOptions.insert(newIndex, item);
})
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
Expand Down Expand Up @@ -599,12 +617,12 @@ class _CreateScreenState extends State<CreateScreen> {

SelectionMenu<Duration?> pollDuration(BuildContext context) =>
SelectionMenu(l(context).pollDuration, [
SelectionMenuItem(value: Duration(minutes: 30), title: '30 minutes'),
SelectionMenuItem(value: Duration(hours: 1), title: '1 hour'),
SelectionMenuItem(value: Duration(hours: 6), title: '6 hours'),
SelectionMenuItem(value: Duration(hours: 12), title: '12 hours'),
SelectionMenuItem(value: Duration(days: 1), title: '1 day'),
SelectionMenuItem(value: Duration(days: 3), title: '3 days'),
SelectionMenuItem(value: Duration(days: 7), title: '7 days'),
SelectionMenuItem(value: Duration(), title: 'Unlimited'),
SelectionMenuItem(value: Duration(minutes: 30), title: l(context).pollDuration_minutes(30)),
SelectionMenuItem(value: Duration(hours: 1), title: l(context).pollDuration_hours(1)),
SelectionMenuItem(value: Duration(hours: 6), title: l(context).pollDuration_hours(6)),
SelectionMenuItem(value: Duration(hours: 12), title: l(context).pollDuration_hours(12)),
SelectionMenuItem(value: Duration(days: 1), title: l(context).pollDuration_days(1)),
SelectionMenuItem(value: Duration(days: 3), title: l(context).pollDuration_days(3)),
SelectionMenuItem(value: Duration(days: 7), title: l(context).pollDuration_days(7)),
SelectionMenuItem(value: Duration(days: 365), title: l(context).pollDuration_days(365)),
]);
32 changes: 30 additions & 2 deletions lib/src/widgets/content_item/poll.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,29 @@ class _PollState extends State<Poll> {
_choices = widget.poll.choices.toList();
final answer = _choices.firstWhereOrNull((choice) => choice.chosen);
_selectedAnswer = answer?.id;
_submitted = whenLoggedIn(context, answer != null) ?? true;

final expired = widget.poll.endPoll.isBefore(DateTime.now());
_submitted = (whenLoggedIn(context, answer != null) ?? true) || expired;
}

String getTimeTillExpire() {
final diff = widget.poll.endPoll.difference(DateTime.now());

final days = diff.inDays;
final hours = diff.inHours;
final minutes = diff.inMinutes;
final seconds = diff.inSeconds;

if (days.abs() != 0) {
return l(context).pollExpiry_days(days);
}
if (hours.abs() != 0) {
return l(context).pollExpiry_hours(hours);
}
if (minutes.abs() != 0) {
return l(context).pollExpiry_minutes(minutes);
}
return l(context).pollExpiry_seconds(seconds);
}

@override
Expand Down Expand Up @@ -124,7 +146,13 @@ class _PollState extends State<Poll> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(l(context).pollVotes(totalVotes)),
Row(
children: [
Text(l(context).pollVotes(totalVotes)),
const SizedBox(width: 10),
Text(getTimeTillExpire()),
],
),
if (!_submitted)
ElevatedButton(
onPressed: () async {
Expand Down