Fakultas Ilmu Komputer UI

Commit 4e545b17 authored by Dzaky Noor Hasyim's avatar Dzaky Noor Hasyim
Browse files

Merge branch 'dev-putsal' of...

Merge branch 'dev-putsal' of https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/sosial/bisago/bisago-fe into dev-noor
parents f93d3b87 ebd90b71
import 'dart:async';
import 'package:bisaGo/model/komentar_posting_kegiatan.dart';
import 'package:bisaGo/network/data/network_model.dart';
import 'package:bisaGo/repository/komentar_posting_kegiatan_repository.dart';
import 'package:get_it/get_it.dart';
import 'package:http/http.dart';
class KomentarPostingKegiatanBloc {
KomentarPostingKegiatanRepository _komentarPostingKegiatanRepository;
StreamController _komentarPostingKegiatanListController;
List<KomentarPostingKegiatanModel> allKomentarPositngKegiatanFromApi;
StreamSink<NetworkModel<KomentarPostingKegiatanList>> get komentarPostingKegiatanListSink =>
_komentarPostingKegiatanListController.sink;
Stream<NetworkModel<KomentarPostingKegiatanList>> get komentarPostingKegiatanListStream =>
_komentarPostingKegiatanListController.stream;
KomentarPostingKegiatanBloc(String namaLokasi, int id) {
_komentarPostingKegiatanListController =
StreamController<NetworkModel<KomentarPostingKegiatanList>>();
_komentarPostingKegiatanRepository =
GetIt.instance.get<BaseKomentarPostingKegiatanRepository>();
fetchKomentarPostingKegiatanList(namaLokasi, id);
}
Future<void> fetchKomentarPostingKegiatanList(String namaLokasi, int id) async {
komentarPostingKegiatanListSink.add(NetworkModel.loading('Getting Komentar'));
try {
final komentarPostingKegiatanListResponse =
await _komentarPostingKegiatanRepository.fetchKomentarPostingKegiatan(namaLokasi, id);
allKomentarPositngKegiatanFromApi =
List.from(komentarPostingKegiatanListResponse.allKomentarKegiatan);
komentarPostingKegiatanListSink
.add(NetworkModel.completed(komentarPostingKegiatanListResponse));
} catch (e) {
komentarPostingKegiatanListSink.add(NetworkModel.error(e.toString()));
}
}
Future<dynamic> addKomentarPostingKegiatan(
Map<String, dynamic> newKomentarPostingKegiatanData,
String namaLokasi,
int id) async {
try {
return await _komentarPostingKegiatanRepository.createKomentarPostingKegiatan(
newKomentarPostingKegiatanData, namaLokasi, id);
} catch (e) {
return Response('Failed to add komentar', 400);
}
}
void resetKomentarPostingKegiatanList() {
komentarPostingKegiatanListSink.add(
NetworkModel.completed(KomentarPostingKegiatanList(allKomentarPositngKegiatanFromApi)));
}
void dispose() {
_komentarPostingKegiatanListController?.close();
}
}
import 'package:bisaGo/repository/kegiatan_repository.dart'; import 'package:bisaGo/repository/kegiatan_repository.dart';
import 'package:bisaGo/repository/komentar_posting_kegiatan_repository.dart';
import 'package:bisaGo/repository/komentar_posting_repository.dart'; import 'package:bisaGo/repository/komentar_posting_repository.dart';
import 'package:bisaGo/repository/komentar_repository.dart'; import 'package:bisaGo/repository/komentar_repository.dart';
import 'package:bisaGo/repository/komunitas_repository.dart'; import 'package:bisaGo/repository/komunitas_repository.dart';
...@@ -23,11 +22,13 @@ class AppGetIt { ...@@ -23,11 +22,13 @@ class AppGetIt {
() => KomentarRepository()); () => KomentarRepository());
_getIt.registerLazySingleton<BaseKomentarPostingRepository>( _getIt.registerLazySingleton<BaseKomentarPostingRepository>(
() => KomentarPostingRepository()); () => KomentarPostingRepository());
_getIt _getIt.registerLazySingleton<BaseKomentarPostingKegiatanRepository>(
.registerLazySingleton<BaseLokasiRepository>(() => LokasiRepository()); () => KomentarPostingKegiatanRepository());
_getIt _getIt.registerLazySingleton<BaseLokasiRepository>(
.registerLazySingleton<BaseLayananRepository>(() => LayananRepository()); () => LokasiRepository());
_getIt _getIt.registerLazySingleton<BaseLayananRepository>(
.registerLazySingleton<BaseKegiatanRepository>(() => KegiatanRepository()); () => LayananRepository());
_getIt.registerLazySingleton<BaseKegiatanRepository>(
() => KegiatanRepository());
} }
} }
import 'package:json_annotation/json_annotation.dart';
import 'package:bisaGo/config/custom_serializer.dart';
part 'komentar_posting_kegiatan.g.dart';
@JsonSerializable()
class KomentarPostingKegiatanList {
final List<KomentarPostingKegiatanModel> allKomentarKegiatan;
KomentarPostingKegiatanList(this.allKomentarKegiatan);
}
@JsonSerializable()
class KomentarPostingKegiatanModel {
final int id;
final String creator;
final String deskripsi;
@JsonKey(name: 'created', fromJson: CustomSerializer.stringToDateTime)
final DateTime created;
KomentarPostingKegiatanModel(
{this.id,
this.creator,
this.deskripsi,
this.created}
);
factory KomentarPostingKegiatanModel.fromJson(Map<String, dynamic> json) =>
_$KomentarPostingKegiatanModelFromJson(json);
Map<String, dynamic> toJson() => _$KomentarPostingKegiatanModelToJson(this);
}
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'komentar_posting_kegiatan.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
KomentarPostingKegiatanList _$KomentarPostingKegiatanListFromJson(
Map<String, dynamic> json) {
return KomentarPostingKegiatanList(
(json['allKomentarKegiatan'] as List)
?.map((e) => e == null
? null
: KomentarPostingKegiatanModel.fromJson(e as Map<String, dynamic>))
?.toList(),
);
}
Map<String, dynamic> _$KomentarPostingKegiatanListToJson(
KomentarPostingKegiatanList instance) =>
<String, dynamic>{
'allKomentarKegiatan': instance.allKomentarKegiatan,
};
KomentarPostingKegiatanModel _$KomentarPostingKegiatanModelFromJson(
Map<String, dynamic> json) {
return KomentarPostingKegiatanModel(
id: json['id'] as int,
creator: json['creator'] as String,
deskripsi: json['deskripsi'] as String,
created: CustomSerializer.stringToDateTime(json['created'] as String)
);
}
Map<String, dynamic> _$KomentarPostingKegiatanModelToJson(
KomentarPostingKegiatanModel instance) =>
<String, dynamic>{
'id': instance.id,
'creator': instance.creator,
'deskripsi': instance.deskripsi,
'created': instance.created?.toIso8601String(),
};
// import 'package:bisaGo/config/strings.dart'; import 'package:bisaGo/config/styles.dart';
import 'package:bisaGo/model/lokasi.dart'; import 'package:bisaGo/model/lokasi.dart';
import 'package:bisaGo/model/kegiatan.dart';
import 'package:bisaGo/page/filter_fasilitas/postingan/detail_post_kegiatan.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
// import 'package:bisaGo/component/image_holder.dart'; // import 'package:bisaGo/component/image_holder.dart';
import 'package:bisaGo/config/styles.dart';
import 'package:bisaGo/model/kegiatan.dart';
class Kegiatan extends StatefulWidget { class Kegiatan extends StatefulWidget {
final Lokasi lokasi; final Lokasi lokasi;
...@@ -24,7 +24,25 @@ class _KegiatanState extends State<Kegiatan> { ...@@ -24,7 +24,25 @@ class _KegiatanState extends State<Kegiatan> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return InkWell( return InkWell(
// key: Key('Kegiatan'), key: Key('Kegiatan'),
onTap: () {
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (BuildContext context) => DetailPostKegiatanPage(
lokasi: widget.lokasi,
kegiatan: KegiatanModel(
id: widget.kegiatan.id,
namaLokasi: widget.lokasi.name,
creator: widget.kegiatan.creator,
namaKegiatan: widget.kegiatan.namaKegiatan,
penyelenggara: widget.kegiatan.penyelenggara,
narahubung: widget.kegiatan.narahubung,
deskripsi: widget.kegiatan.deskripsi,
timeStart: widget.kegiatan.timeStart,
timeEnd: widget.kegiatan.timeEnd
),
)
));
},
child: Container( child: Container(
margin: const EdgeInsets.only(bottom: regularSpace), margin: const EdgeInsets.only(bottom: regularSpace),
padding: const EdgeInsets.all(doubleSpace), padding: const EdgeInsets.all(doubleSpace),
......
import 'dart:async'; import 'dart:async';
import 'package:bisaGo/config/strings.dart';
import 'package:bisaGo/model/kegiatan.dart'; import 'package:bisaGo/model/kegiatan.dart';
import 'package:bisaGo/model/lokasi.dart'; import 'package:bisaGo/model/lokasi.dart';
import 'package:bisaGo/page/filter_fasilitas/fasilitas.dart'; // import 'package:bisaGo/page/updateInformasi/update_informasi.dart';
import 'package:bisaGo/page/updateInformasi/update_informasi.dart';
import 'package:bisaGo/utils/validator.dart'; import 'package:bisaGo/utils/validator.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:bisaGo/bloc/komentar_posting_bloc.dart'; import 'package:bisaGo/bloc/komentar_posting_kegiatan_bloc.dart';
import 'package:bisaGo/component/image_holder.dart'; import 'package:bisaGo/component/image_holder.dart';
import 'package:bisaGo/component/bisago_appbar.dart'; import 'package:bisaGo/component/bisago_appbar.dart';
import 'package:bisaGo/config/styles.dart'; import 'package:bisaGo/config/styles.dart';
import 'package:bisaGo/model/komentar.dart'; import 'package:bisaGo/model/komentar_posting_kegiatan.dart';
import 'package:bisaGo/model/komentar_posting.dart';
import 'package:bisaGo/network/data/network_model.dart'; import 'package:bisaGo/network/data/network_model.dart';
import 'package:bisaGo/page/login/login.dart'; import 'package:bisaGo/page/login/login.dart';
import 'package:share/share.dart'; import 'package:share/share.dart';
...@@ -25,28 +22,23 @@ class DetailPostKegiatanPage extends StatefulWidget { ...@@ -25,28 +22,23 @@ class DetailPostKegiatanPage extends StatefulWidget {
final Lokasi lokasi; final Lokasi lokasi;
final KegiatanModel kegiatan; // ganti model x // sudah final KegiatanModel kegiatan; // ganti model x // sudah
const DetailPostKegiatanPage( const DetailPostKegiatanPage(
{@required this.lokasi, @required this.kegiatan, Key key}) {@required this.kegiatan, @required this.lokasi, Key key})
: super(key: key); : super(key: key);
@override @override
_DetailPostKegiatanPageState createState() => _DetailPostKegiatanPageState(); _DetailPostKegiatanPageState createState() => _DetailPostKegiatanPageState();
} }
class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> { class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
Map<String, dynamic> newKomentarPostingData = {}; Map<String, dynamic> newKomentarPostingKegiatanData = {};
KomentarPostingBloc _bloc; KomentarPostingKegiatanBloc _bloc;
List<KomentarPostingModel> allKomentarPostingFromApi; List<KomentarPostingKegiatanModel> allKomentarPositngKegiatanFromApi;
TextEditingController komentarController = TextEditingController(); TextEditingController komentarKegiatanController = TextEditingController();
final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
int like;
int dislike;
int alreadyLikeFlag;
int alreadyDislikeFlag;
@override @override
void initState() { void initState() {
alreadyLikeFlag = 0; allKomentarPositngKegiatanFromApi = [];
alreadyDislikeFlag = 0; _bloc = KomentarPostingKegiatanBloc(widget.lokasi.placeId, widget.kegiatan.id);
allKomentarPostingFromApi = [];
_bloc = KomentarPostingBloc(widget.lokasi.placeId, widget.komentar.id);
super.initState(); super.initState();
} }
...@@ -56,7 +48,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> { ...@@ -56,7 +48,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
child: Scaffold( child: Scaffold(
appBar: BisaGoAppBar( appBar: BisaGoAppBar(
title: widget.kegiatan.namaLokasi, // ganti widget.x.namalokasi // sudah title: widget.kegiatan.namaLokasi, // ganti widget.x.namalokasi // sudah
key: Key('appbar-text-${widget.komentar.namaLokasi}'), key: Key('appbar-text-${widget.kegiatan.namaLokasi}'),
actions: <Widget>[ actions: <Widget>[
InkWell( InkWell(
child: const Icon(Icons.share), child: const Icon(Icons.share),
...@@ -106,53 +98,38 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> { ...@@ -106,53 +98,38 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
], ],
), ),
), ),
PopupMenuButton( // PopupMenuButton(
key: const Key('Button Ubah Informasi'), // key: const Key('Button Ubah Informasi'),
elevation: 4.0, // elevation: 4.0,
offset: const Offset(0.0, 40.0), // offset: const Offset(0.0, 40.0),
itemBuilder: (BuildContext context) { // itemBuilder: (BuildContext context) {
final choices = ['Ubah Informasi']; // final choices = ['Ubah Informasi'];
return choices.map((String choice) { // return choices.map((String choice) {
return PopupMenuItem( // return PopupMenuItem(
key: Key(choice), // key: Key(choice),
child: ElevatedButton( // child: ElevatedButton(
style: ButtonStyle( // style: ButtonStyle(
padding: MaterialStateProperty.all( // padding: MaterialStateProperty.all(
EdgeInsets.symmetric( // EdgeInsets.symmetric(
vertical: 0, horizontal: 0)), // vertical: 0, horizontal: 0)),
backgroundColor: // backgroundColor:
MaterialStateProperty.all(Colors.white), // MaterialStateProperty.all(Colors.white),
foregroundColor: // foregroundColor:
MaterialStateProperty.all(Colors.black), // MaterialStateProperty.all(Colors.black),
elevation: MaterialStateProperty.all(0)), // elevation: MaterialStateProperty.all(0)),
onPressed: _updateInformasi, // onPressed: _updateInformasi,
child: SizedBox( // child: SizedBox(
width: double.infinity, // width: double.infinity,
child: Text(choice), // child: Text(choice),
), // ),
), // ),
); // );
}).toList(); // }).toList();
}, // },
), // ),
], ],
), ),
), ),
// Container(
// key: const Key('Text Jumlah'),
// width: MediaQuery.of(context).size.width,
// color: red,
// padding: const EdgeInsets.symmetric(
// vertical: regularSpace, horizontal: doubleSpace),
// child: Text(
// 'Tersedia sebanyak ${widget.komentar.jumlah} '
// 'unit fasilitas.',
// style: const TextStyle(
// fontSize: 16,
// color: Colors.white,
// fontFamily: 'Comfortaa',
// ),
// )),
Container( Container(
margin: const EdgeInsets.all(doubleSpace), margin: const EdgeInsets.all(doubleSpace),
child: Column( child: Column(
...@@ -161,39 +138,11 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> { ...@@ -161,39 +138,11 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
SizedBox( SizedBox(
height: 150, height: 150,
child: ImageHolder( child: ImageHolder(
url: widget.komentar.image, url: null,
fasilitas: widget.komentar.tag)), fasilitas: null)),
const SizedBox( const SizedBox(
height: 10, height: 10,
), ),
// Wrap(
// alignment: WrapAlignment.start,
// direction: Axis.horizontal,
// crossAxisAlignment: WrapCrossAlignment.start,
// children: widget.komentar.tag
// .map<Widget>((tag) =>
// _createTagContainer(getTag(tag)))
// .toList(),
// ),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: <Widget>[
// const Text(
// 'Dapat digunakan oleh',
// style: TextStyle(fontSize: 16),
// textAlign: TextAlign.left,
// ),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// children: <Widget>[
// _showIfContains('DF'),
// _showIfContains('DI'),
// _showIfContains('DM'),
// _showIfContains('DS'),
// ],
// )
// ],
// ),
Container( Container(
key: const Key('desc'), key: const Key('desc'),
// decoration: BoxDecoration( // decoration: BoxDecoration(
...@@ -328,7 +277,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> { ...@@ -328,7 +277,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
), ),
), ),
StreamBuilder( StreamBuilder(
stream: _bloc.komentarPostingListStream, stream: _bloc.komentarPostingKegiatanListStream,
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.hasData) { if (snapshot.hasData) {
switch (snapshot.data.status) { switch (snapshot.data.status) {
...@@ -340,16 +289,16 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> { ...@@ -340,16 +289,16 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
); );
break; break;
case Status.completed: case Status.completed:
allKomentarPostingFromApi = allKomentarPositngKegiatanFromApi =
snapshot.data.data.allKomentar; snapshot.data.data.allKomentarKegiatan; // kalo error, brarti allKegiatan
if (allKomentarPostingFromApi.isEmpty) { if (allKomentarPositngKegiatanFromApi.isEmpty) {
return const Center( return const Center(
child: Text('Tidak ada komentar')); child: Text('Tidak ada komentar'));
} else { } else {
return Column( return Column(
children: allKomentarPostingFromApi.map<Widget>((k) => children: allKomentarPositngKegiatanFromApi.map<Widget>((k) =>
komentarPlaceHolder( komentarKegiatanPlaceHolder(
k.creator, k.dateTime, k.deskripsi k.creator, k.created, k.deskripsi
) )
).toList() ).toList()
); );
...@@ -376,7 +325,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> { ...@@ -376,7 +325,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
maxLines: null, maxLines: null,
minLines: 3, minLines: 3,
validator: FieldValidator.validateInfo, validator: FieldValidator.validateInfo,
controller: komentarController, controller: komentarKegiatanController,
style: const TextStyle( style: const TextStyle(
fontSize: 18, fontSize: 18,
), ),
...@@ -464,34 +413,34 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> { ...@@ -464,34 +413,34 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
MaterialPageRoute(builder: (BuildContext context) => const Login()), MaterialPageRoute(builder: (BuildContext context) => const Login()),
(Route<dynamic> route) => false); (Route<dynamic> route) => false);
} else { } else {
await _validateKomentarInput(); await _validateKomentarKegiatanInput();
} }
} }
Future<void> _validateKomentarInput() async { Future<void> _validateKomentarKegiatanInput() async {
final form = _formKey.currentState; final form = _formKey.currentState;
if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
form.save(); form.save();
await _submitKomentar(komentarController.text); await _submitKomentarKegiatan(komentarKegiatanController.text);
} }
} }
Future<void> _submitKomentar(String komentar) async { Future<void> _submitKomentarKegiatan(String komentarKegiatan) async {
final _namaLokasi = widget.lokasi.placeId; final _namaLokasi = widget.lokasi.placeId;
newKomentarPostingData['deskripsi'] = komentar; newKomentarPostingKegiatanData['deskripsi'] = komentarKegiatan;
newKomentarPostingData['namaLokasi'] = _namaLokasi; newKomentarPostingKegiatanData['namaLokasi'] = _namaLokasi;
newKomentarPostingData['id'] = widget.komentar.id; newKomentarPostingKegiatanData['id'] = widget.kegiatan.id; // ganti widget.x.id // sudah
_bloc = KomentarPostingBloc(_namaLokasi, widget.komentar.id); _bloc = KomentarPostingKegiatanBloc(_namaLokasi, widget.kegiatan.id); // ganti widget.x.id // sudah
final response = await _bloc.addKomentarPosting( final response = await _bloc.addKomentarPostingKegiatan(
newKomentarPostingData, _namaLokasi, widget.komentar.id); newKomentarPostingKegiatanData, _namaLokasi, widget.kegiatan.id); // ganti widget.x.id // sudah
if (response['response'] == 'komentar added') { if (response['response'] == 'komentar added') {
successDialog(context); successDialog(context);
Timer(const Duration(seconds: 2), () { Timer(const Duration(seconds: 2), () {
Navigator.pop(context); Navigator.pop(context);
}); });
await _bloc.fetchKomentarPostingList(_namaLokasi, widget.komentar.id); await _bloc.fetchKomentarPostingKegiatanList(_namaLokasi, widget.kegiatan.id); // ganti widget.x.id // sudah
komentarController.clear(); komentarKegiatanController.clear();
} else { } else {
failedDialog(context); failedDialog(context);
} }
...@@ -521,7 +470,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> { ...@@ -521,7 +470,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
}); });
} }
Widget komentarPlaceHolder(String name, DateTime date, String description) { Widget komentarKegiatanPlaceHolder(String name, DateTime created, String description) {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
...@@ -545,7 +494,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> { ...@@ -545,7 +494,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
name, name,
style: const TextStyle(fontSize: 18), style: const TextStyle(fontSize: 18),
), ),
Text('${DateForma