Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ivofernandes committed Dec 30, 2022
2 parents 97772b7 + a62bbdf commit c9224e6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const String apiBaseUrl = 'https://www.tabnews.com.br/api/v1';
const String baseUrl = 'https://www.tabnews.com.br';
const int pageSize = 30;
const int pageSize = 30;
11 changes: 10 additions & 1 deletion lib/page/content/content_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import 'package:tabnews/page/content/content_widgets/post_body.dart';
import 'package:tabnews/service/api_content.dart';
import 'package:tabnews/service/messenger.dart';
import 'package:tabnews/service/storage.dart';
import 'package:tabnews/service/user_features.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:url_launcher/url_launcher.dart';

class ContentViewPage extends StatefulWidget {
const ContentViewPage({
Expand All @@ -27,6 +30,7 @@ class _ContentViewPageState extends State<ContentViewPage> {
StorageService storage = StorageService();

MessengerService messengerService = MessengerService();
UserFeaturesService userFeaturesService = UserFeaturesService();

ApiContent apiContent = ApiContent();

Expand Down Expand Up @@ -62,7 +66,12 @@ class _ContentViewPageState extends State<ContentViewPage> {

Future<void> getParams() async {
final String userId = await storage.sharedPreferencesGet('user_id', '');
if (userId == widget.contentData.ownerId!) {

final bool canEditAndDeleteContentOthers =
await userFeaturesService.hasFeature('update:content:others');

if (userId == widget.contentData.ownerId! ||
canEditAndDeleteContentOthers) {
setState(() {
canEdit = true;
});
Expand Down
4 changes: 4 additions & 0 deletions lib/page/login_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:tabnews/model/user.dart';
import 'package:tabnews/page/register_page.dart';
Expand Down Expand Up @@ -52,6 +54,8 @@ class _LoginPageState extends State<LoginPage> {

await storage.sharedPreferencesAddString('user_id', user.id);
await storage.sharedPreferencesAddString('user_username', user.username);
await storage.sharedPreferencesAddString(
'user_features', jsonEncode(user.features));

messengerService.show(context, text: 'Logado com sucesso!');
Navigator.of(context).pop();
Expand Down
17 changes: 17 additions & 0 deletions lib/service/user_features.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'dart:convert';

import 'package:tabnews/service/storage.dart';

class UserFeaturesService {
StorageService storage = StorageService();

dynamic getFeatureList() async =>
await storage.sharedPreferencesGet('user_features', '');

Future<bool> hasFeature(String feature) async {
final String data = await storage.sharedPreferencesGet('user_features', '');
final List<dynamic> featureList = jsonDecode(data);

return featureList.contains(feature);
}
}

0 comments on commit c9224e6

Please sign in to comment.