Skip to content

Commit

Permalink
feat: #50 Connect all data flow
Browse files Browse the repository at this point in the history
- ์ „์ฒด์ ์œผ๋กœ UI๋ฅผ ์ˆ˜์ •ํ•˜๊ณ , ๊ฐ ํ™”๋ฉด ์ „ํ™˜์‹œ ๋ฐ์ดํ„ฐ๋ฅผ ์—…๋ฐ์ดํŠธ ์‹œ์ผœ์ค๋‹ˆ๋‹ค.
- ์™„๋…์ด ์ด๋ฏธ์ง€๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. (๊ทธ ์™ธ์— ์ด๋ฏธ์ง€๋„)
- ๋‹คํฌ ๋ชจ๋“œ๋ฅผ ๋ง‰์Šต๋‹ˆ๋‹ค.
  • Loading branch information
zaehorang committed Nov 10, 2024
1 parent 17cc7e4 commit 479c850
Show file tree
Hide file tree
Showing 38 changed files with 587 additions and 701 deletions.
6 changes: 2 additions & 4 deletions FiveGuyes/FiveGuyes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
1A27D9662CDB779000D1E14D /* TotalCalendarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A27D9652CDB779000D1E14D /* TotalCalendarView.swift */; };
1A54142B2CD9FEF400283FBD /* BookSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A54142A2CD9FEF400283FBD /* BookSearchView.swift */; };
1AA14A782CDDA30D00B763A6 /* TotalCalendarTextBubble.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AA14A772CDDA30D00B763A6 /* TotalCalendarTextBubble.swift */; };
24360D462CD8A2F800E83D2B /* EmptyDataMainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24360D452CD8A2F800E83D2B /* EmptyDataMainView.swift */; };
24360D482CD8BAF100E83D2B /* EmptyNotiView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24360D472CD8BAF100E83D2B /* EmptyNotiView.swift */; };
24360D4A2CD8BE3C00E83D2B /* FinishGoalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24360D492CD8BE3C00E83D2B /* FinishGoalView.swift */; };
24360D532CD9F3AF00E83D2B /* DailyProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24360D522CD9F3AF00E83D2B /* DailyProgressView.swift */; };
Expand Down Expand Up @@ -63,7 +62,6 @@
1A27D9652CDB779000D1E14D /* TotalCalendarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TotalCalendarView.swift; sourceTree = "<group>"; };
1A54142A2CD9FEF400283FBD /* BookSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = BookSearchView.swift; path = FiveGuyes/Sources/Views/Screen/BookSetting/BookSearch/BookSearchView.swift; sourceTree = SOURCE_ROOT; };
1AA14A772CDDA30D00B763A6 /* TotalCalendarTextBubble.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TotalCalendarTextBubble.swift; sourceTree = "<group>"; };
24360D452CD8A2F800E83D2B /* EmptyDataMainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyDataMainView.swift; sourceTree = "<group>"; };
24360D472CD8BAF100E83D2B /* EmptyNotiView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyNotiView.swift; sourceTree = "<group>"; };
24360D492CD8BE3C00E83D2B /* FinishGoalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinishGoalView.swift; sourceTree = "<group>"; };
24360D522CD9F3AF00E83D2B /* DailyProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyProgressView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -199,7 +197,6 @@
children = (
26890B962CAE811A008DFF49 /* ContentView.swift */,
24360D472CD8BAF100E83D2B /* EmptyNotiView.swift */,
24360D452CD8A2F800E83D2B /* EmptyDataMainView.swift */,
26D852F92CCE40930016239A /* Navigation */,
26D852FB2CCE40BC0016239A /* Screen */,
26D853052CCE44970016239A /* Components */,
Expand Down Expand Up @@ -415,7 +412,6 @@
24360D4A2CD8BE3C00E83D2B /* FinishGoalView.swift in Sources */,
26F19A682CD9EFD800F41D6D /* MainHomeView.swift in Sources */,
26F19A742CDB271E00F41D6D /* NavigationRootView.swift in Sources */,
24360D462CD8A2F800E83D2B /* EmptyDataMainView.swift in Sources */,
264440502CD8A3AC0031A290 /* CompletionReviewView.swift in Sources */,
264440502CD8A3AC0031A290 /* CompletionReviewView.swift in Sources */,
26890B952CAE811A008DFF49 /* FiveGuyesApp.swift in Sources */,
Expand Down Expand Up @@ -582,6 +578,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_UIUserInterfaceStyle = Light;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -617,6 +614,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_UIUserInterfaceStyle = Light;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "x1_Completed.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "x2_Completed.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "x3_Completed.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"images" : [
{
"filename" : "wandoki.png",
"filename" : "x1_Nothing.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "x2_Nothing.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "x3_Nothing.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"images" : [
{
"filename" : "wandoki2.png",
"filename" : "celebratex1.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "celebratex2.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "celebratex3.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions FiveGuyes/FiveGuyes/Resources/Extensions/Date+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,35 @@ extension Date {
let components = calendar.dateComponents([.year, .month], from: self)
return calendar.date(from: components)!
}

/// ์ง€์ •๋œ ์ผ ์ˆ˜๋งŒํผ UTC ๊ธฐ์ค€์œผ๋กœ ๋‚ ์งœ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
/// - Parameter days: ์ถ”๊ฐ€ํ•  ์ผ ์ˆ˜ (์Œ์ˆ˜์ผ ๊ฒฝ์šฐ ๊ฐ์†Œ)
/// - Returns: UTC ๊ธฐ์ค€์œผ๋กœ ์ผ ์ˆ˜๊ฐ€ ์ถ”๊ฐ€๋œ ์ƒˆ๋กœ์šด `Date`
func addDaysInUTC(_ days: Int) -> Date {
var utcCalendar = Calendar.current
utcCalendar.timeZone = TimeZone(secondsFromGMT: 0)! // UTC ์‹œ๊ฐ„๋Œ€ ์„ค์ •
return utcCalendar.date(byAdding: .day, value: days, to: self) ?? self
}

/// ์ง€์ •๋œ ์ผ ์ˆ˜๋งŒํผ ๋‚ ์งœ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
/// - Parameter days: ์ถ”๊ฐ€ํ•  ์ผ ์ˆ˜ (์Œ์ˆ˜์ผ ๊ฒฝ์šฐ ๊ฐ์†Œ)
/// - Returns: ์ผ ์ˆ˜๊ฐ€ ์ถ”๊ฐ€๋œ ์ƒˆ๋กœ์šด `Date`
func addDays(_ days: Int) -> Date {
return Calendar.current.date(byAdding: .day, value: days, to: self) ?? self
}

/// `yyyy๋…„ MM์›” dd์ผ` ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
func toKoreanDateString() -> String {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy๋…„ MM์›” dd์ผ"
return formatter.string(from: self)
}

/// `yyyy๋…„ MM์›” dd์ผ` ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
func toKoreanDateStringWithoutYear() -> String {
let formatter = DateFormatter()
formatter.dateFormat = "MM์›” dd์ผ"
return formatter.string(from: self)
}

}
111 changes: 35 additions & 76 deletions FiveGuyes/FiveGuyes/Sources/Models/BookDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ final class BookDetails {
let coverURL: String?
let totalPages: Int

let startDate: Date
let targetEndDate: Date
var startDate: Date
var targetEndDate: Date

var nonReadingDays: [Date]

Expand All @@ -40,16 +40,48 @@ final class UserBook {
var book: BookDetails
var readingRecords: [String: ReadingRecord] = [:] // Keyed by formatted date strings

// ๊ณ„์‚ฐ ๋กœ์ง์„ ๋” ํŽธํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ๋งˆ์ง€๋ง‰์œผ๋กœ ์ฝ์€ ๋‚ ์˜ ๊ฒฐ๊ณผ๋ฅผ ๋”ฐ๋กœ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
var lastReadDate: Date? // ๋งˆ์ง€๋ง‰ ์ฝ์€ ๋‚ ์งœ
var lastPagesRead: Int = 0 // ๋งˆ์ง€๋ง‰์œผ๋กœ ์ฝ์€ ํŽ˜์ด์ง€ ์ˆ˜

var completionReview = ""

init(book: BookDetails) {
self.book = book
}

/// `pagesRead`๊ฐ€ 0์ด ์•„๋‹Œ ๋‚ ์˜ ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
/// ์ง€๊ธˆ๊นŒ์ง€ ๋…์„œ๋ฅผ ํ•œ ๋‚ ์˜ ์ˆ˜
func nonZeroReadingDaysCount() -> Int {
// ์ฒซ ๋‚ ์€ 1์ผ ์งธ ๋„์ „์ค‘์ด๋‹ˆ๊นŒ + 1์„ ํ•ด์ค€๋‹ค.
let readingDays = readingRecords.values.filter { $0.pagesRead > 0 }
if readingDays.isEmpty {
return 1
}
return readingRecords.values.filter { $0.pagesRead > 0 }.count
}
}

@Observable
final class UserLibrary {
var currentReadingBook: UserBook?
var completedBooks: [BookDetails] = []
var completedBooks: [UserBook?] = []

/// ํ˜„์žฌ ์ฝ๊ณ  ์žˆ๋Š” ์ฑ…์„ ์™„๋… ์ฒ˜๋ฆฌํ•˜๊ณ , `completedBooks`์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
func completeCurrentBook(_ book: UserBook, review: String) {
// ์ฑ…์˜ ์™„๋… ๋‚ ์งœ๋ฅผ ์˜ค๋Š˜๋กœ ์„ค์ •
book.book.targetEndDate = Date()
book.completionReview = review

// ์‹œ์ž‘ ๋‚ ์งœ๊ฐ€ ์ข…๋ฃŒ ๋‚ ์งœ๋ณด๋‹ค ์ดํ›„์— ์žˆ์œผ๋ฉด ์‹œ์ž‘ ๋‚ ์งœ๋„ ์™„๋ฃŒ ๋‚ ์งœ๋กœ ์„ค์ •
if book.book.startDate > book.book.targetEndDate {
book.book.startDate = book.book.targetEndDate
}

// ์™„๋…ํ•œ ์ฑ…์„ completedBooks์— ์ถ”๊ฐ€ํ•˜๊ณ  currentReadingBook์„ nil๋กœ ์„ค์ •
completedBooks.append(book)
currentReadingBook = nil
}
}

extension UserBook {
Expand Down Expand Up @@ -81,76 +113,3 @@ extension UserBook {
return userBook
}
}


//// BookDetails ๋”๋ฏธ ๋ฐ์ดํ„ฐ
//extension BookDetails {
// static func dummyBookDetails1() -> BookDetails {
// let dateFormatter = DateFormatter()
// dateFormatter.dateFormat = "yyyy-MM-dd"
//
// return BookDetails(
// title: "Swift Programming Basics",
// author: "John Doe",
// totalPages: 300,
// startDate: dateFormatter.date(from: "2024-01-01")!,
// targetEndDate: dateFormatter.date(from: "2024-02-01")!,
// nonReadingDays: [
// dateFormatter.date(from: "2024-01-07")!,
// dateFormatter.date(from: "2024-01-14")!,
// dateFormatter.date(from: "2024-01-21")!
// ]
// )
// }
//
// static func dummyBookDetails2() -> BookDetails {
// let dateFormatter = DateFormatter()
// dateFormatter.dateFormat = "yyyy-MM-dd"
//
// return BookDetails(
// title: "Advanced iOS Development",
// author: "Jane Smith",
// totalPages: 450,
// startDate: dateFormatter.date(from: "2023-11-01")!,
// targetEndDate: dateFormatter.date(from: "2023-12-01")!,
// nonReadingDays: [
// dateFormatter.date(from: "2023-11-10")!,
// dateFormatter.date(from: "2023-11-17")!
// ]
// )
// }
//
// static func dummyBookDetails3() -> BookDetails {
// let dateFormatter = DateFormatter()
// dateFormatter.dateFormat = "yyyy-MM-dd"
//
// return BookDetails(
// title: "UI/UX Design Principles",
// author: "Alex Johnson",
// totalPages: 200,
// startDate: dateFormatter.date(from: "2023-10-01")!,
// targetEndDate: dateFormatter.date(from: "2023-10-15")!,
// nonReadingDays: [
// dateFormatter.date(from: "2023-10-05")!
// ]
// )
// }
//}
//
//// CurrentBook ๋”๋ฏธ ๋ฐ์ดํ„ฐ
//extension CurrentBook {
// static func dummyCurrentBook() -> CurrentBook {
// let dateFormatter = DateFormatter()
// dateFormatter.dateFormat = "yyyy-MM-dd"
//
// return CurrentBook(
// details: BookDetails.dummyBookDetails1(),
// currentPage: 150,
// dailyTargets: [
// dateFormatter.date(from: "2024-01-01")!: 100,
// dateFormatter.date(from: "2024-01-02")!: 100,
// dateFormatter.date(from: "2024-01-03")!: 100
// ]
// )
// }
//}
Loading

0 comments on commit 479c850

Please sign in to comment.