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
14 changes: 2 additions & 12 deletions lib/collab/page_made_here.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ List<StrategyOp> pageCopyContentOps({
final newLineupId = _sharedCopyIds();
return [
for (final element in elements)
_copiedElement(pageId, element, _copyId(element.publicId)),
_copiedElement(pageId, element, newStorableCopyId(element.publicId)),
for (final lineup in lineups)
_copiedLineupGroup(pageId, lineup, newLineupId),
];
Expand Down Expand Up @@ -67,21 +67,11 @@ RemotePageSnapshot pageMadeHere({
);
}

/// The longest root a copy id keeps, URL-encoded, as the server's
/// (convex/lib/pageCopyId.ts): a longer one would make the op's storage
/// key too long to keep, so that copy gets a plain id.
const _maxKeptRootLength = 80;

String _copyId(String id) =>
Uri.encodeComponent(pageCopyRoot(id)).length > _maxKeptRootLength
? const Uuid().v4()
: newPageCopyId(id);

/// One copy id per id, shared by every lineup group copied: a spot or
/// lineup named twice is the same copy both times.
String Function(String id) _sharedCopyIds() {
final ids = <String, String>{};
return (id) => ids[id] ??= _copyId(id);
return (id) => ids[id] ??= newStorableCopyId(id);
}

ElementAddOp _copiedElement(String pageId, DrawnRow element, String id) {
Expand Down
21 changes: 19 additions & 2 deletions lib/const/line_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,12 @@ class LineUpGraph {
/// The lineups [linkIds] and the spots they aim at, ready to be put on
/// another page, each under a new id that carries its original's (see
/// page_copy_id.dart). Spots they share stay shared in the copy.
LineUpGraph copyOfLinks(Set<String> linkIds) {
LineUpGraph copyOfLinks(
Set<String> linkIds, {
String Function(String id) newId = newPageCopyId,
}) {
final newIds = <String, String>{};
String renamed(String id) => newIds[id] ??= newPageCopyId(id);
String renamed(String id) => newIds[id] ??= newId(id);
final part = linksWithSpots(linkIds);
return LineUpGraph(
origins: [
Expand Down Expand Up @@ -1398,6 +1401,20 @@ class LineUpProvider extends Notifier<LineUpState> {
}
}

/// Adds [copies] (a paste: lineups whose ids are all new) as one undoable
/// addition.
void addCopies(LineUpGraph copies) {
if (!ref.canEditPages || copies.links.isEmpty) return;
_apply(from: LineUpGraph.empty, to: copies);
_record(
LineUpGraphAction(
type: ActionType.addition,
id: copies.links.first.id,
after: copies.deepCopy(),
),
);
}

// --- Deletions -----------------------------------------------------------

void deleteLink(String linkId) {
Expand Down
12 changes: 12 additions & 0 deletions lib/const/page_copy_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ String pageCopyRoot(String id) {
/// A fresh id for a copy of [id] on another page.
String newPageCopyId(String id) =>
'${pageCopyRoot(id)}$_copyMark${const Uuid().v4()}';

/// The longest root a copy id keeps, URL-encoded, as the server's
/// (convex/lib/pageCopyId.ts): a longer one would make the op's storage
/// key too long to keep, so that copy gets a plain id.
const _maxKeptRootLength = 80;

/// [newPageCopyId], or a plain id when [id]'s root is too long for the copy
/// to be stored to send (only an item imported with an unusually long id).
String newStorableCopyId(String id) =>
Uri.encodeComponent(pageCopyRoot(id)).length > _maxKeptRootLength
? const Uuid().v4()
: newPageCopyId(id);
Loading
Loading