fluffychat/lib/pangea/common/utils/any_state_holder.dart
wcjord 473ffbaf24
docs: writing assistance redesign design spec (#5655) (#5696)
* "docs: writing assistance redesign design spec (#5655)

Add comprehensive design doc for the WA redesign:
- AssistanceRing replaces StartIGCButton (segmented ring around Pangea icon)
- Background highlights with category colors (not red/orange error tones)
- Simplified match lifecycle: open → viewed → accepted (no ignore)
- Persistent span card with smooth transitions between matches
- Send always available, no gate on unresolved matches

Remove superseded design docs (SPAN_CARD_REDESIGN_FINALIZED.md,
SPAN_CARD_REDESIGN_Q_AND_A.md, choreographer.instructions.md)."

* feat: replace ignored status with viewed status, initial updates to span card

* resolve merge conflicts

* rebuild input bar on active match update to fix span hightlighting

* cleanup

* allow opening span cards for closed matches

* no gate on sending, update underline colors

* animate span card transitions

* initial updates to add segmented IGC progress ring

* update segment colors / opacities based on match statuses

* use same widget for igc loading and fetched

* more segment animation changes

* fix scrolling and wrap in span card

* better disabled color

* close span card on assistance state change

* remove print statements

* update design doc

* cleanup

---------

Co-authored-by: ggurdin <ggurdin@gmail.com>
2026-02-25 13:07:53 -05:00

169 lines
4.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:collection/collection.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
class OverlayListEntry {
final OverlayEntry entry;
final String? key;
final bool canPop;
final bool blockOverlay;
OverlayListEntry(
this.entry, {
this.key,
this.canPop = true,
this.blockOverlay = false,
});
}
class PangeaAnyState {
final Map<String, LayerLinkAndKey> _layerLinkAndKeys = {};
List<OverlayListEntry> entries = [];
LayerLinkAndKey layerLinkAndKey(
String transformTargetId, [
throwErrorIfNotThere = false,
]) {
if (_layerLinkAndKeys[transformTargetId] == null) {
if (throwErrorIfNotThere) {
Sentry.addBreadcrumb(Breadcrumb(data: _layerLinkAndKeys));
throw Exception("layerLinkAndKey with null for $transformTargetId");
} else {
_layerLinkAndKeys[transformTargetId] = LayerLinkAndKey(
transformTargetId,
);
}
}
return _layerLinkAndKeys[transformTargetId]!;
}
bool openOverlay(
OverlayEntry entry,
BuildContext context, {
String? overlayKey,
bool canPop = true,
bool blockOverlay = false,
bool rootOverlay = false,
}) {
if (entries.any((e) => e.blockOverlay)) {
return false;
}
if (overlayKey != null &&
entries.any((element) => element.key == overlayKey)) {
return false;
}
entries.add(
OverlayListEntry(
entry,
key: overlayKey,
canPop: canPop,
blockOverlay: blockOverlay,
),
);
Overlay.of(context, rootOverlay: rootOverlay).insert(entry);
return true;
}
void closeOverlay([String? overlayKey]) {
final entry = overlayKey != null
? entries.firstWhereOrNull((element) => element.key == overlayKey)
: entries.lastWhereOrNull((element) => element.canPop);
if (entry != null) {
try {
entry.entry.remove();
entry.entry.dispose();
} catch (err, s) {
ErrorHandler.logError(e: err, s: s, data: {"overlay": entry});
}
entries.remove(entry);
}
}
void closeAllOverlays({RegExp? filter, force = false}) {
List<OverlayListEntry> shouldRemove = List.from(entries);
if (!force) {
shouldRemove = shouldRemove.where((element) => element.canPop).toList();
}
if (filter != null) {
shouldRemove = shouldRemove
.where((element) => element.key != null)
.where((element) => filter.hasMatch(element.key!))
.toList();
}
if (shouldRemove.isEmpty) return;
for (int i = 0; i < shouldRemove.length; i++) {
try {
shouldRemove[i].entry.remove();
shouldRemove[i].entry.dispose();
} catch (err, s) {
ErrorHandler.logError(e: err, s: s, data: {"overlay": shouldRemove[i]});
}
entries.remove(shouldRemove[i]);
}
}
RenderBox? getRenderBox(String key) {
final box =
layerLinkAndKey(key).key.currentContext?.findRenderObject()
as RenderBox?;
return box?.hasSize == true ? box : null;
}
bool isOverlayOpen({RegExp? regex, String? overlayKey}) {
return entries.any(
(element) =>
element.key != null &&
(regex?.hasMatch(element.key!) == true || element.key == overlayKey),
);
}
List<String> getMatchingOverlayKeys(RegExp regex) {
return entries
.where((e) => e.key != null)
.where((element) => regex.hasMatch(element.key!))
.map((e) => e.key)
.whereType<String>()
.toList();
}
}
class LayerLinkAndKey {
late LabeledGlobalKey key;
late LayerLink link;
String transformTargetId;
LayerLinkAndKey(this.transformTargetId) {
key = LabeledGlobalKey(transformTargetId);
link = LayerLink();
}
Map<String, dynamic> toJson() => {
"key": key.toString(),
"link": link.toString(),
"transformTargetId": transformTargetId,
};
@override
operator ==(Object other) =>
identical(this, other) ||
other is LayerLinkAndKey &&
runtimeType == other.runtimeType &&
key == other.key &&
link == other.link &&
transformTargetId == other.transformTargetId;
@override
int get hashCode => key.hashCode ^ link.hashCode ^ transformTargetId.hashCode;
}