Skip to content

Commit

Permalink
implemented adding images to note
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrcc committed Dec 16, 2023
1 parent ff7ba21 commit 4ecf957
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 26 deletions.
Binary file modified .DS_Store
Binary file not shown.
19 changes: 4 additions & 15 deletions notes-ios/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,22 @@
}
}
},
"Delete" : {
"Create" : {
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Löschen"
"value" : "Erstellen"
}
}
}
},
"Language" : {
"extractionState" : "stale",
"Delete" : {
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Sprache"
"value" : "Löschen"
}
}
}
Expand Down Expand Up @@ -82,16 +81,6 @@
}
}
},
"Save" : {
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Speichern"
}
}
}
},
"Title" : {
"localizations" : {
"de" : {
Expand Down
2 changes: 1 addition & 1 deletion notes-ios/components/NoteList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct NoteList: View {
var body: some View {
List($viewModel.notes) { $item in
NavigationLink {
NoteView(note: $item, viewModel: viewModel, uiImages: [])
NoteView(note: $item, viewModel: viewModel)
} label: {
NoteRow(note: item)
.swipeActions(allowsFullSwipe: false) {
Expand Down
1 change: 1 addition & 0 deletions notes-ios/domain/Note.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ struct Note: Identifiable, Codable {
var id: UUID
var title: String
var text: String
var images: [Data] = []
}
2 changes: 1 addition & 1 deletion notes-ios/views/CreateNoteView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct CreateNoteView: View {
}

var createNoteMenu: some View {
Button("Save") {
Button("Create") {
Task {
await self.viewModel.addNote(note:note)
self.mode.wrappedValue.dismiss()
Expand Down
20 changes: 11 additions & 9 deletions notes-ios/views/NoteView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@ struct NoteView: View {
@ObservedObject var viewModel: ViewModel

@State private var selectedPhotos = [PhotosPickerItem]()
@State var uiImages: [UIImage]

var body: some View {
NavigationStack {
VStack(alignment: .leading) {
TextField("Title", text: $note.title)
.font(.title).bold()
if !uiImages.isEmpty {
if !note.images.isEmpty {
Divider()
HStack {
ScrollView(.horizontal) {
LazyHStack{
ForEach(uiImages, id: \.self) { photo in
Image(uiImage: photo)
.resizable()
.scaledToFit()
.frame(width: 90, height: 90)
ForEach(note.images, id: \.self) { data in
if let uiImage = UIImage(data: data) {
Image(uiImage: uiImage)
.resizable()
.scaledToFit()
.frame(width: 90, height: 90)
}
}
}
}
Expand All @@ -44,13 +45,14 @@ struct NoteView: View {
.padding()
.padding(.top, 0)
.onChange(of: selectedPhotos) { _, result in
uiImages.removeAll()
note.images.removeAll()
Task {
for photo in selectedPhotos {
do {
if let data = try await photo.loadTransferable(type: Data.self) {
if let uiImage = UIImage(data: data) {
self.uiImages.append(uiImage)

note.images.append(data)
}
}
} catch {
Expand Down

0 comments on commit 4ecf957

Please sign in to comment.