Add a preview toot to the top of the display settings page. (#716)

* Add a preview toot tot the top of the display settings page.

* DisplayModel doesn't need to be @State

* Disable hitTest

* Example Post

---------

Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
This commit is contained in:
Gareth Simpson 2023-02-08 18:09:24 +00:00 committed by GitHub
parent 0c359f2b79
commit 8f6e6853aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 54 additions and 14 deletions

View file

@ -13,8 +13,15 @@ struct DisplaySettingsView: View {
@State private var isFontSelectorPresented = false
private var previewStatusViewModel = StatusRowViewModel(status: Status.placeholder(parseMarkdown: true))
var body: some View {
Form {
Section("settings.display.example-toot") {
StatusRowView(viewModel: previewStatusViewModel)
.allowsHitTesting(false)
}
Section {
Toggle("settings.display.theme.systemColor", isOn: $theme.followSystemColorScheme)
themeSelectorButton

View file

@ -65,6 +65,7 @@
"settings.app.source" = "Font (enllaç a GitHub)";
"settings.app.support" = "Dona suport a l'aplicació";
"settings.app.about" = "About";
"settings.display.example-toot" = "Example Post";
"settings.display.avatar.position" = "Posició de les fotos de perfil";
"settings.display.avatar.shape" = "Forma de les fotos de perfil";
"settings.display.navigation-title" = "Configuració de l'aparença";

View file

@ -66,6 +66,7 @@
"settings.app.source" = "Quellcode (auf GitHub)";
"settings.app.support" = "Unterstütze die App";
"settings.app.about" = "About";
"settings.display.example-toot" = "Example Post";
"settings.display.avatar.position" = "Profilbild-Position";
"settings.display.avatar.shape" = "Profilbild-Form";
"settings.display.navigation-title" = "Anzeigeeinstellungen";

View file

@ -66,6 +66,7 @@
"settings.app.source" = "Source (GitHub link)";
"settings.app.support" = "Support the app";
"settings.app.about" = "About";
"settings.display.example-toot" = "Example Post";
"settings.display.font" = "Timeline Font";
"settings.display.font.system" = "System";
"settings.display.font.custom" = "Custom";

View file

@ -66,6 +66,7 @@
"settings.app.source" = "Source (GitHub link)";
"settings.app.support" = "Support the app";
"settings.app.about" = "About";
"settings.display.example-toot" = "Example Post";
"settings.display.font" = "Timeline Font";
"settings.display.font.system" = "System";
"settings.display.font.custom" = "Custom";

View file

@ -66,6 +66,7 @@
"settings.app.source" = "Código fuente (Enlace a GitHub)";
"settings.app.support" = "Apoya a Ice Cubes";
"settings.app.about" = "Acerca de";
"settings.display.example-toot" = "Example Post";
"settings.display.avatar.position" = "Posición del avatar";
"settings.display.avatar.shape" = "Forma del avatar";
"settings.display.navigation-title" = "Ajustes de apariencia";

View file

@ -66,6 +66,7 @@
"settings.app.source" = "Source (lien GitHub)";
"settings.app.support" = "Soutenir l'application";
"settings.app.about" = "À propos";
"settings.display.example-toot" = "Example Post";
"settings.display.avatar.position" = "Position de l'avatar";
"settings.display.avatar.shape" = "Forme de l'avatar";
"settings.display.navigation-title" = "Paramètres d'affichage";

View file

@ -66,6 +66,7 @@
"settings.app.source" = "Sorgenti (link GitHub)";
"settings.app.support" = "Supporta l'applicazione";
"settings.app.about" = "Informazioni";
"settings.display.example-toot" = "Example Post";
"settings.display.avatar.position" = "Posizione dell'avatar";
"settings.display.avatar.shape" = "Forma dell'avatar";
"settings.display.navigation-title" = "Impostazioni di visualizzazione";

View file

@ -66,6 +66,7 @@
"settings.app.source" = "ソース (GitHub link)";
"settings.app.support" = "アプリを支援する";
"settings.app.about" = "アプリについて";
"settings.display.example-toot" = "Example Post";
"settings.display.font" = "タイムラインのフォント";
"settings.display.font.system" = "システムフォント";
"settings.display.font.custom" = "カスタム";

View file

@ -66,6 +66,7 @@
"settings.app.source" = "소스 코드 (GitHub)";
"settings.app.support" = "이 앱 지원하기";
"settings.app.about" = "이 앱에 관해";
"settings.display.example-toot" = "Example Post";
"settings.display.avatar.position" = "프로필 사진 위치";
"settings.display.avatar.shape" = "프로필 사진 모양";
"settings.display.navigation-title" = "화면 설정";

View file

@ -66,6 +66,7 @@
"settings.app.source" = "Kilde (GitHub-lenke)";
"settings.app.support" = "Støtt denne appen";
"settings.app.about" = "About";
"settings.display.example-toot" = "Example Post";
"settings.display.font" = "Tidslinjefont";
"settings.display.font.system" = "System";
"settings.display.font.custom" = "Tilpasset";

View file

@ -66,6 +66,7 @@
"settings.app.source" = "Broncode (GitHub-link)";
"settings.app.support" = "De app steunen";
"settings.app.about" = "Info";
"settings.display.example-toot" = "Example Post";
"settings.display.avatar.position" = "Avatarpositie";
"settings.display.avatar.shape" = "Avatarvorm";
"settings.display.navigation-title" = "Weergaveopties";

View file

@ -66,6 +66,7 @@
"settings.app.source" = "Źródło (link do GitHub)";
"settings.app.support" = "Wspieraj aplikację";
"settings.app.about" = "O aplikacji";
"settings.display.example-toot" = "Example Post";
"settings.display.avatar.position" = "Położenie awatara";
"settings.display.avatar.shape" = "Kształt awatara";
"settings.display.navigation-title" = "Ustawienia ekranu";

View file

@ -66,6 +66,7 @@
"settings.app.source" = "Código fonte (link GitHub)";
"settings.app.support" = "Apoie o app";
"settings.app.about" = "About";
"settings.display.example-toot" = "Example Post";
"settings.display.avatar.position" = "Posição do avatar";
"settings.display.avatar.shape" = "Formato do avatar";
"settings.display.navigation-title" = "Ver Configurações";

View file

@ -66,6 +66,7 @@
"settings.app.source" = "Kaynak Kodu (GitHub link)";
"settings.app.support" = "Uygulamayı Destekleyin";
"settings.app.about" = "About";
"settings.display.example-toot" = "Example Post";
"settings.display.avatar.position" = "Avatar Pozisyonu";
"settings.display.avatar.shape" = "Avatar Şekli";
"settings.display.navigation-title" = "Gösterim Ayarları";

View file

@ -66,6 +66,7 @@
"settings.app.source" = "源代码GitHub 链接)";
"settings.app.support" = "支持本应用";
"settings.app.about" = "关于";
"settings.display.example-toot" = "Example Post";
"settings.display.avatar.position" = "头像位置";
"settings.display.avatar.shape" = "头像边框";
"settings.display.navigation-title" = "显示设置";

View file

@ -54,10 +54,10 @@ public struct Account: Codable, Identifiable, Equatable, Hashable {
public static func placeholder() -> Account {
.init(id: UUID().uuidString,
username: "Username",
displayName: "Display Name",
displayName: "John Mastodon",
avatar: URL(string: "https://files.mastodon.social/media_attachments/files/003/134/405/original/04060b07ddf7bb0b.png")!,
header: URL(string: "https://files.mastodon.social/media_attachments/files/003/134/405/original/04060b07ddf7bb0b.png")!,
acct: "account@account.com",
acct: "johnm@example.com",
note: .init(stringValue: "Some content"),
createdAt: "2022-12-16T10:20:54.000Z",
followersCount: 10,

View file

@ -77,13 +77,25 @@ public struct HTMLString: Codable, Equatable, Hashable {
}
}
public init(stringValue: String) {
public init(stringValue: String, parseMarkdown:Bool = false) {
htmlValue = stringValue
asMarkdown = stringValue
asRawText = stringValue
statusesURLs = []
if parseMarkdown {
do {
let options = AttributedString.MarkdownParsingOptions(allowsExtendedAttributes: true,
interpretedSyntax: .inlineOnlyPreservingWhitespace)
asSafeMarkdownAttributedString = try AttributedString(markdown: asMarkdown, options: options)
} catch {
asSafeMarkdownAttributedString = AttributedString(stringLiteral: htmlValue)
}
}
else {
asSafeMarkdownAttributedString = AttributedString(stringLiteral: htmlValue)
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

View file

@ -3,6 +3,11 @@ import Foundation
public typealias ServerDate = String
extension ServerDate {
public static var sampleDate: ServerDate {
createdAtDateFormatter.string(from: Date()-100)
}
private static var createdAtDateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.calendar = .init(identifier: .iso8601)

View file

@ -100,11 +100,12 @@ public struct Status: AnyStatus, Codable, Identifiable, Equatable, Hashable, Sta
public let sensitive: Bool
public let language: String?
public static func placeholder() -> Status {
public static func placeholder(parseMarkdown:Bool = false) -> Status {
.init(id: UUID().uuidString,
content: .init(stringValue: "This is a #toot\nWith some @content\nAnd some more content for your #eyes @only"),
content: .init(stringValue: "Lorem ipsum [#dolor](#) sit amet\nconsectetur [@adipiscing](#) elit\nAsed do eiusmod tempor incididunt ut labore.", parseMarkdown: parseMarkdown),
account: .placeholder(),
createdAt: "2022-12-16T10:20:54.000Z",
createdAt: ServerDate.sampleDate,
editedAt: nil,
reblog: nil,
mediaAttachments: [],