Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
feat: client-side post previews
Browse files Browse the repository at this point in the history
* refactor compose form
  • Loading branch information
Craftplacer committed May 23, 2023
1 parent e6e8c43 commit d0b1005
Show file tree
Hide file tree
Showing 6 changed files with 414 additions and 212 deletions.
17 changes: 16 additions & 1 deletion src/kaiteki/lib/fediverse/model/post/draft.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import "package:equatable/equatable.dart";
import "package:kaiteki/fediverse/model/attachment.dart";
import "package:kaiteki/fediverse/model/formatting.dart";
import "package:kaiteki/fediverse/model/post/post.dart";
import "package:kaiteki/fediverse/model/visibility.dart";
import "package:kaiteki/model/file.dart";

class PostDraft {
class PostDraft extends Equatable {
final String content;
final Visibility visibility;
final Formatting formatting;
Expand All @@ -13,6 +14,9 @@ class PostDraft {
final List<Attachment> attachments;
final String? language;

bool get isEmpty =>
content.isEmpty && subject?.isNotEmpty != true && attachments.isEmpty;

const PostDraft({
required this.subject,
required this.content,
Expand Down Expand Up @@ -42,6 +46,17 @@ class PostDraft {
language: language ?? this.language,
);
}

@override
List<Object?> get props => [
subject,
content,
visibility,
formatting,
replyTo,
attachments,
language,
];
}

class AttachmentDraft {
Expand Down
10 changes: 6 additions & 4 deletions src/kaiteki/lib/text/elements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,22 @@ abstract class Element extends Equatable {
}

const Element({this.text, this.children});

bool has(bool Function(Element element) predicate) {
return predicate(this) || children?.any(predicate) == true;
}
}

typedef ReplacementElementBuilder = Element Function(String text);

class TextElement extends Element {
@override
final String? text;
final TextElementStyle? style;

const TextElement(
this.text, {
String? text, {
this.style,
super.children,
});
}) : super(text: text);

List<Element> cut(int index, int length, ReplacementElementBuilder builder) {
final text = this.text;
Expand Down
9 changes: 8 additions & 1 deletion src/kaiteki/lib/text/rendering_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,25 @@ Emoji? resolveEmoji(
]) {
final adapter = ref.read(adapterProvider);

if (emojis == null) debugPrint("No emojis were provided");

if (emojis != null) {
return emojis.firstWhereOrNull((e) => e.short == input);
final emoji = emojis.firstWhereOrNull((e) => e.short == input);
if (emoji == null) debugPrint("Couldn't find $input in provided emojis");
return emoji;
}

if (adapter is MisskeyAdapter) {
final url = buildEmojiUriManual(adapter.instance, input, remoteHost);
debugPrint("Returning mkv13 emoji based on static url: $url");
return CustomEmoji(
short: input,
url: url,
instance: remoteHost ?? adapter.instance,
);
}

debugPrint("Couldn't resolve emoji $input");

return null;
}
5 changes: 4 additions & 1 deletion src/kaiteki/lib/text/text_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ class TextRenderer {
final name = element.name;
final emoji = context?.emojiResolver?.call(name);

if (emoji == null) return TextSpan(text: ":$name:");
if (emoji == null) {
debugPrint("Couldn't resolve emoji $name");
return TextSpan(text: ":$name:");
}

// FIXME(Craftplacer): Change this piece widget into an EmojiSpan. Added Builder to fix scaling with inherited font size.
return WidgetSpan(
Expand Down
Loading

0 comments on commit d0b1005

Please sign in to comment.