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

[Fix] 파일 복제 버그 수정 #484

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion Data/CoreData/Repositories/PaperDataRepositoryImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ final class PaperDataRepositoryImpl: PaperDataRepository {
let newUrl = url.deletingLastPathComponent().appending(path: info.title + ".pdf")

if let _ = try? FileManager.default.moveItem(at: url, to: newUrl) {
dataToEdit.url = try! newUrl.bookmarkData(options: .minimalBookmark)
let newBookmarkData = try! newUrl.bookmarkData(options: .minimalBookmark)
dataToEdit.url = newBookmarkData
PDFSharedData.shared.paperInfo?.url = newBookmarkData
Comment on lines +88 to +90
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PDFSharedData에 바뀐 이름을 반영해 저장할 때 사용할 수 있도록 변경함

} else {
return .failure(PDFUploadError.fileNameDuplication)
}
Expand Down
14 changes: 14 additions & 0 deletions Presentation/Helper/Errors/HomeViewError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// HomeViewError.swift
// Reazy
//
// Created by 문인범 on 3/9/25.
//

import Foundation


enum HomeViewError: Error {
case cannotCreateBookmark
case bookmarkNotFound
}
11 changes: 7 additions & 4 deletions Presentation/Home/Paper/PaperListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ struct PaperListView: View {
@State private var isMenuOpen: Bool = false
@State private var buttonPosition: CGRect = .zero

@State private var isErrorAlertPresented: Bool = false

var body: some View {
GeometryReader { geometry in
ZStack {
Expand Down Expand Up @@ -164,7 +166,8 @@ struct PaperListView: View {

if selectedItemID == paperInfo.id {
self.isNavigationPushed = true
navigateToPaper()
// TODO: 에러 처리 필요
try? navigateToPaper()
homeViewModel.updateLastModifiedDate(at: paperInfo.id, lastModifiedDate: Date())
} else {
selectedItemID = paperInfo.id
Expand Down Expand Up @@ -369,7 +372,7 @@ extension PaperListView {
extension PaperListView {

// TODO: URL 분리 필요
private func navigateToPaper() {
private func navigateToPaper() throws {
guard let selectedPaperID = selectedItemID,
let selectedPaper = homeViewModel.paperInfos.first(where: { $0.id == selectedPaperID }) else {
return
Expand All @@ -380,14 +383,14 @@ extension PaperListView {

guard let url = try? URL.init(resolvingBookmarkData: data, bookmarkDataIsStale: &isStale) else {
print("bookmarkdata to url failed")
return
throw HomeViewError.bookmarkNotFound
}

if isStale {
print("Bookmark(\(url.lastPathComponent)) is stale")
guard let newURL = try? url.bookmarkData(options: .minimalBookmark) else {
print("Unable to create bookmark")
return
throw HomeViewError.cannotCreateBookmark
}

let idx = homeViewModel.paperInfos.firstIndex { $0.id == selectedPaperID }!
Expand Down
3 changes: 2 additions & 1 deletion Presentation/MainPDF/MainPDFView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ struct MainPDFView: View {
self.homeViewModel.isInHomeView = true
self.searchViewModel.removeAllAnnotations()
PDFSharedData.shared.updatePaperInfo()
mainPDFViewModel.savePDF(pdfView: mainPDFViewModel.pdfDrawer.pdfView)
// TODO: 에러 처리 필요
try? mainPDFViewModel.savePDF(pdfView: mainPDFViewModel.pdfDrawer.pdfView)
self.focusFigureViewModel.stopTask()
self.focusFigureViewModel.cancellables.removeAll()

Expand Down
10 changes: 5 additions & 5 deletions Presentation/MainPDF/ViewModel/MainPDFViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ final class MainPDFViewModel: ObservableObject {

// MARK: - 초기 세팅 메소드
extension MainPDFViewModel {
public func savePDF(pdfView: PDFView) {
print("savePDF")
public func savePDF(pdfView: PDFView) throws {
var a = false
guard let document = pdfView.document else { return }
guard let pdfURL = document.documentURL else {
guard let pdfURL = PDFSharedData.shared.paperInfo?.url, let url = try? URL(resolvingBookmarkData: pdfURL, bookmarkDataIsStale: &a) else {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pdfView에서 url를 받아와 사용을 했었는데 pdfView에서는 바뀐 url을 반영하지 않아 바뀐 URL을 사용할 수 있게 PDFSharedData에서 받아오도록 변경했습니다

print("PDF URL을 찾을 수 없습니다.")
return
throw HomeViewError.cannotCreateBookmark
}

for pageIndex in 0..<document.pageCount {
Expand All @@ -148,7 +148,7 @@ extension MainPDFViewModel {
// PDF 파일을 지정한 URL에 덮어쓰기 저장
do {
let pdfData = document.dataRepresentation()
try pdfData?.write(to: pdfURL)
try pdfData?.write(to: url)
print("PDF 저장이 완료되었습니다.")
} catch {
print("PDF 저장 중 오류 발생: \(error.localizedDescription)")
Expand Down
7 changes: 7 additions & 0 deletions Reazy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@
path = "Preview Content";
sourceTree = "<group>";
};
2CC7D9032D7D92B700D882D6 /* Errors */ = {
isa = PBXFileSystemSynchronizedRootGroup;
path = Errors;
sourceTree = "<group>";
};
2CEBB8C12D5A407E00EC04D2 /* HomeSearch */ = {
isa = PBXFileSystemSynchronizedRootGroup;
path = HomeSearch;
Expand Down Expand Up @@ -624,6 +629,7 @@
2C1474132CE8F2CC00B35D92 /* Helper */ = {
isa = PBXGroup;
children = (
2CC7D9032D7D92B700D882D6 /* Errors */,
2C14731D2CE73B6F00B35D92 /* NotificationCenter + Extension.swift */,
2CD48F552CFC3F8D004A5949 /* OrientationManager.swift */,
2C1474142CE8F2D500B35D92 /* Navigation */,
Expand Down Expand Up @@ -911,6 +917,7 @@
2C14745F2CE900FE00B35D92 /* DTO */,
2C3A2D092D4CF76800ED121D /* Collection */,
2C5C24142CE9DB6A00C37A1B /* Preview Content */,
2CC7D9032D7D92B700D882D6 /* Errors */,
2CEBB8C12D5A407E00EC04D2 /* HomeSearch */,
6ED57AD02CF6F33C00358561 /* Figure */,
6ED57AD12CF6F34C00358561 /* Collection */,
Expand Down