Skip to content

Commit

Permalink
HashTag feature implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush0Chaudhary committed Oct 11, 2023
1 parent 0a6efcb commit 5a85b59
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AddPostViewModel extends BaseModel {
late User _currentUser;
late OrgInfo _selectedOrg;
final TextEditingController _controller = TextEditingController();

final TextEditingController _textHashTagController = TextEditingController();
final TextEditingController _titleController = TextEditingController();

/// The image file that is to be uploaded.
Expand Down Expand Up @@ -66,6 +66,14 @@ class AddPostViewModel extends BaseModel {
/// * `TextEditingController`: The main text controller of the post body
TextEditingController get controller => _controller;

/// hashtag text controller.
///
/// params:
/// None
/// returns:
/// * `TextEditingController`: The main text controller of the hashtag
TextEditingController get textHashTagController => _textHashTagController;

/// Post title text controller.
///
/// params:
Expand Down Expand Up @@ -152,7 +160,7 @@ class AddPostViewModel extends BaseModel {
await _dbFunctions.gqlAuthMutation(
PostQueries().uploadPost(),
variables: {
"text": _controller.text,
"text": "${_controller.text} #${_textHashTagController.text}",
"organizationId": _selectedOrg.id,
"title": _titleController.text,
},
Expand Down
57 changes: 42 additions & 15 deletions lib/views/after_auth_screens/add_post_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:talawa/enums/enums.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/utils/app_localization.dart';
import 'package:talawa/view_model/after_auth_view_models/add_post_view_models/add_post_view_model.dart';
import 'package:talawa/views/base_view.dart';
Expand Down Expand Up @@ -89,22 +91,47 @@ class AddPost extends StatelessWidget {
onPressed: () => model.getImageFromGallery(camera: true),
icon: const Icon(Icons.camera_alt),
),
// button to select file
// IconButton(
// key: const Key('add_post_icon_button4'),
// onPressed: () {
// },
// icon: const Icon(Icons.file_upload),
// ),
// button to add hastags to the post.
// TextButton(
// key: const Key('add_post_text_btn2'),
// onPressed: () {},
// child: Text(
// '# ${AppLocalizations.of(context)!.strictTranslate("Add hashtag")}',
// style: Theme.of(context).textTheme.titleLarge,
// ),
// ),
TextButton(
key: const Key('add_post_text_btn2'),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("Enter the Tag"),
content: TextField(
controller: model.textHashTagController,
),
actions: [
TextButton(
onPressed: () {
navigationService.showTalawaErrorSnackBar(
"The tag was added",
MessageType.info,
);
Navigator.of(context).pop();
},
child: const Text("Add"),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text("Cancel"),
),
],
);
},
);
},
child: Text(
model.textHashTagController.text == ""
? '# ${AppLocalizations.of(context)!.strictTranslate("Add tag")}'
: model.textHashTagController.text,
style: Theme.of(context).textTheme.titleLarge,
),
),
],
),
const Divider(),
Expand Down
39 changes: 32 additions & 7 deletions lib/widgets/post_detailed_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class _DescriptionTextWidgetState extends State<DescriptionTextWidget> {
///
late String secondHalf;

/// tags in the post.
///
late String tag;

//setting the flag to true initially
/// is show more turned on.
///
Expand All @@ -42,8 +46,18 @@ class _DescriptionTextWidgetState extends State<DescriptionTextWidget> {
if (widget.text.length > 150) {
firstHalf = widget.text.substring(0, 150);
secondHalf = widget.text.substring(150, widget.text.length);
tag = "";
} else {
firstHalf = widget.text;
if (widget.text.split("#").length == 2) {
firstHalf = widget.text.split("#")[0];
tag = widget.text.split("#")[1];
} else if (widget.text.split("#").length == 1) {
firstHalf = widget.text;
tag = "";
} else {
firstHalf = widget.text.split("#")[0];
tag = "";
}
secondHalf = "";
}
}
Expand All @@ -53,12 +67,23 @@ class _DescriptionTextWidgetState extends State<DescriptionTextWidget> {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 5.0),
child: secondHalf.isEmpty
? Text(
firstHalf,
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(fontFamily: 'open-sans', color: Colors.black38),
? Column(
children: [
Text(
firstHalf,
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(fontFamily: 'open-sans', color: Colors.black38),
),
tag != ""
? Text(
"# $tag",
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
fontFamily: 'open-sans', color: Colors.black38),
)
: Container(),
],
)
: Column(
children: <Widget>[
Expand Down

0 comments on commit 5a85b59

Please sign in to comment.