Skip to content

Commit

Permalink
redirected calendar feature to calendar plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
josancamon19 committed Oct 30, 2024
1 parent f070bdb commit 32a2be1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 76 deletions.
4 changes: 2 additions & 2 deletions app/lib/env/env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ abstract class Env {

static String? get mixpanelProjectToken => _instance.mixpanelProjectToken;

static String? get apiBaseUrl => _instance.apiBaseUrl;
// static String? get apiBaseUrl => _instance.apiBaseUrl;

// static String? get apiBaseUrl => 'https://based-hardware-development--backened-dev-api.modal.run/';
// static String? get apiBaseUrl => 'https://camel-lucky-reliably.ngrok-free.app/';
static String? get apiBaseUrl => 'https://camel-lucky-reliably.ngrok-free.app/';
// static String? get apiBaseUrl => 'https://mutual-fun-boar.ngrok-free.app/';

static String? get growthbookApiKey => _instance.growthbookApiKey;
Expand Down
39 changes: 6 additions & 33 deletions app/lib/pages/memory_detail/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import 'package:friend_private/backend/schema/memory.dart';
import 'package:friend_private/pages/apps/page.dart';
import 'package:friend_private/pages/memory_detail/memory_detail_provider.dart';
import 'package:friend_private/pages/memory_detail/test_prompts.dart';
import 'package:friend_private/pages/settings/calendar.dart';
import 'package:friend_private/pages/settings/developer.dart';
import 'package:friend_private/providers/connectivity_provider.dart';
import 'package:friend_private/providers/memory_provider.dart';
import 'package:friend_private/utils/alerts/app_snackbar.dart';
import 'package:friend_private/utils/analytics/mixpanel.dart';
import 'package:friend_private/utils/features/calendar.dart';
import 'package:friend_private/utils/other/temp.dart';
import 'package:friend_private/widgets/dialog.dart';
import 'package:friend_private/widgets/expandable_text.dart';
Expand Down Expand Up @@ -276,6 +275,11 @@ class EventsListWidget extends StatelessWidget {
return const SizedBox.shrink();
}
return ListTile(
onTap: () {
AppSnackbar.showSnackbar(
'This integration is being deprecated. Please use the new Google Calendar app.',
);
},
contentPadding: EdgeInsets.zero,
title: Text(
event.title,
Expand All @@ -288,37 +292,6 @@ class EventsListWidget extends StatelessWidget {
style: const TextStyle(color: Colors.grey, fontSize: 15),
),
),
trailing: IconButton(
onPressed: event.created
? null
: () {
var calEnabled = SharedPreferencesUtil().calendarEnabled;
var calSelected = SharedPreferencesUtil().calendarId.isNotEmpty;
if (!calEnabled || !calSelected) {
routeToPage(context, const CalendarPage());
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(!calEnabled
? 'Enable calendar integration to add events'
: 'Select a calendar to add events to'),
));
return;
}
context.read<MemoryDetailProvider>().updateEventState(true, idx);
setMemoryEventsState(provider.memory.id, [idx], [true]);
CalendarUtil().createEvent(
event.title,
event.startsAt,
event.duration,
description: event.description,
);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Event added! It may take a few minutes to show up in your calendar. 📆'),
),
);
},
icon: Icon(event.created ? Icons.check : Icons.add, color: Colors.white),
),
);
},
),
Expand Down
12 changes: 6 additions & 6 deletions app/lib/pages/settings/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ class _SettingsPageState extends State<SettingsPage> {
// icon: Icons.integration_instructions,
// ),
// const SizedBox(height: 8),
getItemAddOn2(
'Calendar Integration',
() => routeToPage(context, const CalendarPage()),
icon: Icons.calendar_month,
),
const SizedBox(height: 20),
// getItemAddOn2(
// 'Calendar Integration',
// () => routeToPage(context, const CalendarPage()),
// icon: Icons.calendar_month,
// ),
// const SizedBox(height: 20),
getItemAddOn2(
'About Omi',
() => routeToPage(context, const AboutOmiPage()),
Expand Down
67 changes: 33 additions & 34 deletions app/lib/providers/memory_provider.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import 'dart:async';

import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:friend_private/backend/http/api/memories.dart';
import 'package:friend_private/backend/preferences.dart';
import 'package:friend_private/backend/schema/memory.dart';
import 'package:friend_private/backend/schema/structured.dart';
import 'package:friend_private/services/services.dart';
import 'package:friend_private/services/wals.dart';
import 'package:friend_private/utils/analytics/mixpanel.dart';
import 'package:friend_private/utils/features/calendar.dart';

class MemoryProvider extends ChangeNotifier implements IWalServiceListener, IWalSyncProgressListener {
List<ServerMemory> memories = [];
Expand All @@ -28,11 +25,14 @@ class MemoryProvider extends ChangeNotifier implements IWalServiceListener, IWal
IWalService get _wal => ServiceManager.instance().wal;

List<Wal> _missingWals = [];

List<Wal> get missingWals => _missingWals;

int get missingWalsInSeconds =>
_missingWals.isEmpty ? 0 : _missingWals.map((val) => val.seconds).reduce((a, b) => a + b);

double _walsSyncedProgress = 0.0;

double get walsSyncedProgress => _walsSyncedProgress;

bool isSyncing = false;
Expand Down Expand Up @@ -153,22 +153,21 @@ class MemoryProvider extends ChangeNotifier implements IWalServiceListener, IWal
var mem = await getMemories();
memories = mem;
memories.sort((a, b) => b.createdAt.compareTo(a.createdAt));
createEventsForMemories();
setLoadingMemories(false);
notifyListeners();
return memories;
}

void createEventsForMemories() {
for (var memory in memories) {
if (memory.structured.events.isNotEmpty &&
!memory.structured.events.first.created &&
memory.startedAt != null &&
memory.startedAt!.isAfter(DateTime.now().add(const Duration(days: -1)))) {
_handleCalendarCreation(memory);
}
}
}
// void createEventsForMemories() {
// for (var memory in memories) {
// if (memory.structured.events.isNotEmpty &&
// !memory.structured.events.first.created &&
// memory.startedAt != null &&
// memory.startedAt!.isAfter(DateTime.now().add(const Duration(days: -1)))) {
// _handleCalendarCreation(memory);
// }
// }
// }

Future getMoreMemoriesFromServer() async {
if (memories.length % 50 != 0) return;
Expand Down Expand Up @@ -267,26 +266,26 @@ class MemoryProvider extends ChangeNotifier implements IWalServiceListener, IWal
notifyListeners();
}

_handleCalendarCreation(ServerMemory memory) {
if (!SharedPreferencesUtil().calendarEnabled) return;
if (SharedPreferencesUtil().calendarType != 'auto') return;

List<Event> events = memory.structured.events;
if (events.isEmpty) return;

List<int> indexes = events.mapIndexed((index, e) => index).toList();
setMemoryEventsState(memory.id, indexes, indexes.map((_) => true).toList());
for (var i = 0; i < events.length; i++) {
if (events[i].created) continue;
events[i].created = true;
CalendarUtil().createEvent(
events[i].title,
events[i].startsAt,
events[i].duration,
description: events[i].description,
);
}
}
// _handleCalendarCreation(ServerMemory memory) {
// if (!SharedPreferencesUtil().calendarEnabled) return;
// if (SharedPreferencesUtil().calendarType != 'auto') return;
//
// List<Event> events = memory.structured.events;
// if (events.isEmpty) return;
//
// List<int> indexes = events.mapIndexed((index, e) => index).toList();
// setMemoryEventsState(memory.id, indexes, indexes.map((_) => true).toList());
// for (var i = 0; i < events.length; i++) {
// if (events[i].created) continue;
// events[i].created = true;
// CalendarUtil().createEvent(
// events[i].title,
// events[i].startsAt,
// events[i].duration,
// description: events[i].description,
// );
// }
// }

/////////////////////////////////////////////////////////////////
////////// Delete Memory With Undo Functionality ///////////////
Expand Down
2 changes: 1 addition & 1 deletion app/lib/widgets/expandable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class _ExpandableTextWidgetState extends State<ExpandableTextWidget> {
fontWeight: FontWeight.w600,
),
),
data: widget.isExpanded ? widget.text : widget.text.substring(0, 300),
data: widget.isExpanded ? widget.text : widget.text.length > 300 ?widget.text.substring(0, 300): widget.text,
),
// Text(
// widget.text,
Expand Down

0 comments on commit 32a2be1

Please sign in to comment.