PostGeneratorView.swift 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. import AppKit
  2. import SwiftUI
  3. import UniformTypeIdentifiers
  4. struct PostGeneratorView: View {
  5. @Bindable var viewModel: PostGeneratorViewModel
  6. private enum Layout {
  7. static let horizontalPadding: CGFloat = 24
  8. static let columnWidth: CGFloat = 300
  9. static let columnSpacing: CGFloat = 20
  10. static let sectionSpacing: CGFloat = 12
  11. static let imageUploadHeight: CGFloat = 140
  12. }
  13. var body: some View {
  14. VStack(spacing: 0) {
  15. header
  16. messageBanners
  17. ScrollView {
  18. VStack(alignment: .leading, spacing: 12) {
  19. tabBar
  20. PostPageBoundary {
  21. switch viewModel.selectedTab {
  22. case .compose:
  23. composeContent
  24. case .preview:
  25. previewContent
  26. }
  27. }
  28. }
  29. .padding(.horizontal, Layout.horizontalPadding)
  30. .padding(.top, 12)
  31. .padding(.bottom, 24)
  32. }
  33. }
  34. .background(AppTheme.background)
  35. .fileImporter(
  36. isPresented: $viewModel.showImageImporter,
  37. allowedContentTypes: [.image],
  38. allowsMultipleSelection: false
  39. ) { result in
  40. switch result {
  41. case .success(let urls):
  42. if let url = urls.first {
  43. viewModel.setImage(from: url)
  44. }
  45. case .failure(let error):
  46. viewModel.handleImageImportFailure(error)
  47. }
  48. }
  49. .alert("Replace existing content?", isPresented: $viewModel.showOverwriteConfirmation) {
  50. Button("Cancel", role: .cancel) {
  51. viewModel.cancelOverwriteConfirmation()
  52. }
  53. Button("Replace", role: .destructive) {
  54. Task { await viewModel.confirmOverwriteAndGenerate() }
  55. }
  56. } message: {
  57. Text("Generating will replace your current title, body, and poll options.")
  58. }
  59. .onChange(of: viewModel.draft.topic) { _, _ in viewModel.notifyDraftEdited() }
  60. .onChange(of: viewModel.draft.subreddit) { _, _ in viewModel.notifyDraftEdited() }
  61. .onChange(of: viewModel.draft.title) { _, _ in viewModel.notifyDraftEdited() }
  62. .onChange(of: viewModel.draft.body) { _, _ in viewModel.notifyDraftEdited() }
  63. .onChange(of: viewModel.draft.linkURL) { _, _ in viewModel.notifyDraftEdited() }
  64. .onChange(of: viewModel.draft.videoURL) { _, _ in viewModel.notifyDraftEdited() }
  65. .onChange(of: viewModel.draft.flair) { _, _ in viewModel.notifyDraftEdited() }
  66. }
  67. // MARK: - Header
  68. private var header: some View {
  69. VStack(spacing: 0) {
  70. HStack(spacing: 14) {
  71. ModernSidebarIconView(kind: .postGenerator, size: 40)
  72. VStack(alignment: .leading, spacing: 2) {
  73. HStack(spacing: 6) {
  74. Text("Post Generator")
  75. .font(.system(size: 18, weight: .semibold))
  76. .foregroundStyle(AppTheme.textPrimary)
  77. if viewModel.hasDraftChanges {
  78. Circle()
  79. .fill(AppTheme.accentOrange)
  80. .frame(width: 6, height: 6)
  81. .help("Draft has unsaved edits")
  82. }
  83. }
  84. Text(viewModel.generationEngineSubtitle)
  85. .font(.system(size: 11))
  86. .foregroundStyle(AppTheme.textSecondary)
  87. }
  88. Spacer()
  89. headerActions
  90. }
  91. .padding(.horizontal, Layout.horizontalPadding)
  92. .padding(.vertical, 16)
  93. FullWidthDivider()
  94. }
  95. }
  96. @ViewBuilder
  97. private var messageBanners: some View {
  98. if let error = viewModel.errorMessage {
  99. PostGeneratorMessageBanner(message: error, isError: true)
  100. .padding(.horizontal, Layout.horizontalPadding)
  101. .padding(.top, 8)
  102. } else if let success = viewModel.successMessage {
  103. PostGeneratorMessageBanner(message: success, isError: false)
  104. .padding(.horizontal, Layout.horizontalPadding)
  105. .padding(.top, 8)
  106. }
  107. }
  108. private var headerActions: some View {
  109. HStack(spacing: 8) {
  110. Button {
  111. viewModel.resetDraft()
  112. } label: {
  113. Label("Reset", systemImage: "arrow.counterclockwise")
  114. .font(.system(size: 11, weight: .medium))
  115. }
  116. .buttonStyle(AppSecondaryButtonStyle())
  117. Button {
  118. viewModel.copyToClipboard()
  119. } label: {
  120. Label("Copy", systemImage: "doc.on.doc")
  121. .font(.system(size: 11, weight: .medium))
  122. }
  123. .buttonStyle(AppSecondaryButtonStyle())
  124. .disabled(!viewModel.canExport)
  125. Button {
  126. Task { await viewModel.generatePost() }
  127. } label: {
  128. HStack(spacing: 6) {
  129. if viewModel.isGenerating {
  130. ProgressView()
  131. .controlSize(.small)
  132. .tint(.white)
  133. } else {
  134. Image(systemName: "sparkles")
  135. .font(.system(size: 11, weight: .semibold))
  136. }
  137. Text(viewModel.isGenerating ? "Generating…" : "Generate")
  138. .font(.system(size: 11, weight: .semibold))
  139. }
  140. .foregroundStyle(.white)
  141. .padding(.horizontal, 14)
  142. .padding(.vertical, 8)
  143. .background(viewModel.canGenerate ? AppTheme.accentPurple : AppTheme.accentPurple.opacity(0.4))
  144. .clipShape(RoundedRectangle(cornerRadius: 8))
  145. }
  146. .buttonStyle(AppPrimaryButtonStyle())
  147. .disabled(!viewModel.canGenerate)
  148. }
  149. }
  150. // MARK: - Tab Bar
  151. private var tabBar: some View {
  152. ToolSegmentedTabBar(
  153. selection: $viewModel.selectedTab,
  154. accentColor: AppTheme.accentPurple,
  155. width: 220
  156. )
  157. }
  158. // MARK: - Compose
  159. private var composeContent: some View {
  160. composeColumns
  161. }
  162. private var composeColumns: some View {
  163. HStack(alignment: .top, spacing: Layout.columnSpacing) {
  164. composeColumn(title: "Configuration", icon: "slider.horizontal.3") {
  165. configurationPanel
  166. }
  167. .frame(width: Layout.columnWidth)
  168. .layoutPriority(1)
  169. Rectangle()
  170. .fill(AppTheme.border)
  171. .frame(width: 1)
  172. .padding(.vertical, 2)
  173. composeColumn(title: "Generated result", icon: "doc.badge.sparkles") {
  174. editorPanel
  175. }
  176. .frame(minWidth: 0, maxWidth: .infinity)
  177. .layoutPriority(0)
  178. }
  179. }
  180. private func composeColumn<Content: View>(
  181. title: String,
  182. icon: String,
  183. @ViewBuilder content: () -> Content
  184. ) -> some View {
  185. VStack(alignment: .leading, spacing: Layout.sectionSpacing) {
  186. composeSectionHeader(title: title, icon: icon)
  187. content()
  188. }
  189. }
  190. private func composeSectionHeader(title: String, icon: String) -> some View {
  191. HStack(spacing: 6) {
  192. Image(systemName: icon)
  193. .font(.system(size: 10, weight: .semibold))
  194. .foregroundStyle(AppTheme.accentPurpleLight)
  195. Text(title)
  196. .font(.system(size: 11, weight: .semibold))
  197. .foregroundStyle(AppTheme.textSecondary)
  198. }
  199. .textCase(.uppercase)
  200. .tracking(0.4)
  201. }
  202. private var configurationPanel: some View {
  203. VStack(spacing: Layout.sectionSpacing) {
  204. PostFormCard(title: "Post Type", subtitle: "Choose how you want to post") {
  205. PostTypePicker(selectedType: Binding(
  206. get: { viewModel.draft.postType },
  207. set: { viewModel.selectPostType($0) }
  208. ))
  209. }
  210. PostFormCard(title: "Target Subreddit", subtitle: "Where will this be posted?") {
  211. VStack(alignment: .leading, spacing: 6) {
  212. PostFormField(
  213. label: "Subreddit",
  214. placeholder: "technology",
  215. text: $viewModel.draft.subreddit,
  216. prefix: "r/",
  217. isRequired: true
  218. )
  219. if !viewModel.draft.subreddit.isEmpty,
  220. !PostDraftValidator.isValidSubreddit(viewModel.draft.subreddit) {
  221. validationHint("Use 3–21 characters: letters, numbers, underscores only.")
  222. }
  223. }
  224. }
  225. PostFormCard(title: "AI Settings", subtitle: "Guide the tone and topic") {
  226. VStack(alignment: .leading, spacing: 12) {
  227. PostFormField(
  228. label: "Topic / Keywords",
  229. placeholder: "e.g. macOS productivity tips",
  230. text: $viewModel.draft.topic,
  231. isRequired: true
  232. )
  233. VStack(alignment: .leading, spacing: 6) {
  234. Text("Tone")
  235. .font(.system(size: 10, weight: .medium))
  236. .foregroundStyle(AppTheme.textTertiary)
  237. TonePicker(selectedTone: $viewModel.draft.tone)
  238. }
  239. }
  240. }
  241. PostFormCard(title: "Labels", subtitle: "Tags and optional flair") {
  242. VStack(alignment: .leading, spacing: 12) {
  243. HStack(spacing: 8) {
  244. PostTagToggle(
  245. title: "NSFW",
  246. systemImage: "exclamationmark.triangle.fill",
  247. activeColor: Color(hex: 0xEF4444),
  248. isOn: $viewModel.draft.isNSFW
  249. )
  250. .frame(maxWidth: .infinity)
  251. PostTagToggle(
  252. title: "Spoiler",
  253. systemImage: "eye.slash.fill",
  254. activeColor: AppTheme.textSecondary,
  255. isOn: $viewModel.draft.isSpoiler
  256. )
  257. .frame(maxWidth: .infinity)
  258. PostTagToggle(
  259. title: "OC",
  260. systemImage: "star.fill",
  261. activeColor: AppTheme.accentGreen,
  262. isOn: $viewModel.draft.isOC
  263. )
  264. .frame(maxWidth: .infinity)
  265. }
  266. PostFormField(
  267. label: "Flair",
  268. placeholder: "Discussion, Question, Meme…",
  269. text: $viewModel.draft.flair
  270. )
  271. }
  272. }
  273. }
  274. }
  275. private var editorPanel: some View {
  276. VStack(spacing: Layout.sectionSpacing) {
  277. mediaAttachmentSection
  278. if viewModel.hasGeneratedContent {
  279. generatedContentSection
  280. } else {
  281. PostGeneratorEmptyResultPlaceholder()
  282. }
  283. }
  284. }
  285. @ViewBuilder
  286. private var mediaAttachmentSection: some View {
  287. switch viewModel.draft.postType {
  288. case .image:
  289. PostFormCard(title: "Media", subtitle: "Attach an image for your post — not used by AI") {
  290. imageUploadArea
  291. }
  292. case .link:
  293. PostFormCard(title: "Media", subtitle: "Attach the URL you'll share — not used by AI") {
  294. VStack(alignment: .leading, spacing: 6) {
  295. PostFormField(
  296. label: "URL",
  297. placeholder: "https://example.com/article",
  298. text: $viewModel.draft.linkURL
  299. )
  300. if !viewModel.draft.linkURL.isEmpty,
  301. !PostDraftValidator.isValidHTTPURL(viewModel.draft.linkURL) {
  302. validationHint("Enter a valid http or https URL.")
  303. }
  304. }
  305. }
  306. case .video:
  307. PostFormCard(title: "Media", subtitle: "Attach a YouTube, Vimeo, or video URL — not used by AI") {
  308. VStack(alignment: .leading, spacing: 6) {
  309. PostFormField(
  310. label: "Video URL",
  311. placeholder: "https://youtube.com/watch?v=…",
  312. text: $viewModel.draft.videoURL
  313. )
  314. if !viewModel.draft.videoURL.isEmpty,
  315. !PostDraftValidator.isValidHTTPURL(viewModel.draft.videoURL) {
  316. validationHint("Enter a valid http or https URL.")
  317. }
  318. }
  319. }
  320. case .text, .poll:
  321. EmptyView()
  322. }
  323. }
  324. private var generatedContentSection: some View {
  325. VStack(spacing: Layout.sectionSpacing) {
  326. PostFormCard(title: "Title", subtitle: "Generated by AI — edit if you like") {
  327. PostFormField(
  328. label: "Post Title",
  329. placeholder: "Generated title appears here",
  330. text: $viewModel.draft.title
  331. )
  332. }
  333. generatedPostTypeEditor
  334. .frame(minHeight: 160, alignment: .top)
  335. characterCountFooter
  336. }
  337. }
  338. @ViewBuilder
  339. private var generatedPostTypeEditor: some View {
  340. switch viewModel.draft.postType {
  341. case .text:
  342. textPostEditor
  343. case .image:
  344. imageCaptionEditor
  345. case .link:
  346. linkDescriptionEditor
  347. case .video:
  348. videoDescriptionEditor
  349. case .poll:
  350. pollPostEditor
  351. }
  352. }
  353. private var textPostEditor: some View {
  354. PostFormCard(title: "Body", subtitle: "Generated by AI — markdown supported") {
  355. PostFormTextEditor(
  356. label: "Post Body",
  357. placeholder: "Edit the generated body…",
  358. text: $viewModel.draft.body,
  359. minHeight: 220
  360. )
  361. }
  362. }
  363. private var imageCaptionEditor: some View {
  364. PostFormCard(title: "Caption", subtitle: "Generated by AI — edit if you like") {
  365. PostFormTextEditor(
  366. label: "Caption (optional)",
  367. placeholder: "Edit the generated caption…",
  368. text: $viewModel.draft.body,
  369. minHeight: 80
  370. )
  371. }
  372. }
  373. private var linkDescriptionEditor: some View {
  374. PostFormCard(title: "Description", subtitle: "Generated by AI — edit if you like") {
  375. PostFormTextEditor(
  376. label: "Description (optional)",
  377. placeholder: "Edit the generated description…",
  378. text: $viewModel.draft.body,
  379. minHeight: 100
  380. )
  381. }
  382. }
  383. private var videoDescriptionEditor: some View {
  384. PostFormCard(title: "Description", subtitle: "Generated by AI — edit if you like") {
  385. PostFormTextEditor(
  386. label: "Description (optional)",
  387. placeholder: "Edit the generated description…",
  388. text: $viewModel.draft.body,
  389. minHeight: 100
  390. )
  391. }
  392. }
  393. private var pollPostEditor: some View {
  394. PostFormCard(title: "Poll", subtitle: "Generated options — edit if you like") {
  395. VStack(alignment: .leading, spacing: 12) {
  396. ForEach(Array(viewModel.draft.pollOptions.enumerated()), id: \.element.id) { index, option in
  397. HStack(spacing: 8) {
  398. PostFormField(
  399. label: "Option \(index + 1)",
  400. placeholder: "Poll option",
  401. text: Binding(
  402. get: { option.text },
  403. set: { viewModel.updatePollOption(id: option.id, text: $0) }
  404. )
  405. )
  406. if viewModel.canRemovePollOption {
  407. Button {
  408. viewModel.removePollOption(option)
  409. } label: {
  410. Image(systemName: "minus.circle.fill")
  411. .font(.system(size: 14))
  412. .foregroundStyle(Color(hex: 0xEF4444).opacity(0.8))
  413. }
  414. .buttonStyle(AppPlainButtonStyle())
  415. .hoverOverlay(cornerRadius: 7)
  416. .padding(.top, 18)
  417. }
  418. }
  419. }
  420. if viewModel.canAddPollOption {
  421. Button {
  422. viewModel.addPollOption()
  423. } label: {
  424. Label("Add Option", systemImage: "plus.circle.fill")
  425. .font(.system(size: 11, weight: .medium))
  426. .foregroundStyle(AppTheme.accentPurpleLight)
  427. }
  428. .buttonStyle(AppPlainButtonStyle())
  429. .hoverOverlay(cornerRadius: 6)
  430. }
  431. VStack(alignment: .leading, spacing: 6) {
  432. Text("Poll Duration")
  433. .font(.system(size: 10, weight: .medium))
  434. .foregroundStyle(AppTheme.textTertiary)
  435. HStack(spacing: 8) {
  436. ForEach(PollDuration.allCases) { duration in
  437. Button {
  438. viewModel.draft.pollDuration = duration
  439. viewModel.notifyDraftEdited()
  440. } label: {
  441. Text(duration.label)
  442. .font(.system(size: 10, weight: .semibold))
  443. .foregroundStyle(
  444. viewModel.draft.pollDuration == duration ? .white : AppTheme.textSecondary
  445. )
  446. .frame(maxWidth: .infinity)
  447. .padding(.vertical, 7)
  448. .background(
  449. RoundedRectangle(cornerRadius: 7)
  450. .fill(
  451. viewModel.draft.pollDuration == duration
  452. ? AppTheme.accentPurple
  453. : AppTheme.panelBackground
  454. )
  455. )
  456. .overlay(
  457. RoundedRectangle(cornerRadius: 7)
  458. .stroke(AppTheme.cardBorder, lineWidth: 1)
  459. )
  460. }
  461. .buttonStyle(AppPlainButtonStyle())
  462. .hoverOverlay(cornerRadius: 7)
  463. }
  464. }
  465. }
  466. PostFormTextEditor(
  467. label: "Context (optional)",
  468. placeholder: "Edit the generated poll context…",
  469. text: $viewModel.draft.body,
  470. minHeight: 80
  471. )
  472. }
  473. }
  474. }
  475. @ViewBuilder
  476. private var imageUploadArea: some View {
  477. Group {
  478. if let url = viewModel.draft.imageFileURL, let nsImage = NSImage(contentsOf: url) {
  479. ZStack(alignment: .topTrailing) {
  480. Image(nsImage: nsImage)
  481. .resizable()
  482. .scaledToFit()
  483. .frame(maxWidth: .infinity, maxHeight: Layout.imageUploadHeight)
  484. .frame(maxWidth: .infinity, maxHeight: Layout.imageUploadHeight)
  485. .clipped()
  486. Button {
  487. viewModel.removeImage()
  488. } label: {
  489. Image(systemName: "xmark.circle.fill")
  490. .font(.system(size: 18))
  491. .foregroundStyle(.white)
  492. .shadow(radius: 2)
  493. }
  494. .buttonStyle(AppPlainButtonStyle())
  495. .hoverOverlay(cornerRadius: 8)
  496. .padding(8)
  497. }
  498. } else {
  499. Button {
  500. viewModel.showImageImporter = true
  501. } label: {
  502. VStack(spacing: 8) {
  503. Image(systemName: "photo.badge.plus")
  504. .font(.system(size: 24))
  505. .foregroundStyle(AppTheme.accentPurpleLight)
  506. Text("Click to upload image")
  507. .font(.system(size: 11, weight: .medium))
  508. .foregroundStyle(AppTheme.textSecondary)
  509. Text("PNG, JPG, GIF, WebP")
  510. .font(.system(size: 9))
  511. .foregroundStyle(AppTheme.textTertiary)
  512. }
  513. .frame(maxWidth: .infinity, maxHeight: .infinity)
  514. .background(AppTheme.panelBackground)
  515. .clipShape(RoundedRectangle(cornerRadius: 8))
  516. .overlay(
  517. RoundedRectangle(cornerRadius: 8)
  518. .strokeBorder(
  519. AppTheme.accentPurple.opacity(0.3),
  520. style: StrokeStyle(lineWidth: 1, dash: [6, 4])
  521. )
  522. )
  523. }
  524. .buttonStyle(AppPlainButtonStyle())
  525. .hoverCard(cornerRadius: 8)
  526. }
  527. }
  528. .frame(maxWidth: .infinity)
  529. .frame(height: Layout.imageUploadHeight)
  530. .clipShape(RoundedRectangle(cornerRadius: 8))
  531. }
  532. private var characterCountFooter: some View {
  533. HStack(spacing: 12) {
  534. Text(titleCharacterCount)
  535. .font(.system(size: 10, weight: .medium, design: .monospaced))
  536. .foregroundStyle(
  537. viewModel.draft.title.count > PostDraftValidator.maxTitleLength
  538. ? Color(hex: 0xF87171)
  539. : AppTheme.textTertiary
  540. )
  541. if !viewModel.draft.body.isEmpty {
  542. Text("·")
  543. .foregroundStyle(AppTheme.textTertiary)
  544. Text(bodyCharacterCount)
  545. .font(.system(size: 10, weight: .medium, design: .monospaced))
  546. .foregroundStyle(
  547. viewModel.draft.body.count > PostDraftValidator.maxBodyLength
  548. ? Color(hex: 0xF87171)
  549. : AppTheme.textTertiary
  550. )
  551. }
  552. Spacer()
  553. Text("Reddit limits: 300 title · 40,000 body")
  554. .font(.system(size: 10))
  555. .foregroundStyle(AppTheme.textTertiary)
  556. }
  557. .padding(.horizontal, 12)
  558. .padding(.vertical, 9)
  559. .background(
  560. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  561. .fill(AppTheme.cardBackground)
  562. .overlay(
  563. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  564. .stroke(AppTheme.cardBorder, lineWidth: 1)
  565. )
  566. )
  567. }
  568. private var titleCharacterCount: String {
  569. "\(viewModel.draft.title.count) / \(PostDraftValidator.maxTitleLength) title"
  570. }
  571. private var bodyCharacterCount: String {
  572. "\(viewModel.draft.body.count) / \(PostDraftValidator.maxBodyLength) body"
  573. }
  574. // MARK: - Preview
  575. private var previewContent: some View {
  576. VStack(alignment: .leading, spacing: Layout.columnSpacing) {
  577. composeSectionHeader(title: "Live Preview", icon: "eye")
  578. HStack {
  579. Spacer(minLength: 0)
  580. VStack(spacing: Layout.sectionSpacing) {
  581. RedditPostPreviewCard(
  582. draft: viewModel.draft,
  583. formattedSubreddit: viewModel.formattedSubreddit
  584. )
  585. previewMetadata
  586. }
  587. .frame(maxWidth: 560)
  588. Spacer(minLength: 0)
  589. }
  590. }
  591. }
  592. private var previewMetadata: some View {
  593. VStack(alignment: .leading, spacing: 0) {
  594. metadataRow(label: "Type", value: viewModel.draft.postType.title)
  595. metadataDivider
  596. metadataRow(label: "Subreddit", value: viewModel.formattedSubreddit)
  597. metadataDivider
  598. metadataRow(label: "Tone", value: viewModel.draft.tone.title)
  599. metadataDivider
  600. metadataRow(label: "Engine", value: viewModel.usesLiveAI ? "AI" : "Local templates")
  601. if viewModel.draft.isNSFW || viewModel.draft.isSpoiler || viewModel.draft.isOC {
  602. metadataDivider
  603. metadataRow(
  604. label: "Tags",
  605. value: [
  606. viewModel.draft.isNSFW ? "NSFW" : nil,
  607. viewModel.draft.isSpoiler ? "Spoiler" : nil,
  608. viewModel.draft.isOC ? "OC" : nil,
  609. ]
  610. .compactMap { $0 }
  611. .joined(separator: ", ")
  612. )
  613. }
  614. }
  615. .padding(14)
  616. .frame(maxWidth: .infinity, alignment: .leading)
  617. .background(
  618. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  619. .fill(AppTheme.cardBackground)
  620. .overlay(
  621. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  622. .stroke(AppTheme.cardBorder, lineWidth: 1)
  623. )
  624. )
  625. }
  626. private var metadataDivider: some View {
  627. Rectangle()
  628. .fill(AppTheme.border)
  629. .frame(height: 1)
  630. .padding(.vertical, 6)
  631. }
  632. private func metadataRow(label: String, value: String) -> some View {
  633. HStack(alignment: .top, spacing: 12) {
  634. Text(label)
  635. .font(.system(size: 10, weight: .medium))
  636. .foregroundStyle(AppTheme.textTertiary)
  637. .frame(width: 72, alignment: .leading)
  638. Text(value)
  639. .font(.system(size: 10))
  640. .foregroundStyle(AppTheme.textSecondary)
  641. .fixedSize(horizontal: false, vertical: true)
  642. }
  643. }
  644. private func validationHint(_ message: String) -> some View {
  645. HStack(spacing: 4) {
  646. Image(systemName: "exclamationmark.circle.fill")
  647. .font(.system(size: 9))
  648. Text(message)
  649. .font(.system(size: 9))
  650. }
  651. .foregroundStyle(Color(hex: 0xF87171))
  652. }
  653. }
  654. private struct PostSecondaryButtonStyle: ButtonStyle {
  655. func makeBody(configuration: Configuration) -> some View {
  656. AppSecondaryButtonStyle().makeBody(configuration: configuration)
  657. }
  658. }
  659. #Preview {
  660. PostGeneratorView(viewModel: PostGeneratorViewModel())
  661. .frame(width: 880, height: 720)
  662. }