Skip to content

Commit

Permalink
Merge pull request #38 from GPle-Team/36-mainpage-refactoring
Browse files Browse the repository at this point in the history
🔀 :: [#36] 메인페이지 리팩토링
  • Loading branch information
shwaaaa authored Dec 30, 2024
2 parents 1186255 + c22c911 commit b024ad0
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 151 deletions.
272 changes: 146 additions & 126 deletions Projects/App/Sources/Feature/MainFeature/Sources/LocationPostView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,142 +32,162 @@ struct LocationPostView: View {
ScrollView {
switch locationType {
case "GYM":
ForEach(viewModel.gymPostList) { post in
DetailView(
postViewModel: PostViewModel(),
postId: post.id,
title: post.title,
name: post.author.name,
grade: post.author.grade,
imageUrl: post.imageUrl,
tagList: post.tagList.map{ ($0.name, $0.id) },
emojiList: [
post.emojiList.chinaCount,
post.emojiList.congCount,
post.emojiList.heartCount,
post.emojiList.poopCount,
post.emojiList.thinkCount,
post.emojiList.thumbsCount
],
checkEmojiList: post.checkEmoji,
createTime: post.createdTime
)

Rectangle()
.foregroundStyle(GPleAsset.Color.gray900.swiftUIColor)
.frame(height: 3)
.padding(.vertical, 10)
if viewModel.gymPostList.isEmpty {
PostEmptyView()
} else {
ForEach(viewModel.gymPostList) { post in
DetailView(
postViewModel: PostViewModel(),
postId: post.id,
title: post.title,
name: post.author.name,
grade: post.author.grade,
imageUrl: post.imageUrl,
tagList: post.tagList.map{ ($0.name, $0.id) },
emojiList: [
post.emojiList.chinaCount,
post.emojiList.congCount,
post.emojiList.heartCount,
post.emojiList.poopCount,
post.emojiList.thinkCount,
post.emojiList.thumbsCount
],
checkEmojiList: post.checkEmoji,
createTime: post.createdTime
)

Rectangle()
.foregroundStyle(GPleAsset.Color.gray900.swiftUIColor)
.frame(height: 3)
.padding(.vertical, 10)
}
}
case "HOME":
ForEach(viewModel.homePostList) { post in
DetailView(
postViewModel: PostViewModel(),
postId: post.id,
title: post.title,
name: post.author.name,
grade: post.author.grade,
imageUrl: post.imageUrl,
tagList: post.tagList.map{ ($0.name, $0.id) },
emojiList: [
post.emojiList.chinaCount,
post.emojiList.congCount,
post.emojiList.heartCount,
post.emojiList.poopCount,
post.emojiList.thinkCount,
post.emojiList.thumbsCount
],
checkEmojiList: post.checkEmoji,
createTime: post.createdTime
)

Rectangle()
.foregroundStyle(GPleAsset.Color.gray900.swiftUIColor)
.frame(height: 3)
.padding(.vertical, 10)
if viewModel.homePostList.isEmpty {
PostEmptyView()
} else {
ForEach(viewModel.homePostList) { post in
DetailView(
postViewModel: PostViewModel(),
postId: post.id,
title: post.title,
name: post.author.name,
grade: post.author.grade,
imageUrl: post.imageUrl,
tagList: post.tagList.map{ ($0.name, $0.id) },
emojiList: [
post.emojiList.chinaCount,
post.emojiList.congCount,
post.emojiList.heartCount,
post.emojiList.poopCount,
post.emojiList.thinkCount,
post.emojiList.thumbsCount
],
checkEmojiList: post.checkEmoji,
createTime: post.createdTime
)

Rectangle()
.foregroundStyle(GPleAsset.Color.gray900.swiftUIColor)
.frame(height: 3)
.padding(.vertical, 10)
}
}
case "PLAYGROUND":
ForEach(viewModel.playgroundPostList) { post in
DetailView(
postViewModel: PostViewModel(),
postId: post.id,
title: post.title,
name: post.author.name,
grade: post.author.grade,
imageUrl: post.imageUrl,
tagList: post.tagList.map{ ($0.name, $0.id) },
emojiList: [
post.emojiList.chinaCount,
post.emojiList.congCount,
post.emojiList.heartCount,
post.emojiList.poopCount,
post.emojiList.thinkCount,
post.emojiList.thumbsCount
],
checkEmojiList: post.checkEmoji,
createTime: post.createdTime
)

Rectangle()
.foregroundStyle(GPleAsset.Color.gray900.swiftUIColor)
.frame(height: 3)
.padding(.vertical, 10)
if viewModel.playgroundPostList.isEmpty {
PostEmptyView()
} else {
ForEach(viewModel.playgroundPostList) { post in
DetailView(
postViewModel: PostViewModel(),
postId: post.id,
title: post.title,
name: post.author.name,
grade: post.author.grade,
imageUrl: post.imageUrl,
tagList: post.tagList.map{ ($0.name, $0.id) },
emojiList: [
post.emojiList.chinaCount,
post.emojiList.congCount,
post.emojiList.heartCount,
post.emojiList.poopCount,
post.emojiList.thinkCount,
post.emojiList.thumbsCount
],
checkEmojiList: post.checkEmoji,
createTime: post.createdTime
)

Rectangle()
.foregroundStyle(GPleAsset.Color.gray900.swiftUIColor)
.frame(height: 3)
.padding(.vertical, 10)
}
}
case "DOMITORY":
ForEach(viewModel.domitoryPostList) { post in
DetailView(
postViewModel: PostViewModel(),
postId: post.id,
title: post.title,
name: post.author.name,
grade: post.author.grade,
imageUrl: post.imageUrl,
tagList: post.tagList.map{ ($0.name, $0.id) },
emojiList: [
post.emojiList.chinaCount,
post.emojiList.congCount,
post.emojiList.heartCount,
post.emojiList.poopCount,
post.emojiList.thinkCount,
post.emojiList.thumbsCount
],
checkEmojiList: post.checkEmoji,
createTime: post.createdTime
)

Rectangle()
.foregroundStyle(GPleAsset.Color.gray900.swiftUIColor)
.frame(height: 3)
.padding(.vertical, 10)
if viewModel.domitoryPostList.isEmpty {
PostEmptyView()
} else {
ForEach(viewModel.domitoryPostList) { post in
DetailView(
postViewModel: PostViewModel(),
postId: post.id,
title: post.title,
name: post.author.name,
grade: post.author.grade,
imageUrl: post.imageUrl,
tagList: post.tagList.map{ ($0.name, $0.id) },
emojiList: [
post.emojiList.chinaCount,
post.emojiList.congCount,
post.emojiList.heartCount,
post.emojiList.poopCount,
post.emojiList.thinkCount,
post.emojiList.thumbsCount
],
checkEmojiList: post.checkEmoji,
createTime: post.createdTime
)

Rectangle()
.foregroundStyle(GPleAsset.Color.gray900.swiftUIColor)
.frame(height: 3)
.padding(.vertical, 10)
}
}
case "WALKING_TRAIL":
ForEach(viewModel.walkingTrailPostList) { post in
DetailView(
postViewModel: PostViewModel(),
postId: post.id,
title: post.title,
name: post.author.name,
grade: post.author.grade,
imageUrl: post.imageUrl,
tagList: post.tagList.map{ ($0.name, $0.id) },
emojiList: [
post.emojiList.chinaCount,
post.emojiList.congCount,
post.emojiList.heartCount,
post.emojiList.poopCount,
post.emojiList.thinkCount,
post.emojiList.thumbsCount
],
checkEmojiList: post.checkEmoji,
createTime: post.createdTime
)

Rectangle()
.foregroundStyle(GPleAsset.Color.gray900.swiftUIColor)
.frame(height: 3)
.padding(.vertical, 10)
if viewModel.walkingTrailPostList.isEmpty {
PostEmptyView()
} else {
ForEach(viewModel.walkingTrailPostList) { post in
DetailView(
postViewModel: PostViewModel(),
postId: post.id,
title: post.title,
name: post.author.name,
grade: post.author.grade,
imageUrl: post.imageUrl,
tagList: post.tagList.map{ ($0.name, $0.id) },
emojiList: [
post.emojiList.chinaCount,
post.emojiList.congCount,
post.emojiList.heartCount,
post.emojiList.poopCount,
post.emojiList.thinkCount,
post.emojiList.thumbsCount
],
checkEmojiList: post.checkEmoji,
createTime: post.createdTime
)

Rectangle()
.foregroundStyle(GPleAsset.Color.gray900.swiftUIColor)
.frame(height: 3)
.padding(.vertical, 10)
}
}
default:
EmptyView()
PostEmptyView()
}
}
.padding(.top, 8)
Expand Down
63 changes: 38 additions & 25 deletions Projects/App/Sources/Feature/MainFeature/Sources/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SwiftUI
struct MainView: View {
@StateObject var viewModel = MainViewModel()
@StateObject var postViewModel: PostViewModel
@State private var selectedIndex = 0

var body: some View {
NavigationView {
Expand Down Expand Up @@ -166,38 +167,38 @@ struct MainView: View {
.foregroundStyle(GPleAsset.Color.gray800.swiftUIColor)
.font(GPleFontFamily.Pretendard.regular.swiftUIFont(size: 14))
}
.padding(.leading, 8)

Text(title)
.foregroundStyle(GPleAsset.Color.white.swiftUIColor)
.font(GPleFontFamily.Pretendard.semiBold.swiftUIFont(size: 18))
.padding(.top, 16)
.padding(.leading, 8)

Text(place)
.foregroundStyle(GPleAsset.Color.gray600.swiftUIColor)
.font(GPleFontFamily.Pretendard.regular.swiftUIFont(size: 14))
.padding(.top, 4)

ForEach(imageURL, id: \.self) { imageURL in
AsyncImage(url: URL(string: imageURL)) { phase in
switch phase {
case .empty:
ProgressView()
.frame(width: 318, height: 318)
case .success(let image):
image
.resizable()
.scaledToFit()
.frame(width: 318)
.cornerRadius(8)
case .failure:
Image(systemName: "exclamationmark.triangle.fill")
.foregroundColor(.red)
.frame(width: 318, height: 318)
@unknown default:
EmptyView()
.padding(.leading, 8)

TabView(selection: $selectedIndex) {
ForEach(imageURL.indices, id: \.self) { index in
if let imageUrl = URL(string: imageURL[index]) {
AsyncImage(url: imageUrl) { image in
image
.resizable()
.padding(.top, 12)
} placeholder: {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
}
.tag(index)
}
}
}
.padding(.horizontal, 8)
.frame(height: 381)
.tabViewStyle(.page)
.padding(.top, 16)

HStack(spacing: 8) {
Expand All @@ -212,16 +213,28 @@ struct MainView: View {
.foregroundStyle(GPleAsset.Color.gray600.swiftUIColor)
.font(GPleFontFamily.Pretendard.regular.swiftUIFont(size: 14))
.padding(.top, 12)

Text(date)
.foregroundStyle(GPleAsset.Color.gray800.swiftUIColor)
.font(GPleFontFamily.Pretendard.regular.swiftUIFont(size: 14))
.padding(.top, 4)
.padding(.leading, 8)

let dateString = date.split(separator: "T").first
if let dateString = dateString {
let components = dateString.split(separator: "-")
if components.count >= 3 {
var month = String(components[1])
var day = String(components[2])

Text("\(month)\(day)")
.foregroundStyle(GPleAsset.Color.gray800.swiftUIColor)
.font(GPleFontFamily.Pretendard.regular.swiftUIFont(size: 14))
.padding(.top, 6)
.padding(.leading, 8)
}
}

}
.padding(.horizontal, 10)
.padding(.vertical, 20)
.padding(.horizontal, 16)
.background(GPleAsset.Color.gray1000.swiftUIColor)
.cornerRadius(12)
.padding(.horizontal, 20)
}
}
Loading

0 comments on commit b024ad0

Please sign in to comment.