Skip to content

Commit f476cbd

Browse files
Fix: Incorrect note is deleted & opened (#17)
* Remove ID of Note * Invert case for Read of note within collection range * Add missing logo in Notes details page
1 parent c8728f7 commit f476cbd

7 files changed

Lines changed: 41 additions & 60 deletions

File tree

src/NoteWidgetDetailsPanel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ const styles = StyleSheet.create({
139139
flex: 1,
140140
flexDirection: "column",
141141
alignItems: "center",
142-
margin: 30
142+
margin: 30,
143+
backgroundColor: "transparent"
143144
},
144145
titleBox: {
145146
borderLeftWidth: 0,

windows/ReactNativeNotes/NativeModules/DatabaseHandler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace winrt::ReactNativeNotes::implementation
2626
REACT_METHOD( UpdateNote, L"updateNote" );
2727
void UpdateNote( const std::string noteTitle, const std::string noteFullMessage, const unsigned int id ) noexcept
2828
{
29-
data->Update( std::move(NoteModel( noteTitle, false, noteFullMessage, id )) );
29+
data->Update( std::move(NoteModel( noteTitle, false, noteFullMessage )), id );
3030
}
3131

3232
REACT_METHOD( GetNoteTitle, L"getNoteTitle" );

windows/ReactNativeNotes/NativeModules/Repository/NoteModel.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,14 @@
44

55
namespace winrt::ReactNativeNotes::implementation
66
{
7-
NoteModel::NoteModel( const std::string& title, const bool& isDone, const std::string& post, const unsigned int& ID )
8-
: title{title}, isDone{isDone}, post{post}, id{ID}
7+
NoteModel::NoteModel( const std::string& title, const bool& isDone, const std::string& post )
8+
: title{title}, isDone{isDone}, post{post}
99
{
1010
}
1111

1212
bool NoteModel::operator==( const NoteModel& model ) const
1313
{
14-
return this->id == model.id;
15-
}
16-
17-
unsigned int NoteModel::ID() const noexcept
18-
{
19-
return id;
20-
}
21-
22-
void NoteModel::ID( unsigned int ID ) noexcept
23-
{
24-
this->id = ID;
14+
return this->title == model.title;
2515
}
2616

2717
std::string NoteModel::Title() const noexcept
@@ -48,9 +38,13 @@ namespace winrt::ReactNativeNotes::implementation
4838
{
4939
const unsigned int shortMessageTextLength = 97;
5040
if( post.size() > 100 )
41+
{
5142
return post.substr( 0, shortMessageTextLength ).append( "..." );
43+
}
5244
else
45+
{
5346
return post;
47+
}
5448
}
5549

5650
bool NoteModel::IsDone() const noexcept

windows/ReactNativeNotes/NativeModules/Repository/NoteModel.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ namespace winrt::ReactNativeNotes::implementation
1010
public:
1111
explicit NoteModel() = default;
1212

13-
NoteModel( const std::string& title, const bool& isDone, const std::string& post = "", const unsigned int& ID = 0 );
13+
NoteModel( const std::string& title, const bool& isDone, const std::string& post = "" );
1414

1515
bool operator==( const NoteModel& model ) const;
1616

17-
unsigned int ID() const noexcept;
18-
void ID( unsigned int ) noexcept;
19-
2017
std::string Title() const noexcept;
2118
void Title( std::string ) noexcept;
2219

@@ -29,7 +26,6 @@ namespace winrt::ReactNativeNotes::implementation
2926
void IsDone( bool ) noexcept;
3027

3128
private:
32-
unsigned int id;
3329
std::string title;
3430
std::string post;
3531
bool isDone;

windows/ReactNativeNotes/NativeModules/Repository/Repository.cpp

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,27 @@ namespace winrt::ReactNativeNotes::implementation
66
{
77
void Repository::Create( NoteModel& note ) noexcept
88
{
9-
note.ID( static_cast<unsigned int>(notes.size()) );
109
notes.push_back( note );
1110
}
1211

13-
NoteModel Repository::Read( const unsigned int ID ) const noexcept
12+
NoteModel Repository::Read( const int index ) const noexcept
1413
{
15-
for( auto it = notes.cbegin(); it != notes.cend(); ++it )
14+
if( index < notes.size() )
1615
{
17-
if( it->ID() == ID )
18-
return it.operator*();
16+
return notes.at( index );
1917
}
20-
return NoteModel();
21-
}
22-
23-
NoteModel Repository::Read( const int index ) const noexcept
24-
{
25-
if( index >= notes.size() )
26-
return NoteModel();
2718
else
28-
return notes.at(index);
29-
}
30-
31-
void Repository::Update( const NoteModel& note ) noexcept
32-
{
33-
if( note.ID() < notes.size() )
3419
{
35-
notes[note.ID()] = note;
20+
return NoteModel();
3621
}
3722
}
3823

39-
void Repository::Delete( const unsigned int ID ) noexcept
24+
void Repository::Update( const NoteModel& note, const unsigned int& index ) noexcept
4025
{
41-
auto it = std::find( notes.cbegin(), notes.cend(), Read(ID) );
42-
notes.erase( it );
26+
if( index < notes.size() )
27+
{
28+
notes[index] = note;
29+
}
4330
}
4431

4532
void Repository::Delete( const int index ) noexcept
@@ -52,10 +39,6 @@ namespace winrt::ReactNativeNotes::implementation
5239
return notes.size();
5340
}
5441

55-
const bool Repository::Exists( const unsigned int ID ) const noexcept
56-
{
57-
return std::find_if( notes.cbegin(), notes.cend(), [=]( const NoteModel& n )->bool { return n.ID() == ID; } ) != notes.cend();
58-
}
5942
const bool Repository::Exists( const int index ) const noexcept
6043
{
6144
return index < notes.size();

windows/ReactNativeNotes/NativeModules/Repository/Repository.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@ namespace winrt::ReactNativeNotes::implementation
1818

1919
void Create( NoteModel& note ) noexcept;
2020

21-
NoteModel Read( const unsigned int ID ) const noexcept;
2221
NoteModel Read( const int index ) const noexcept;
2322

24-
void Update( const NoteModel& note ) noexcept;
23+
void Update( const NoteModel& note, const unsigned int& index ) noexcept;
2524

26-
void Delete( const unsigned int ID ) noexcept;
2725
void Delete( const int index ) noexcept;
2826

2927
unsigned int Size() const noexcept;
3028

31-
const bool Exists( const unsigned int ID ) const noexcept;
3229
const bool Exists( const int index ) const noexcept;
3330

3431
private:

windows/ReactNativeNotes/NoteWidgetDetailsPage.xaml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,25 @@
88
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
99
mc:Ignorable="d"
1010
Background="Transparent">
11-
<react:ReactRootView x:Name="ReactRootView" ComponentName="NoteWidgetDetailsPanel" MinHeight="400">
12-
<react:ReactRootView.Background>
13-
<LinearGradientBrush>
14-
<GradientStop Offset="0.3" Color="#D0E7F3"/>
15-
<GradientStop Offset="1.4" Color="#A6B3D9"/>
16-
<GradientStop Offset="0.6" Color="#F8A878"/>
17-
<GradientStop Offset="0.9" Color="#D0E7F3"/>
18-
</LinearGradientBrush>
19-
</react:ReactRootView.Background>
20-
</react:ReactRootView>
11+
<Grid>
12+
<Grid.RowDefinitions>
13+
<RowDefinition Height="14*"/>
14+
<RowDefinition Height="*"/>
15+
</Grid.RowDefinitions>
16+
<react:ReactRootView x:Name="ReactRootView" ComponentName="NoteWidgetDetailsPanel" MinHeight="400" Grid.RowSpan="2">
17+
<react:ReactRootView.Background>
18+
<LinearGradientBrush>
19+
<GradientStop Offset="0.3" Color="#D0E7F3"/>
20+
<GradientStop Offset="1.4" Color="#A6B3D9"/>
21+
<GradientStop Offset="0.6" Color="#F8A878"/>
22+
<GradientStop Offset="0.9" Color="#D0E7F3"/>
23+
</LinearGradientBrush>
24+
</react:ReactRootView.Background>
25+
</react:ReactRootView>
26+
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right">
27+
<TextBlock Grid.Row="1" Text="Powered by " HorizontalAlignment="Right" VerticalAlignment="Center" Foreground="White" FontSize="18"/>
28+
<TextBlock Grid.Row="1" Margin="10,0,10,5" HorizontalAlignment="Right" VerticalAlignment="Center" Foreground="White" FontWeight="Bold" FontSize="25">{callstack}</TextBlock>
29+
</StackPanel>
30+
</Grid>
2131

2232
</Page>

0 commit comments

Comments
 (0)