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

Feat: Social 뷰 UI 및 친구 dummy data 불러오기 구현 #57

Merged
merged 27 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3d38308
Add: SocialViewModel 파일 생성
Eunice0927 Dec 12, 2023
67481f4
Feat: 로그인 하기 전에 보여지는 화면을 구성했다. #46 #47
Eunice0927 Dec 12, 2023
7fd964d
Feat: 친구 샘플 데이터 생성
Eunice0927 Dec 12, 2023
e996bca
Feat: 친구 샘플 데이터 수정
Eunice0927 Dec 12, 2023
f69a107
Feat: 친구가 완료한 투두의 갯수를 계산 해 주는 함수를 추가했다.
Eunice0927 Dec 12, 2023
66551f5
Feat: 친구의 데이터를 가져올 때 가장 최신 데이터를 가져오도록 한다.
Eunice0927 Dec 12, 2023
863ca13
Feat: User의 todoByMonthList Array의 Date를 Formatting한다.
Eunice0927 Dec 12, 2023
848d115
Feat: user의 투두 전체 개수를 세는 함수를 추가했다
Eunice0927 Dec 12, 2023
0c81a94
Feat: 완료한 투두를 세는 함수가 이번 달의 완료한 투두만 count하도록 변경했다
Eunice0927 Dec 12, 2023
7986a7c
Feat: 이번달에 등록된 투두만 가지고 오는지 테스트하기 위한 user4 케이스 추가
Eunice0927 Dec 12, 2023
95b9178
Feat: User4의 프로필 이미지 변경
Eunice0927 Dec 12, 2023
b71a347
Feat: 로그인 후 친구 뷰 UI 구현 #48
Eunice0927 Dec 12, 2023
1b2bea2
Feat: 색상 관리 편의를 위해 View 전체 배경색을 변수로 선언
Eunice0927 Dec 12, 2023
f3fa429
Feat: 관리 편의를 위해 View에 사용된 색상과 사이즈, 폰트 관련 설정값을 변수로 선언
Eunice0927 Dec 12, 2023
93fb71c
Refactor: SocialViewModel 함수의 일부를 재사용 가능하도록 변경
Eunice0927 Dec 12, 2023
9bf7b3e
Feat: 샘플 데이터의 투두가 항상 이미지를 가지도록 변경
Eunice0927 Dec 12, 2023
46bf48c
Feat: setDateFormat함수의 return String 형태 수정
Eunice0927 Dec 12, 2023
ea56b17
Feat: SocialDetailView를 생성하고 View에 선택한 친구의 Data가 보여지도록 했다
Eunice0927 Dec 12, 2023
ca6f55f
Add: SocialDeatilView 파일 생성
Eunice0927 Dec 12, 2023
e4f64d4
Feat: 이번 달 Title은 스크롤 되지 않도록 변경
Eunice0927 Dec 12, 2023
44707ef
Feat: 뷰 상단에 프로필 정보 나타나도록 수정
Eunice0927 Dec 12, 2023
529d8ff
Feat: 응원, 재촉 버튼 구현 #51
Eunice0927 Dec 12, 2023
a922a25
Feat: 친구가 아직 아무 투두리도 작성하지 않았을 경우의 뷰를 디자인
Eunice0927 Dec 12, 2023
0ca609d
Merge branch 'dev' of https://github.com/APP-iOS3rd/PJ2T12_Again12 in…
Eunice0927 Dec 13, 2023
47de9bf
Feat: 로그인 상태 비활성화
Eunice0927 Dec 13, 2023
1eb5fdb
Feat: Model의 Medal을 Hashable하게 변경
Eunice0927 Dec 13, 2023
b15874f
Merge branch 'dev' of https://github.com/APP-iOS3rd/PJ2T12_Again12 in…
Eunice0927 Dec 13, 2023
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
8 changes: 8 additions & 0 deletions PJ2T12_Again12/PJ2T12_Again12.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
0E36BAA32B26B696003EA141 /* HomeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E36BAA22B26B696003EA141 /* HomeViewModel.swift */; };
0E36BAA62B26B6BF003EA141 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E36BAA52B26B6BF003EA141 /* Color.swift */; };
0E36BAB22B26F64C003EA141 /* EditViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E36BAB12B26F64C003EA141 /* EditViewModel.swift */; };
9E7852B12B28419E003BC698 /* SocialViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E7852B02B28419E003BC698 /* SocialViewModel.swift */; };
9E7852B32B2860D5003BC698 /* SocialDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E7852B22B2860D5003BC698 /* SocialDetailView.swift */; };
9E9A102B2B26CF6600A2A73E /* HomeModalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E9A102A2B26CF6600A2A73E /* HomeModalView.swift */; };
01D722B62B28B4C100F93E87 /* StatusModalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01D722B52B28B4C100F93E87 /* StatusModalView.swift */; };
CEB9F57E2B219941005A338E /* PJ2T12_Again12App.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEB9F57D2B219941005A338E /* PJ2T12_Again12App.swift */; };
Expand All @@ -38,6 +40,8 @@
0E36BAA22B26B696003EA141 /* HomeViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HomeViewModel.swift; sourceTree = "<group>"; };
0E36BAA52B26B6BF003EA141 /* Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
0E36BAB12B26F64C003EA141 /* EditViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditViewModel.swift; sourceTree = "<group>"; };
9E7852B02B28419E003BC698 /* SocialViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocialViewModel.swift; sourceTree = "<group>"; };
9E7852B22B2860D5003BC698 /* SocialDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocialDetailView.swift; sourceTree = "<group>"; };
9E9A102A2B26CF6600A2A73E /* HomeModalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeModalView.swift; sourceTree = "<group>"; };
01D722B52B28B4C100F93E87 /* StatusModalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusModalView.swift; sourceTree = "<group>"; };
CEB9F57A2B219941005A338E /* PJ2T12_Again12.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PJ2T12_Again12.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -139,6 +143,7 @@
9E9A102A2B26CF6600A2A73E /* HomeModalView.swift */,
CEB9F59C2B21A9CE005A338E /* SettingsView.swift */,
CEB9F59A2B21A9C5005A338E /* SocialView.swift */,
9E7852B22B2860D5003BC698 /* SocialDetailView.swift */,
CEB9F5962B21A966005A338E /* StatusView.swift */,
01D722B52B28B4C100F93E87 /* StatusModalView.swift */,
CEB9F5902B21A925005A338E /* TodoriTapView.swift */,
Expand All @@ -151,6 +156,7 @@
children = (
0E36BAA22B26B696003EA141 /* HomeViewModel.swift */,
0E36BAB12B26F64C003EA141 /* EditViewModel.swift */,
9E7852B02B28419E003BC698 /* SocialViewModel.swift */,
);
path = ViewModels;
sourceTree = "<group>";
Expand Down Expand Up @@ -239,9 +245,11 @@
CEB9F5952B21A950005A338E /* DetailView.swift in Sources */,
01D722B62B28B4C100F93E87 /* StatusModalView.swift in Sources */,
CEB9F57E2B219941005A338E /* PJ2T12_Again12App.swift in Sources */,
9E7852B32B2860D5003BC698 /* SocialDetailView.swift in Sources */,
CEB9F58F2B219A85005A338E /* User.swift in Sources */,
E3456BB02B26FD2100EEA7B1 /* String.swift in Sources */,
0E36BAA62B26B6BF003EA141 /* Color.swift in Sources */,
9E7852B12B28419E003BC698 /* SocialViewModel.swift in Sources */,
CEB9F59D2B21A9CE005A338E /* SettingsView.swift in Sources */,
CEB9F59B2B21A9C5005A338E /* SocialView.swift in Sources */,
CEE940FA2B26D85700AE52CB /* DataController.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion PJ2T12_Again12/PJ2T12_Again12/Models/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct WantTodo: Identifiable {
var status: Bool
}

struct Medal {
struct Medal: Hashable {
var title: String
var image: String
var status: Bool
Expand Down
152 changes: 152 additions & 0 deletions PJ2T12_Again12/PJ2T12_Again12/ViewModels/SocialViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
//
// SocialViewModel.swift
// PJ2T12_Again12
//
// Created by Eunsu JEONG on 12/12/23.
//

import SwiftUI

@MainActor
class SocialViewModel: ObservableObject {
@Published var isLogin = false
@Published var myFriendsList: [User] = [SampleUsers().userOne, SampleUsers().userTwo, SampleUsers().userThree, SampleUsers().userFour]

func setDateFormat(_ date: Date) -> String {
let year = date.formatted(Date.FormatStyle().year(.defaultDigits))
let month = date.formatted(Date.FormatStyle().month(.twoDigits))

return "\(year).\(month)"
}

///어떤 유저의 가장 최신의 TodoByMonth 데이터가 이번 달인지 판별한다.
func isThisMonth(_ user: User) -> Bool {
var isThisMonth = false

if let recentTodoDate = user.todoByMonthList.last?.date {
if setDateFormat(recentTodoDate) == setDateFormat(Date.now) {
isThisMonth = true
}}
return isThisMonth
}

///어떤 유저가 TodoByMonth 데이터가 있다면 가장 최신 데이터인 todoList를 가지고 온다.
func getTodoList(_ user: User) -> [Todo] {
var result: [Todo] = []

if let todoList = user.todoByMonthList.last?.todoList {
result = todoList
}

return result
}

///어떤 유저가 TodoByMonth 데이터가 있다면 가장 최신 데이터인 wantTodoList를 가지고 온다.
func getWantTodoList(_ user: User) -> [WantTodo] {
var result: [WantTodo] = []

if let wantTodoList = user.todoByMonthList.last?.wantTodoList {
result = wantTodoList
}

return result
}

func countDone(_ user: User) -> Int {
var count = 0

if isThisMonth(user) {
let totalTodo = getTodoList(user)
let totalWantTodo = getWantTodoList(user)

for todo in totalTodo {
if todo.status {
count += 1
}
}

for wantTodo in totalWantTodo {
if wantTodo.status {
count += 1
}
}
}

return count
}

func countTotal(_ user: User) -> Int {
var totalCount = 0

if isThisMonth(user) {
totalCount = getTodoList(user).count + getWantTodoList(user).count
}

return totalCount
}
}

struct SampleTodo {
var toDoOne = Todo(date: Date.now, title: "일찍일어나기", image: "dumbbell", review: "했다", status: true)
var toDoTwo = Todo(date: Date.now, title: "크리스마스 쿠키 만들기", image: "paperplane", review: "", status: false)
var toDoThree = Todo(date: Date.now, title: "열심히 공부하기", image:"book.closed", review: "", status: false)
}

struct SampleWantTodo {
var wantTodoOne = WantTodo(date: Date.now, title: "네트워크 공부", image: "paperplane", review: "", status: false)
var wantTodoTow = WantTodo(date: Date.now, title: "수업 복습", image: "paperplane", review: "무진장 많았는데 결국 난 해냈다", status: true)
var wantTodoThree = WantTodo(date: Date.now, title: "수영하기", image: "dumbbell", review: "드디어 신청", status: true)
}

struct SampleMedal {
var medalOne = Medal(title: "일 년 달성", image: "star", status: false, count: 0)
var medalTwo = Medal(title: "한 달 달성", image: "star.fill", status: true, count: 0)
var medalThree = Medal(title: "하고 싶은 투두 10개 달성", image: "moon.stars.fill", status: true, count: 0)
var medalFour = Medal(title: "해야 하는 투두 10개 달성", image: "moon.stars", status: false, count: 0)
}

struct SampleUsers {
var userOne: User = User(
name: "친구1",
profileImage: "cat",
todoByMonthList: [TodoByMonth(date: Date.now,
todoList: [SampleTodo().toDoOne, SampleTodo().toDoThree],
wantTodoList: [SampleWantTodo().wantTodoOne]
)],
friendList: nil,
medalList: [SampleMedal().medalOne, SampleMedal().medalTwo]
)

var userTwo: User = User(
name: "친구2",
profileImage: "lizard",
todoByMonthList: [TodoByMonth(date: Date.now,
todoList: [SampleTodo().toDoOne, SampleTodo().toDoTwo],
wantTodoList: [SampleWantTodo().wantTodoOne, SampleWantTodo().wantTodoThree]
)],
friendList: nil,
medalList: [SampleMedal().medalOne, SampleMedal().medalFour]
)

var userThree: User = User(
name: "친구3",
profileImage: "tortoise",
todoByMonthList: [TodoByMonth(date: Date.now,
todoList: [SampleTodo().toDoOne, SampleTodo().toDoTwo, SampleTodo().toDoThree],
wantTodoList: [SampleWantTodo().wantTodoThree, SampleWantTodo().wantTodoTow]
)],
friendList: nil,
medalList: [SampleMedal().medalTwo, SampleMedal().medalFour, SampleMedal().medalThree]
)

var userFour: User = User(
name: "친구4",
profileImage: "teddybear",
todoByMonthList: [TodoByMonth(date: Calendar.current.date(from: DateComponents(year: 2023, month: 08, day: 30))!,
todoList: [SampleTodo().toDoOne, SampleTodo().toDoThree],
wantTodoList: [SampleWantTodo().wantTodoOne]
)],
friendList: nil,
medalList: [SampleMedal().medalOne, SampleMedal().medalTwo]
)
}
Loading