и комментарии покрасивее ибо кошмар какое уродство было
This commit is contained in:
parent
0a7c561387
commit
08119cd209
@ -11,77 +11,120 @@ struct AddCommentView: View {
|
|||||||
@State private var isLoading = false
|
@State private var isLoading = false
|
||||||
@State private var errorMessage: String?
|
@State private var errorMessage: String?
|
||||||
@State private var showingSuccess = false
|
@State private var showingSuccess = false
|
||||||
|
@FocusState private var isTextFocused: Bool
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
Form {
|
VStack(spacing: 0) {
|
||||||
Section {
|
VStack(spacing: 16) {
|
||||||
TextField("Текст комментария", text: $text)
|
VStack(alignment: .leading, spacing: 8) {
|
||||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
|
||||||
.frame(minHeight: 100)
|
|
||||||
}
|
|
||||||
.ignoresSafeArea(.keyboard, edges: .bottom)
|
|
||||||
|
|
||||||
Section {
|
|
||||||
if !settings.passcode.isEmpty {
|
|
||||||
HStack {
|
HStack {
|
||||||
Image(systemName: "checkmark.circle.fill")
|
Text("Комментарий")
|
||||||
.foregroundColor(.green)
|
.font(.headline)
|
||||||
Text("Passcode настроен")
|
.foregroundColor(.primary)
|
||||||
.foregroundColor(.green)
|
Spacer()
|
||||||
}
|
Text("\(text.count)")
|
||||||
} else {
|
|
||||||
HStack {
|
|
||||||
Image(systemName: "exclamationmark.triangle.fill")
|
|
||||||
.foregroundColor(.orange)
|
|
||||||
VStack(alignment: .leading) {
|
|
||||||
Text("Passcode не настроен")
|
|
||||||
.foregroundColor(.orange)
|
|
||||||
Text("Постинг может быть ограничен")
|
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextEditor(text: $text)
|
||||||
|
.focused($isTextFocused)
|
||||||
|
.frame(minHeight: 120)
|
||||||
|
.padding(12)
|
||||||
|
.background(Color(.secondarySystemBackground))
|
||||||
|
.cornerRadius(12)
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: 12)
|
||||||
|
.stroke(isTextFocused ? Color.accentColor : Color.clear, lineWidth: 2)
|
||||||
|
)
|
||||||
|
.overlay(
|
||||||
|
Group {
|
||||||
|
if text.isEmpty {
|
||||||
|
HStack {
|
||||||
|
VStack {
|
||||||
|
Text("Напишите ваш комментарий...")
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.padding(.top, 20)
|
||||||
|
.padding(.leading, 16)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack(spacing: 8) {
|
||||||
|
Image(systemName: settings.passcode.isEmpty ? "exclamationmark.triangle.fill" : "checkmark.circle.fill")
|
||||||
|
.foregroundColor(settings.passcode.isEmpty ? .orange : .green)
|
||||||
|
|
||||||
|
Text(settings.passcode.isEmpty ? "Passcode не настроен" : "Passcode настроен")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(settings.passcode.isEmpty ? .orange : .green)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 4)
|
||||||
|
|
||||||
if let error = errorMessage {
|
if let error = errorMessage {
|
||||||
Section {
|
HStack {
|
||||||
Text(error)
|
Image(systemName: "xmark.circle.fill")
|
||||||
.foregroundColor(.red)
|
.foregroundColor(.red)
|
||||||
|
Text(error)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.red)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 4)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.padding(.horizontal, 20)
|
||||||
|
.padding(.top, 20)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
Button(action: addComment) {
|
||||||
|
HStack {
|
||||||
|
if isLoading {
|
||||||
|
ProgressView()
|
||||||
|
.progressViewStyle(CircularProgressViewStyle(tint: .white))
|
||||||
|
.scaleEffect(0.8)
|
||||||
|
} else {
|
||||||
|
Image(systemName: "plus.circle.fill")
|
||||||
}
|
}
|
||||||
.navigationTitle("Комментарий в тред \(threadId)")
|
Text(isLoading ? "Отправка..." : "Добавить комментарий")
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
}
|
||||||
.navigationBarBackButtonHidden(false)
|
.frame(maxWidth: .infinity)
|
||||||
.navigationBarItems(
|
.frame(height: 50)
|
||||||
leading: Button("Отмена") {
|
.background(text.isEmpty || isLoading ? Color.gray : Color.accentColor)
|
||||||
dismiss()
|
.foregroundColor(.white)
|
||||||
},
|
.cornerRadius(25)
|
||||||
trailing: Button("Добавить") {
|
.animation(.easeInOut(duration: 0.2), value: text.isEmpty)
|
||||||
addComment()
|
|
||||||
}
|
}
|
||||||
.disabled(text.isEmpty || isLoading)
|
.disabled(text.isEmpty || isLoading)
|
||||||
)
|
|
||||||
.overlay {
|
Button("Отмена") {
|
||||||
if isLoading {
|
dismiss()
|
||||||
VStack {
|
}
|
||||||
ProgressView()
|
|
||||||
.progressViewStyle(CircularProgressViewStyle())
|
|
||||||
Text("Добавление комментария...")
|
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
.padding(.horizontal, 20)
|
||||||
.background(Color(.systemBackground))
|
.padding(.bottom, 20)
|
||||||
}
|
}
|
||||||
|
.navigationTitle("Тред \(threadId)")
|
||||||
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
|
.onAppear {
|
||||||
|
isTextFocused = true
|
||||||
}
|
}
|
||||||
.alert("Комментарий добавлен", isPresented: $showingSuccess) {
|
.alert("Успешно!", isPresented: $showingSuccess) {
|
||||||
Button("OK") {
|
Button("OK") {
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
} message: {
|
} message: {
|
||||||
Text("Комментарий успешно добавлен")
|
Text("Комментарий добавлен")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,79 +11,143 @@ struct CreateThreadView: View {
|
|||||||
@State private var isLoading = false
|
@State private var isLoading = false
|
||||||
@State private var errorMessage: String?
|
@State private var errorMessage: String?
|
||||||
@State private var showingSuccess = false
|
@State private var showingSuccess = false
|
||||||
|
@FocusState private var titleFocused: Bool
|
||||||
|
@FocusState private var textFocused: Bool
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
Form {
|
VStack(spacing: 0) {
|
||||||
Section {
|
ScrollView {
|
||||||
TextField("Заголовок треда", text: $title)
|
VStack(spacing: 20) {
|
||||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
VStack(alignment: .leading, spacing: 8) {
|
||||||
|
|
||||||
TextField("Текст треда", text: $text)
|
|
||||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
|
||||||
.frame(minHeight: 100)
|
|
||||||
}
|
|
||||||
.ignoresSafeArea(.keyboard, edges: .bottom)
|
|
||||||
|
|
||||||
Section {
|
|
||||||
if !settings.passcode.isEmpty {
|
|
||||||
HStack {
|
HStack {
|
||||||
Image(systemName: "checkmark.circle.fill")
|
Text("Заголовок")
|
||||||
.foregroundColor(.green)
|
.font(.headline)
|
||||||
Text("Passcode настроен")
|
.foregroundColor(.primary)
|
||||||
.foregroundColor(.green)
|
Spacer()
|
||||||
}
|
Text("\(title.count)")
|
||||||
} else {
|
|
||||||
HStack {
|
|
||||||
Image(systemName: "exclamationmark.triangle.fill")
|
|
||||||
.foregroundColor(.orange)
|
|
||||||
VStack(alignment: .leading) {
|
|
||||||
Text("Passcode не настроен")
|
|
||||||
.foregroundColor(.orange)
|
|
||||||
Text("Постинг может быть ограничен")
|
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
TextField("Введите заголовок треда", text: $title)
|
||||||
|
.focused($titleFocused)
|
||||||
|
.padding(16)
|
||||||
|
.background(Color(.secondarySystemBackground))
|
||||||
|
.cornerRadius(12)
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: 12)
|
||||||
|
.stroke(titleFocused ? Color.accentColor : Color.clear, lineWidth: 2)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let error = errorMessage {
|
VStack(alignment: .leading, spacing: 8) {
|
||||||
Section {
|
HStack {
|
||||||
Text(error)
|
Text("Содержание")
|
||||||
.foregroundColor(.red)
|
.font(.headline)
|
||||||
}
|
.foregroundColor(.primary)
|
||||||
}
|
Spacer()
|
||||||
}
|
Text("\(text.count)")
|
||||||
.navigationTitle("Создать тред /\(boardCode)/")
|
.font(.caption)
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
|
||||||
.navigationBarItems(
|
|
||||||
leading: Button("Отмена") {
|
|
||||||
dismiss()
|
|
||||||
},
|
|
||||||
trailing: Button("Создать") {
|
|
||||||
createThread()
|
|
||||||
}
|
|
||||||
.disabled(title.isEmpty || text.isEmpty || isLoading)
|
|
||||||
)
|
|
||||||
.overlay {
|
|
||||||
if isLoading {
|
|
||||||
VStack {
|
|
||||||
ProgressView()
|
|
||||||
.progressViewStyle(CircularProgressViewStyle())
|
|
||||||
Text("Создание треда...")
|
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
||||||
.background(Color(.systemBackground))
|
TextEditor(text: $text)
|
||||||
|
.focused($textFocused)
|
||||||
|
.frame(minHeight: 140)
|
||||||
|
.padding(12)
|
||||||
|
.background(Color(.secondarySystemBackground))
|
||||||
|
.cornerRadius(12)
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: 12)
|
||||||
|
.stroke(textFocused ? Color.accentColor : Color.clear, lineWidth: 2)
|
||||||
|
)
|
||||||
|
.overlay(
|
||||||
|
Group {
|
||||||
|
if text.isEmpty {
|
||||||
|
HStack {
|
||||||
|
VStack {
|
||||||
|
Text("Напишите содержание треда...")
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.padding(.top, 20)
|
||||||
|
.padding(.leading, 16)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.alert("Тред создан", isPresented: $showingSuccess) {
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack(spacing: 8) {
|
||||||
|
Image(systemName: settings.passcode.isEmpty ? "exclamationmark.triangle.fill" : "checkmark.circle.fill")
|
||||||
|
.foregroundColor(settings.passcode.isEmpty ? .orange : .green)
|
||||||
|
|
||||||
|
Text(settings.passcode.isEmpty ? "Passcode не настроен" : "Passcode настроен")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(settings.passcode.isEmpty ? .orange : .green)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 4)
|
||||||
|
|
||||||
|
if let error = errorMessage {
|
||||||
|
HStack {
|
||||||
|
Image(systemName: "xmark.circle.fill")
|
||||||
|
.foregroundColor(.red)
|
||||||
|
Text(error)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.red)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 20)
|
||||||
|
.padding(.top, 20)
|
||||||
|
}
|
||||||
|
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
Button(action: createThread) {
|
||||||
|
HStack {
|
||||||
|
if isLoading {
|
||||||
|
ProgressView()
|
||||||
|
.progressViewStyle(CircularProgressViewStyle(tint: .white))
|
||||||
|
.scaleEffect(0.8)
|
||||||
|
} else {
|
||||||
|
Image(systemName: "plus.circle.fill")
|
||||||
|
}
|
||||||
|
Text(isLoading ? "Создание..." : "Создать тред")
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.frame(height: 50)
|
||||||
|
.background(title.isEmpty || text.isEmpty || isLoading ? Color.gray : Color.accentColor)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.cornerRadius(25)
|
||||||
|
.animation(.easeInOut(duration: 0.2), value: title.isEmpty || text.isEmpty)
|
||||||
|
}
|
||||||
|
.disabled(title.isEmpty || text.isEmpty || isLoading)
|
||||||
|
|
||||||
|
Button("Отмена") {
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 20)
|
||||||
|
.padding(.bottom, 20)
|
||||||
|
}
|
||||||
|
.navigationTitle("/\(boardCode)/")
|
||||||
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
|
.onAppear {
|
||||||
|
titleFocused = true
|
||||||
|
}
|
||||||
|
.alert("Успешно!", isPresented: $showingSuccess) {
|
||||||
Button("OK") {
|
Button("OK") {
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
} message: {
|
} message: {
|
||||||
Text("Тред успешно создан")
|
Text("Тред создан")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user