Skip to content

Commit

Permalink
feat: support new pret APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatNerdSquared committed Dec 3, 2023
1 parent 5954e62 commit b9faf25
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 43 deletions.
10 changes: 5 additions & 5 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ PODS:
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- SDWebImage (5.18.0):
- SDWebImage/Core (= 5.18.0)
- SDWebImage/Core (5.18.0)
- SDWebImage (5.18.3):
- SDWebImage/Core (= 5.18.3)
- SDWebImage/Core (5.18.3)
- SwiftyGif (5.4.4)
- url_launcher_ios (0.0.1):
- Flutter
Expand Down Expand Up @@ -73,10 +73,10 @@ SPEC CHECKSUMS:
file_picker: ce3938a0df3cc1ef404671531facef740d03f920
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
SDWebImage: 182830bcddc30cde95fbc60dfe4badc3553d94ba
SDWebImage: 96e0c18ef14010b7485210e92fac888587ebb958
SwiftyGif: 93a1cc87bf3a51916001cf8f3d63835fb64c819f
url_launcher_ios: 08a3dfac5fb39e8759aeb0abbd5d9480f30fc8b4

PODFILE CHECKSUM: 70d9d25280d0dd177a5f637cdb0f0b0b12c6a189

COCOAPODS: 1.11.3
COCOAPODS: 1.13.0
1 change: 0 additions & 1 deletion lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'main.dart';

class Config {
Config._();
static const currentSchemaVersion = '2.0.0';

static String get logFilePath {
return p.join(
Expand Down
10 changes: 5 additions & 5 deletions lib/model/entry_data.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:pret_a_porter/pret_a_porter.dart';

import '../format_utils.dart';
import '../main.dart';
Expand All @@ -20,7 +20,7 @@ class PeregrineEntryList extends StateNotifier<Map<String, PeregrineEntry>> {
}

void _writeLog() {
JsonBackend().writeEntriesToJson(state);
JsonBackend().writeDataToJson(state, 'entries');
}

void addNewEntry(String input) {
Expand All @@ -43,22 +43,22 @@ class PeregrineEntryList extends StateNotifier<Map<String, PeregrineEntry>> {
}
}

@immutable
class PeregrineEntry {
class PeregrineEntry extends PretDataclass {
final DateTime date;
final String input;
final bool isEncrypted;
final List<String> tags;
final List<String> mentionedContacts;

const PeregrineEntry({
PeregrineEntry({
required this.date,
required this.input,
required this.isEncrypted,
required this.tags,
required this.mentionedContacts,
});

@override
Map<String, dynamic> toJson() {
return {
'date': date.toIso8601String(),
Expand Down
29 changes: 4 additions & 25 deletions lib/model/json_backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,14 @@ class JsonBackend extends PretJsonManager {
@override
final dataFile = File(Config.logFilePath);
@override
final freshJson = <String, dynamic>{
'schema': Config.currentSchemaVersion,
String schemaVersion = '2.0.0';
@override
Map get freshJson => <String, dynamic>{
'schema': schemaVersion,
'tags': [],
'entries': {},
};

void writeEntriesToJson(
Map<String, PeregrineEntry> logToWrite,
) {
jsonWriteWrapper((initialData) {
final mappifiedLog = logToWrite.map((key, value) => MapEntry(
key,
value.toJson(),
));
initialData['entries'] = mappifiedLog;
return initialData;
});
}

void writeTagsToJson(Map<String, PeregrineTag> tagsToWrite) {
jsonWriteWrapper((initialData) {
final stringifiedTagList = tagsToWrite.map(
(key, value) => MapEntry(key, value.toJson()),
);
initialData['tags'] = stringifiedTagList;
return initialData;
});
}

Map<String, PeregrineEntry> readEntriesFromJson() {
final contentsMap = pretLoadJson();
if (contentsMap is List) {
Expand Down
12 changes: 6 additions & 6 deletions lib/model/tag_data.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:pret_a_porter/pret_a_porter.dart';

import '../format_utils.dart';
import 'json_backend.dart';
Expand All @@ -15,7 +15,7 @@ class TagsList extends StateNotifier<Map<String, PeregrineTag>> {
}

void _writeTags() {
JsonBackend().writeTagsToJson(state);
JsonBackend().writeDataToJson(state, 'tags');
}

void toggleAutoEncrypt(String tagName) {
Expand Down Expand Up @@ -43,7 +43,7 @@ class TagsList extends StateNotifier<Map<String, PeregrineTag>> {
count: state[tag]!.count + 1,
);
} else {
state[tag] = const PeregrineTag(
state[tag] = PeregrineTag(
autoEncrypt: false,
count: 1,
);
Expand All @@ -70,16 +70,16 @@ Map<String, PeregrineTag> sortTags(Map<String, PeregrineTag> tags) {
return {for (final mapEntry in sortedTagsList) mapEntry.key: mapEntry.value};
}

@immutable
class PeregrineTag {
class PeregrineTag extends PretDataclass {
final bool autoEncrypt;
final int count;

const PeregrineTag({
PeregrineTag({
required this.autoEncrypt,
required this.count,
});

@override
Map<String, dynamic> toJson() {
return {
'autoEncrypt': autoEncrypt,
Expand Down
2 changes: 1 addition & 1 deletion macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367

COCOAPODS: 1.11.3
COCOAPODS: 1.13.0

0 comments on commit b9faf25

Please sign in to comment.