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
4 changes: 3 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@setupSelectedInstitution": {},
"setupLinkZotero": "Link Zotero",
"@setupLinkZotero": {},
"setupZoteroLong": "Send publications directly to your Zotero library. They will be added to a special Wispar collection.",
"setupZoteroLong": "Send publications directly to your Zotero library. They will be added to the collection of your choice.",
"@setupZoteroLong": {},
"setupLinkMyZotero": "Link my Zotero account",
"@setupLinkMyZotero": {},
Expand Down Expand Up @@ -512,6 +512,8 @@
"@unhideArticle": {},
"sendToZotero": "Send to Zotero",
"@sendToZotero": {},
"zoteroError":"Unable to send the article to Zotero. Please check the logs for more info.",
"@zoteroError":{},
"zoteroSettings": "Zotero settings",
"@zoteroSettings": {},
"zoteroPermissions1": "Wispar needs both read and write access to your Zotero account to enjoy its integration.",
Expand Down
29 changes: 18 additions & 11 deletions lib/services/zotero_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class ZoteroService {
}
}

static Future<void> createZoteroItem(String apiKey, String userId,
static Future<bool> createZoteroItem(String apiKey, String userId,
ZoteroCollection targetCollection, Map<String, dynamic> itemData) async {
final logger = LogsService().logger;
String url;
Expand All @@ -216,12 +216,14 @@ class ZoteroService {
body: body,
);

if (response.statusCode == 200) {
if (response.statusCode == 200 || response.statusCode == 201) {
return true;
} else {
logger.severe(
"Failed to create Zotero item.",
"Status code:${response.statusCode}",
StackTrace.fromString("Response body: ${response.body}"));
return false;
}
}

Expand Down Expand Up @@ -286,14 +288,19 @@ class ZoteroService {
{'creatorType': 'reviewedAuthor'}
]*/
};
await ZoteroService.createZoteroItem(
bool success = await ZoteroService.createZoteroItem(
apiKey, userId, targetCollection, articleData);

ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(AppLocalizations.of(context)!.zoteroArticleSent),
duration: const Duration(seconds: 1),
));
logger.info("Successfully sent the article to Zotero");
if (success) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(AppLocalizations.of(context)!.zoteroArticleSent),
duration: const Duration(seconds: 1),
));
logger.info("Successfully sent the article to Zotero");
} else {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(AppLocalizations.of(context)!.zoteroError),
));
}
} else {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
Expand All @@ -306,8 +313,8 @@ class ZoteroService {
logger.severe("Failed to send item to Zotero", e, stackTrace);

ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Failed to send to Zotero"),
SnackBar(
content: Text(AppLocalizations.of(context)!.zoteroError),
),
);
}
Expand Down
27 changes: 16 additions & 11 deletions lib/widgets/zotero_bottomsheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:wispar/services/zotero_api.dart';
import 'package:wispar/models/zotero_models.dart';
import 'package:wispar/generated_l10n/app_localizations.dart';
import 'package:wispar/services/logs_helper.dart';

Future<ZoteroCollection?> selectZoteroCollection(
BuildContext context, {
Expand Down Expand Up @@ -218,6 +219,7 @@ class _ZoteroCollectionSheetState extends State<_ZoteroCollectionSheet> {

Future<void> _showCreateDialog() async {
final controller = TextEditingController();
final logger = LogsService().logger;

final name = await showDialog<String>(
context: context,
Expand Down Expand Up @@ -253,17 +255,20 @@ class _ZoteroCollectionSheetState extends State<_ZoteroCollectionSheet> {
);

await _loadCollections();

final created = collections.firstWhere(
(c) => c.name == name,
orElse: () => collections.last,
);

if (!mounted) return;

setState(() {
selectedCollection = created;
});
if (collections.isNotEmpty) {
final created = collections.firstWhere(
(c) => c.name == name,
orElse: () => collections.last,
);

if (!mounted) return;

setState(() {
selectedCollection = created;
});
} else {
logger.warning("Could not select new collection: List is empty.");
}
}

@override
Expand Down
Loading