Colors, pages, post links
This commit is contained in:
61
CHDataManagement/Views/Posts/PagePickerView.swift
Normal file
61
CHDataManagement/Views/Posts/PagePickerView.swift
Normal file
@ -0,0 +1,61 @@
|
||||
import SwiftUI
|
||||
|
||||
struct PagePickerView: View {
|
||||
|
||||
@Binding var showPagePicker: Bool
|
||||
|
||||
@Binding var selectedPage: Page?
|
||||
|
||||
@EnvironmentObject
|
||||
private var content: Content
|
||||
|
||||
@Environment(\.language)
|
||||
private var language
|
||||
|
||||
@State
|
||||
private var newSelection: Page?
|
||||
|
||||
init(showPagePicker: Binding<Bool>, selectedPage: Binding<Page?>) {
|
||||
self._showPagePicker = showPagePicker
|
||||
self._selectedPage = selectedPage
|
||||
self.newSelection = selectedPage.wrappedValue
|
||||
// TODO: Fix assignment not working
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text("Select a page to link to")
|
||||
List(content.pages, selection: $newSelection) { page in
|
||||
let loc = page.localized(in: language)
|
||||
Text("\(loc.title) (\(page.id))")
|
||||
.tag(page)
|
||||
}
|
||||
.frame(minHeight: 300)
|
||||
HStack {
|
||||
Button("Use selection") {
|
||||
DispatchQueue.main.async {
|
||||
self.selectedPage = self.newSelection
|
||||
}
|
||||
showPagePicker = false
|
||||
}
|
||||
Button("Remove page", role: .destructive) {
|
||||
DispatchQueue.main.async {
|
||||
self.selectedPage = nil
|
||||
}
|
||||
showPagePicker = false
|
||||
}
|
||||
Button("Cancel", role: .cancel) {
|
||||
showPagePicker = false
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle("Pick a page")
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
PagePickerView(showPagePicker: .constant(true),
|
||||
selectedPage: .constant(nil))
|
||||
.environmentObject(Content.mock)
|
||||
}
|
@ -13,20 +13,18 @@ private struct CenteredPost<Content>: View where Content: View {
|
||||
HorizontalCenter {
|
||||
content
|
||||
}
|
||||
.listRowBackground(PostList.background)
|
||||
.listRowBackground(ColorPalette.listBackground)
|
||||
}
|
||||
}
|
||||
|
||||
struct PostList: View {
|
||||
|
||||
static let background = Color(r: 2, g: 15, b: 26)
|
||||
|
||||
@Binding
|
||||
var posts: [Post]
|
||||
@EnvironmentObject
|
||||
private var content: Content
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
if posts.isEmpty {
|
||||
if content.posts.isEmpty {
|
||||
CenteredPost {
|
||||
Text("No posts yet.")
|
||||
.padding()
|
||||
@ -40,7 +38,7 @@ struct PostList: View {
|
||||
.padding()
|
||||
.listRowSeparator(.hidden)
|
||||
}
|
||||
ForEach(posts) { post in
|
||||
ForEach(content.posts) { post in
|
||||
CenteredPost {
|
||||
PostView(post: post)
|
||||
.frame(maxWidth: 600)
|
||||
@ -50,7 +48,7 @@ struct PostList: View {
|
||||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
.background(PostList.background)
|
||||
.background(ColorPalette.listBackground)
|
||||
.scrollContentBackground(.hidden)
|
||||
}
|
||||
|
||||
@ -64,10 +62,11 @@ struct PostList: View {
|
||||
tags: [],
|
||||
german: .init(title: "Titel", content: "Text"),
|
||||
english: .init(title: "Title", content: "Text"))
|
||||
posts.insert(post, at: 0)
|
||||
content.posts.insert(post, at: 0)
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
PostList(posts: .constant([.mock, .fullMock]))
|
||||
PostList()
|
||||
.environmentObject(Content())
|
||||
}
|
||||
|
@ -11,6 +11,16 @@ struct PostView: View {
|
||||
@State
|
||||
private var showDatePicker = false
|
||||
|
||||
@State
|
||||
private var showPagePicker = false
|
||||
|
||||
private var linkedPageText: String {
|
||||
if let page = post.linkedPage {
|
||||
return page.localized(in: language).title
|
||||
}
|
||||
return "Add linked page"
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .center) {
|
||||
if !post.localized(in: language).images.isEmpty {
|
||||
@ -25,7 +35,7 @@ struct PostView: View {
|
||||
Spacer()
|
||||
Toggle("Draft", isOn: $post.isDraft)
|
||||
}
|
||||
.foregroundStyle(Color(r: 96, g: 186, b: 255))
|
||||
.foregroundStyle(ColorPalette.postDate)
|
||||
TextField("", text: post.localized(in: language).editableTitle())
|
||||
.font(.system(size: 24, weight: .bold))
|
||||
.foregroundStyle(Color.white)
|
||||
@ -46,7 +56,7 @@ struct PostView: View {
|
||||
.resizable()
|
||||
.aspectRatio(1, contentMode: .fit)
|
||||
.frame(height: 18)
|
||||
.foregroundColor(TagView.foreground)
|
||||
.foregroundColor(ColorPalette.tagForeground)
|
||||
.opacity(0.7)
|
||||
.padding(.top, 3)
|
||||
}
|
||||
@ -54,17 +64,31 @@ struct PostView: View {
|
||||
}
|
||||
TextEditor(text: post.localized(in: language).editableContent())
|
||||
.font(.body)
|
||||
.foregroundStyle(Color(r: 221, g: 221, b: 221))
|
||||
.foregroundStyle(ColorPalette.postText)
|
||||
.textEditorStyle(.plain)
|
||||
.padding(.leading, -5)
|
||||
.scrollDisabled(true)
|
||||
HorizontalCenter {
|
||||
Button(action: { showPagePicker = true }) {
|
||||
Text(linkedPageText)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.foregroundStyle(ColorPalette.postDate)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.background(Color(r: 4, g: 31, b: 52))
|
||||
.background(ColorPalette.postBackground)
|
||||
.cornerRadius(8)
|
||||
.sheet(isPresented: $showDatePicker) {
|
||||
DatePickerView(post: post, showDatePicker: $showDatePicker)
|
||||
DatePickerView(
|
||||
post: post,
|
||||
showDatePicker: $showDatePicker)
|
||||
}
|
||||
.sheet(isPresented: $showPagePicker) {
|
||||
PagePickerView(
|
||||
showPagePicker: $showPagePicker,
|
||||
selectedPage: $post.linkedPage)
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,11 +105,11 @@ struct PostView: View {
|
||||
List {
|
||||
PostView(post: .fullMock)
|
||||
.listRowSeparator(.hidden)
|
||||
.listRowBackground(Color(r: 2, g: 15, b: 26))
|
||||
.listRowBackground(ColorPalette.listBackground)
|
||||
.environment(\.language, ContentLanguage.german)
|
||||
PostView(post: .mock)
|
||||
.listRowSeparator(.hidden)
|
||||
.listRowBackground(Color(r: 2, g: 15, b: 26))
|
||||
.listRowBackground(ColorPalette.listBackground)
|
||||
}
|
||||
.listStyle(.plain)
|
||||
}
|
||||
|
@ -4,10 +4,6 @@ import SFSafeSymbols
|
||||
|
||||
struct TagView: View {
|
||||
|
||||
static let background = Color(r: 9, g: 62, b: 103)
|
||||
|
||||
static let foreground = Color(r: 96, g: 186, b: 255)
|
||||
|
||||
@Environment(\.language)
|
||||
var language: ContentLanguage
|
||||
|
||||
@ -37,11 +33,11 @@ struct TagView: View {
|
||||
.opacity(0.7)
|
||||
.padding(.leading, -5)
|
||||
}
|
||||
.foregroundColor(TagView.foreground)
|
||||
.foregroundColor(ColorPalette.tagForeground)
|
||||
.font(.caption2)
|
||||
.padding(.horizontal, 8)
|
||||
.padding(.vertical, 4)
|
||||
.background(TagView.background)
|
||||
.background(ColorPalette.tagBackground)
|
||||
.cornerRadius(8)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user