Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/view creation2 al #40

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,91 +48,63 @@ struct ContentView: View {
// Assign posts to the posts array
self.posts = [post1, post2, post3]
}



var body: some View {
NavigationView{
NavigationView {
VStack {
//gets the list of posts as well as puts it in the order
List(posts, id: \.createdAt) { post in
VStack(alignment: .leading){
Text(post.contents)
.font(.headline)
Text("Posted by: \(post.user.name)")
.font(.subheadline)
Text("Posted at: \(post.createdAt.formatted())")
.font(.subheadline)
VStack(alignment: .leading) {
HStack {
VStack(alignment: .leading, spacing: 4) {
Text(post.contents)
.font(.headline)

Text("Posted by: \(post.user.name)")
.font(.subheadline)

Text("Posted at: \(post.createdAt.formatted())")
.font(.subheadline)
}

Spacer()

if isAdmin {
NavigationLink(destination: deletePostView()) {
Image(systemName: "trash")
.foregroundColor(.red)
}
.buttonStyle(BorderlessButtonStyle()) // Remove button background padding
.frame(width: 24, height: 24) // Adjust to fit icon size exactly
}
}

ForEach(post.comments, id: \.createdAt){ comment in
Text(comment.contents)
.font(.body)
.padding(.leading)
NavigationLink(destination: commentView(comments: post.comments)) {
Text("View all comments")
.font(.caption)
.foregroundColor(.blue)
.padding(.top, 5)
}

if isLoggedIn{
//when the user is logged in they will see the comment button and can make a comment
NavigationLink(destination: newCommentView())
{
Text("Add a comment").font(.caption).foregroundColor(.blue)
if isLoggedIn {
NavigationLink(destination: newCommentView()) {
Text("Add a comment")
.font(.caption)
.foregroundColor(.blue)
}
// THIS IS ALL OLD CODE, I DID not want to delete it bc it helps see //thought process
// Button(action: {
// selectedPost = post
// showNewCommentForm.toggle()
// }){
// Text("Add a comment")
// .font(.caption)
// .foregroundColor(.blue)
// }
// .sheet(isPresented: $showNewCommentForm)
// {
// VStack
// {
// Text("Add a comment").font(.title2)
// TextField("Enter comment", text: $newCommentString)
// .textFieldStyle(RoundedBorderTextFieldStyle())
// .padding()
// Button("Submit")
// {
//
// }
//
// }
// }
}
}
.padding()
}
if isLoggedIn{
NavigationLink(destination: NewPostView())
{

if isLoggedIn {
NavigationLink(destination: NewPostView()) {
Text("Create New Post")
}
.bold()
.padding(.top)
//OLD LOG OUT OR LOG IN CODE. Feel free to delete but is simpler, so can help //see thought process
// Button(action: {
// logout()
// }) {
// Text("Logout")
// .font(.headline)
// .foregroundColor(.blue)
// .padding()
// .frame(maxWidth: .infinity)
// .cornerRadius(10)
// }
//
//
}
// if !isLoggedIn{
// NavigationLink(destination: LoginView())
// {
// Text("Login")
// }
// .bold()
// .padding(.top)
// }

}
//This is whatt allows us to have to login and logout in the top corner
.navigationTitle("Posts")
.navigationBarItems(trailing: HStack {
if !isLoggedIn {
Expand All @@ -142,48 +114,25 @@ struct ContentView: View {
.foregroundColor(.blue)
}
} else {
Button(action: {
logout()
}) {
Button(action: { logout() }) {
Text("Logout")
.font(.headline)
.foregroundColor(.blue)
}
}
})
}
.onAppear{
setupMockData()
.onAppear { setupMockData() }
}
}
func logout(){

func logout() {
isLoggedIn = false
}
}


#Preview {
ContentView()
}



#Preview {
ContentView()
}

// init(loginState: LoginState) {
// self._loginState = State(initialValue: loginState)
// }

//#Preview {
// ContentView(loginState: .notLoggedIn)
//}

// switch loginState {
// case .notLoggedIn:
// //LoginView(loginState: $loginState)
// ForumView(loginState: $loginState)
// case .userLoggedIn:
// UserView(loginState: $loginState)
// case .adminLoggedIn:
// AdminView(loginState: $loginState)
// }
// }
// .padding()
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct LoginView: View {
.frame(maxWidth: .infinity)
.cornerRadius(10)
}

}
.padding()
}
Expand All @@ -70,6 +71,8 @@ struct LoginView: View {
//Actions for the button added here
print("Username: \(username), Password: \(password)" )
}


}
#Preview {
ContentView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Darien Aranda on 11/9/24.
//

import SwiftUI
//import SwiftUI

//struct AdminView: View {
// @Binding var loginState: LoginState
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// commentView.swift
// miniProject-seniorDesign
//
// Created by Austin Lim on 11/12/24.
//

import SwiftUI

struct commentView: View{
let comments: [Comment]

var body : some View{
List(comments, id: \.createdAt) { comment in
VStack(alignment: .leading) {
HStack{
VStack{
Text(comment.contents)
.font(.body)
}
}

}
.padding()
}
.navigationTitle("Comments")

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// deletePostView.swift
// miniProject-seniorDesign
//
// Created by Austin Lim on 11/11/24.
//

import SwiftUI

struct deletePostView: View{
@Environment(\.presentationMode) var presentationMode
var body: some View{
ZStack{
Color.black.opacity(0.4) // Semi-transparent background to simulate a modal overlay
.edgesIgnoringSafeArea(.all) // Extends the overlay to cover the whole screen

VStack(spacing: 20) {
Text("Are you sure you want to delete this post?")
.font(.title2)
.multilineTextAlignment(.center)
.padding()
HStack(spacing: 40){
Button(action:{

}){
Text("No")
.font(.headline)
.foregroundColor(.blue)
.padding()
.frame(width: 100)
.background(Color.white)
.cornerRadius(10)
.shadow(radius: 5)
}
Button(action:{

}){
Text("Yes")
.font(.headline)
.foregroundColor(.blue)
.padding()
.frame(width: 100)
.background(Color.white)
.cornerRadius(10)
.shadow(radius: 5)
}
}
}



}
}
}
#Preview {
ContentView()
}