From 884dd5d013adec839bb51ca5be21133d7744f7c2 Mon Sep 17 00:00:00 2001 From: Bartosz Klonowski <70535775+BartoszKlonowski@users.noreply.github.com> Date: Tue, 29 Jun 2021 12:26:02 +0200 Subject: [PATCH 1/3] Remove ID of Note --- .../NativeModules/DatabaseHandler.hpp | 2 +- .../NativeModules/Repository/NoteModel.cpp | 16 +++-------- .../NativeModules/Repository/NoteModel.hpp | 6 +---- .../NativeModules/Repository/Repository.cpp | 27 +++---------------- .../NativeModules/Repository/Repository.hpp | 5 +--- 5 files changed, 9 insertions(+), 47 deletions(-) diff --git a/windows/ReactNativeNotes/NativeModules/DatabaseHandler.hpp b/windows/ReactNativeNotes/NativeModules/DatabaseHandler.hpp index c53fb82..c153637 100644 --- a/windows/ReactNativeNotes/NativeModules/DatabaseHandler.hpp +++ b/windows/ReactNativeNotes/NativeModules/DatabaseHandler.hpp @@ -26,7 +26,7 @@ namespace winrt::ReactNativeNotes::implementation REACT_METHOD( UpdateNote, L"updateNote" ); void UpdateNote( const std::string noteTitle, const std::string noteFullMessage, const unsigned int id ) noexcept { - data->Update( std::move(NoteModel( noteTitle, false, noteFullMessage, id )) ); + data->Update( std::move(NoteModel( noteTitle, false, noteFullMessage )), id ); } REACT_METHOD( GetNoteTitle, L"getNoteTitle" ); diff --git a/windows/ReactNativeNotes/NativeModules/Repository/NoteModel.cpp b/windows/ReactNativeNotes/NativeModules/Repository/NoteModel.cpp index 23e837b..ecdc407 100644 --- a/windows/ReactNativeNotes/NativeModules/Repository/NoteModel.cpp +++ b/windows/ReactNativeNotes/NativeModules/Repository/NoteModel.cpp @@ -4,24 +4,14 @@ namespace winrt::ReactNativeNotes::implementation { - NoteModel::NoteModel( const std::string& title, const bool& isDone, const std::string& post, const unsigned int& ID ) - : title{title}, isDone{isDone}, post{post}, id{ID} + NoteModel::NoteModel( const std::string& title, const bool& isDone, const std::string& post ) + : title{title}, isDone{isDone}, post{post} { } bool NoteModel::operator==( const NoteModel& model ) const { - return this->id == model.id; - } - - unsigned int NoteModel::ID() const noexcept - { - return id; - } - - void NoteModel::ID( unsigned int ID ) noexcept - { - this->id = ID; + return this->title == model.title; } std::string NoteModel::Title() const noexcept diff --git a/windows/ReactNativeNotes/NativeModules/Repository/NoteModel.hpp b/windows/ReactNativeNotes/NativeModules/Repository/NoteModel.hpp index ef496bc..1a72d47 100644 --- a/windows/ReactNativeNotes/NativeModules/Repository/NoteModel.hpp +++ b/windows/ReactNativeNotes/NativeModules/Repository/NoteModel.hpp @@ -10,13 +10,10 @@ namespace winrt::ReactNativeNotes::implementation public: explicit NoteModel() = default; - NoteModel( const std::string& title, const bool& isDone, const std::string& post = "", const unsigned int& ID = 0 ); + NoteModel( const std::string& title, const bool& isDone, const std::string& post = "" ); bool operator==( const NoteModel& model ) const; - unsigned int ID() const noexcept; - void ID( unsigned int ) noexcept; - std::string Title() const noexcept; void Title( std::string ) noexcept; @@ -29,7 +26,6 @@ namespace winrt::ReactNativeNotes::implementation void IsDone( bool ) noexcept; private: - unsigned int id; std::string title; std::string post; bool isDone; diff --git a/windows/ReactNativeNotes/NativeModules/Repository/Repository.cpp b/windows/ReactNativeNotes/NativeModules/Repository/Repository.cpp index 7a319de..f761c0f 100644 --- a/windows/ReactNativeNotes/NativeModules/Repository/Repository.cpp +++ b/windows/ReactNativeNotes/NativeModules/Repository/Repository.cpp @@ -6,20 +6,9 @@ namespace winrt::ReactNativeNotes::implementation { void Repository::Create( NoteModel& note ) noexcept { - note.ID( static_cast(notes.size()) ); notes.push_back( note ); } - NoteModel Repository::Read( const unsigned int ID ) const noexcept - { - for( auto it = notes.cbegin(); it != notes.cend(); ++it ) - { - if( it->ID() == ID ) - return it.operator*(); - } - return NoteModel(); - } - NoteModel Repository::Read( const int index ) const noexcept { if( index >= notes.size() ) @@ -28,20 +17,14 @@ namespace winrt::ReactNativeNotes::implementation return notes.at(index); } - void Repository::Update( const NoteModel& note ) noexcept + void Repository::Update( const NoteModel& note, const unsigned int& index ) noexcept { - if( note.ID() < notes.size() ) + if( index < notes.size() ) { - notes[note.ID()] = note; + notes[index] = note; } } - void Repository::Delete( const unsigned int ID ) noexcept - { - auto it = std::find( notes.cbegin(), notes.cend(), Read(ID) ); - notes.erase( it ); - } - void Repository::Delete( const int index ) noexcept { notes.erase( notes.cbegin() + index ); @@ -52,10 +35,6 @@ namespace winrt::ReactNativeNotes::implementation return notes.size(); } - const bool Repository::Exists( const unsigned int ID ) const noexcept - { - return std::find_if( notes.cbegin(), notes.cend(), [=]( const NoteModel& n )->bool { return n.ID() == ID; } ) != notes.cend(); - } const bool Repository::Exists( const int index ) const noexcept { return index < notes.size(); diff --git a/windows/ReactNativeNotes/NativeModules/Repository/Repository.hpp b/windows/ReactNativeNotes/NativeModules/Repository/Repository.hpp index 81bfe7b..97cd894 100644 --- a/windows/ReactNativeNotes/NativeModules/Repository/Repository.hpp +++ b/windows/ReactNativeNotes/NativeModules/Repository/Repository.hpp @@ -18,17 +18,14 @@ namespace winrt::ReactNativeNotes::implementation void Create( NoteModel& note ) noexcept; - NoteModel Read( const unsigned int ID ) const noexcept; NoteModel Read( const int index ) const noexcept; - void Update( const NoteModel& note ) noexcept; + void Update( const NoteModel& note, const unsigned int& index ) noexcept; - void Delete( const unsigned int ID ) noexcept; void Delete( const int index ) noexcept; unsigned int Size() const noexcept; - const bool Exists( const unsigned int ID ) const noexcept; const bool Exists( const int index ) const noexcept; private: From 3027383e2f3a7588b616cdba56eae337a5069efa Mon Sep 17 00:00:00 2001 From: Bartosz Klonowski <70535775+BartoszKlonowski@users.noreply.github.com> Date: Tue, 29 Jun 2021 12:36:56 +0200 Subject: [PATCH 2/3] Invert case for Read of note within collection range --- .../NativeModules/Repository/NoteModel.cpp | 4 ++++ .../NativeModules/Repository/Repository.cpp | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/windows/ReactNativeNotes/NativeModules/Repository/NoteModel.cpp b/windows/ReactNativeNotes/NativeModules/Repository/NoteModel.cpp index ecdc407..40ca2d6 100644 --- a/windows/ReactNativeNotes/NativeModules/Repository/NoteModel.cpp +++ b/windows/ReactNativeNotes/NativeModules/Repository/NoteModel.cpp @@ -38,9 +38,13 @@ namespace winrt::ReactNativeNotes::implementation { const unsigned int shortMessageTextLength = 97; if( post.size() > 100 ) + { return post.substr( 0, shortMessageTextLength ).append( "..." ); + } else + { return post; + } } bool NoteModel::IsDone() const noexcept diff --git a/windows/ReactNativeNotes/NativeModules/Repository/Repository.cpp b/windows/ReactNativeNotes/NativeModules/Repository/Repository.cpp index f761c0f..86dd654 100644 --- a/windows/ReactNativeNotes/NativeModules/Repository/Repository.cpp +++ b/windows/ReactNativeNotes/NativeModules/Repository/Repository.cpp @@ -11,10 +11,14 @@ namespace winrt::ReactNativeNotes::implementation NoteModel Repository::Read( const int index ) const noexcept { - if( index >= notes.size() ) - return NoteModel(); + if( index < notes.size() ) + { + return notes.at( index ); + } else - return notes.at(index); + { + return NoteModel(); + } } void Repository::Update( const NoteModel& note, const unsigned int& index ) noexcept From afe5a75edfee8bcf3e1d44be1e0f94dc00114555 Mon Sep 17 00:00:00 2001 From: Bartosz Klonowski <70535775+BartoszKlonowski@users.noreply.github.com> Date: Tue, 29 Jun 2021 13:59:25 +0200 Subject: [PATCH 3/3] Add missing logo in Notes details page --- src/NoteWidgetDetailsPanel.js | 3 +- .../NoteWidgetDetailsPage.xaml | 30 ++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/NoteWidgetDetailsPanel.js b/src/NoteWidgetDetailsPanel.js index 9c408b7..e643514 100644 --- a/src/NoteWidgetDetailsPanel.js +++ b/src/NoteWidgetDetailsPanel.js @@ -139,7 +139,8 @@ const styles = StyleSheet.create({ flex: 1, flexDirection: "column", alignItems: "center", - margin: 30 + margin: 30, + backgroundColor: "transparent" }, titleBox: { borderLeftWidth: 0, diff --git a/windows/ReactNativeNotes/NoteWidgetDetailsPage.xaml b/windows/ReactNativeNotes/NoteWidgetDetailsPage.xaml index 63f81bf..65a3510 100644 --- a/windows/ReactNativeNotes/NoteWidgetDetailsPage.xaml +++ b/windows/ReactNativeNotes/NoteWidgetDetailsPage.xaml @@ -8,15 +8,25 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Background="Transparent"> - - - - - - - - - - + + + + + + + + + + + + + + + + + + {callstack} + +