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/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..40ca2d6 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 @@ -48,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/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..86dd654 100644 --- a/windows/ReactNativeNotes/NativeModules/Repository/Repository.cpp +++ b/windows/ReactNativeNotes/NativeModules/Repository/Repository.cpp @@ -6,40 +6,27 @@ 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 + NoteModel Repository::Read( const int index ) const noexcept { - for( auto it = notes.cbegin(); it != notes.cend(); ++it ) + if( index < notes.size() ) { - if( it->ID() == ID ) - return it.operator*(); + return notes.at( index ); } - return NoteModel(); - } - - NoteModel Repository::Read( const int index ) const noexcept - { - if( index >= notes.size() ) - return NoteModel(); else - return notes.at(index); - } - - void Repository::Update( const NoteModel& note ) noexcept - { - if( note.ID() < notes.size() ) { - notes[note.ID()] = note; + return NoteModel(); } } - void Repository::Delete( const unsigned int ID ) noexcept + void Repository::Update( const NoteModel& note, const unsigned int& index ) noexcept { - auto it = std::find( notes.cbegin(), notes.cend(), Read(ID) ); - notes.erase( it ); + if( index < notes.size() ) + { + notes[index] = note; + } } void Repository::Delete( const int index ) noexcept @@ -52,10 +39,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: 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} + +