Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
Option to hide previews, tags, dates
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Oct 19, 2018
1 parent c07a8e8 commit 6f1620f
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 46 deletions.
9 changes: 0 additions & 9 deletions ios/StandardNotes/AppDelegate.h
@@ -1,12 +1,3 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>
Expand Down
9 changes: 0 additions & 9 deletions ios/StandardNotes/AppDelegate.m
@@ -1,12 +1,3 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
Expand Down
56 changes: 50 additions & 6 deletions src/OptionsState.js
Expand Up @@ -32,6 +32,7 @@ export default class OptionsState {
async loadSaved() {
return Storage.get().getItem("options").then(function(result){
_.merge(this, _.omit(JSON.parse(result), ["changeObservers"]));
this.rebuildOptions();
this.notifyObservers();
}.bind(this))
}
Expand All @@ -41,7 +42,10 @@ export default class OptionsState {
}

toJSON() {
return {sortBy: this.sortBy, archivedOnly: this.archivedOnly, selectedTags: this.selectedTags};
return _.merge({
sortBy: this.sortBy,
selectedTags: this.selectedTags
}, this.getDisplayOptionValues());
}

addChangeObserver(callback) {
Expand Down Expand Up @@ -77,13 +81,53 @@ export default class OptionsState {
this.notifyObservers(OptionsState.OptionsStateChangeEventSort);
}

setArchivedOnly(archived) {
this.archivedOnly = archived;
this.notifyObservers(OptionsState.OptionsStateChangeEventViews);
}

setSelectedTags(selectedTags) {
this.selectedTags = selectedTags;
this.notifyObservers(OptionsState.OptionsStateChangeEventTags);
}

getDisplayOptionValues() {
if(!this.displayOptions) {
this.rebuildOptions();
}
return this.displayOptions;
}

rebuildOptions() {
console.log("Rebuilding display options");
this.displayOptions = {
archivedOnly: this.getDisplayOptionValue("archivedOnly"),
hidePreviews: this.getDisplayOptionValue("hidePreviews"),
hideTags: this.getDisplayOptionValue("hideTags"),
hideDates: this.getDisplayOptionValue("hideDates")
}
}

getDisplayOptionValue(key) {
if(key == "archivedOnly") {
return this.archivedOnly;
} else if(key == "hidePreviews") {
return this.hidePreviews;
} else if(key == "hideDates") {
return this.hideDates;
} else if(key == "hideTags") {
return this.hideTags;
}
}

setDisplayOptionKeyValue(key, value) {
if(key == "archivedOnly") {
this.archivedOnly = value;
} else if(key == "hidePreviews") {
this.hidePreviews = value;
} else if(key == "hideDates") {
this.hideDates = value;
} else if(key == "hideTags") {
this.hideTags = value;
}

this.rebuildOptions();

this.notifyObservers(OptionsState.OptionsStateChangeEventViews);
}
}
24 changes: 15 additions & 9 deletions src/containers/NoteCell.js
Expand Up @@ -10,7 +10,7 @@ export default class NoteCell extends React.PureComponent {

constructor(props) {
super(props);
this.state = {selected: false};
this.state = {selected: false, options: props.options || {}};
let Padding = 14;

this.styles = StyleSheet.create({
Expand Down Expand Up @@ -79,6 +79,10 @@ export default class NoteCell extends React.PureComponent {
});
}

componentWillReceiveProps(props) {
this.setState({options: props.options || {}});
}

_onPress = () => {
this.setState({selected: true});
this.props.onPressItem(this.props.item);
Expand Down Expand Up @@ -176,7 +180,7 @@ export default class NoteCell extends React.PureComponent {
</View>
}

{this.props.renderTags && note.tags.length > 0 &&
{this.props.renderTags && !this.state.options.hideTags && note.tags.length > 0 &&
<View style={this.styles.noteTags}>
<Text numberOfLines={1} style={this.aggregateStyles(this.styles.noteTag)}>
{this.props.tagsString}
Expand All @@ -199,19 +203,21 @@ export default class NoteCell extends React.PureComponent {
<Text style={this.aggregateStyles(this.styles.noteTitle, this.styles.noteTitleSelected, this.state.selected)}>{note.title}</Text>
}

{note.content.preview_plain &&
{note.content.preview_plain && !this.state.options.hidePreviews &&
<Text style={this.aggregateStyles(this.styles.noteText, this.styles.noteTextSelected, this.state.selected)}>{note.content.preview_plain}</Text>
}

{!note.content.preview_plain && note.safeText().length > 0 &&
{!note.content.preview_plain && !this.state.options.hidePreviews && note.safeText().length > 0 &&
<Text numberOfLines={2} style={this.aggregateStyles(this.styles.noteText, this.styles.noteTextSelected, this.state.selected)}>{note.text}</Text>
}

<Text
numberOfLines={1}
style={this.aggregateStyles(this.styles.noteDate, this.styles.noteDateSelected, this.state.selected)}>
{this.props.sortType == "client_updated_at" ? "Modified " + note.updatedAtString() : note.createdAtString()}
</Text>
{!this.state.options.hideDates &&
<Text
numberOfLines={1}
style={this.aggregateStyles(this.styles.noteDate, this.styles.noteDateSelected, this.state.selected)}>
{this.props.sortType == "client_updated_at" ? "Modified " + note.updatedAtString() : note.createdAtString()}
</Text>
}

<ActionSheet
ref={o => this.actionSheet = o}
Expand Down
3 changes: 3 additions & 0 deletions src/containers/NoteList.js
Expand Up @@ -69,6 +69,7 @@ export default class NoteList extends Component {
archived={item.archived}
sortType={this.props.sortType}
renderTags={renderTags}
options={this.props.options}
/>
)
}
Expand All @@ -82,6 +83,7 @@ export default class NoteList extends Component {
} else if(this.props.notes.length == 0) {
placeholderText = "No notes.";
}

return (
<View style={{backgroundColor: GlobalStyles.constants().mainBackgroundColor}}>

Expand All @@ -104,6 +106,7 @@ export default class NoteList extends Component {
/>
}
data={this.props.notes}
options={this.props.options}
renderItem={this._renderItem}
ListHeaderComponent={this.renderHeader}
/>
Expand Down
42 changes: 31 additions & 11 deletions src/screens/Filter.js
Expand Up @@ -41,7 +41,7 @@ export default class Filter extends Abstract {
selectedTags = [];
}

this.mergeState({tags: [], selectedTags: selectedTags, archivedOnly: this.options.archivedOnly});
this.mergeState({tags: [], selectedTags: selectedTags, options: this.options});

if(this.props.noteId) {
this.note = ModelManager.get().findItem(this.props.noteId);
Expand Down Expand Up @@ -161,7 +161,7 @@ export default class Filter extends Abstract {

if(event.id == "willDisappear" && !this.props.singleSelectMode) {
// we prefer to notify the parent via NavBarButtonPress.accept, but when this view is presented via nav push,
// the user can swipe back and miss that. So we do it here as a backup
// the user can swipe back and miss that. So we do it here as a backup.
if(!this.didNotifyParent) {
this.notifyParentOfOptionsChange();
}
Expand Down Expand Up @@ -282,9 +282,11 @@ export default class Filter extends Abstract {
})
}

onArchiveSelect = () => {
this.options.setArchivedOnly(!this.options.archivedOnly);
this.mergeState({archivedOnly: this.options.archivedOnly});
onOptionSelect = (option) => {
console.log("option select", option);
this.options.setDisplayOptionKeyValue(option, !this.options.getDisplayOptionValue(option));
this.forceUpdate();
// this.mergeState({archivedOnly: this.options.archivedOnly});

if(this.props.singleSelectMode) {
this.notifyParentOfOptionsChange();
Expand Down Expand Up @@ -349,7 +351,7 @@ export default class Filter extends Abstract {
}

{!this.note &&
<OptionsSection archivedOnly={this.state.archivedOnly} onArchiveSelect={this.onArchiveSelect} title={"Options"} />
<OptionsSection options={this.options.getDisplayOptionValues()} onOptionSelect={this.onOptionSelect} title={"Options"} />
}

{ this.note &&
Expand Down Expand Up @@ -472,11 +474,11 @@ class TagsSection extends Component {
class OptionsSection extends Component {
constructor(props) {
super(props);
this.state = {archivedOnly: props.archivedOnly}
// this.state = {archivedOnly: props.archivedOnly}
}

onPressArchive = () => {
this.props.onArchiveSelect();
onOptionSelect = (option) => {
this.props.onOptionSelect(option);
}

render() {
Expand All @@ -485,11 +487,29 @@ class OptionsSection extends Component {
<SectionHeader title={this.props.title} />

<SectionedAccessoryTableCell
onPress={this.onPressArchive}
onPress={() => {this.onOptionSelect('archivedOnly')}}
text={"Show only archived notes"}
first={true}
selected={() => {return this.props.options.archivedOnly}}
/>

<SectionedAccessoryTableCell
onPress={() => {this.onOptionSelect('hidePreviews')}}
text={"Hide note previews"}
selected={() => {return this.props.options.hidePreviews}}
/>

<SectionedAccessoryTableCell
onPress={() => {this.onOptionSelect('hideTags')}}
text={"Hide note tags"}
selected={() => {return this.props.options.hideTags}}
/>

<SectionedAccessoryTableCell
onPress={() => {this.onOptionSelect('hideDates')}}
text={"Hide note dates"}
last={true}
selected={() => {return this.props.archivedOnly}}
selected={() => {return this.props.options.hideDates}}
/>

</TableSection>
Expand Down
1 change: 1 addition & 0 deletions src/screens/Notes.js
Expand Up @@ -508,6 +508,7 @@ export default class Notes extends Abstract {
decrypting={this.state.decrypting}
loading={this.state.loading}
selectedTags={tags}
options={this.options.displayOptions}
/>
}

Expand Down
10 changes: 8 additions & 2 deletions src/screens/Webview.js
Expand Up @@ -146,9 +146,15 @@ export default class Webview extends Abstract {
}

onMessage = (message) => {
// Ignore any incoming events (like save events) if the note is locked. Allow messages that are required for component setup (administrative)
let data = JSON.parse(message.nativeEvent.data);
var data;
try {
data = JSON.parse(message.nativeEvent.data);
} catch (e) {
console.log("Message is not valid JSON, returning");
return;
}

// Ignore any incoming events (like save events) if the note is locked. Allow messages that are required for component setup (administrative)
if(this.note.locked && !ComponentManager.get().isReadOnlyMessage(data)) {
if(!this.didShowLockAlert) {
Alert.alert('Note Locked', "This note is locked. Changes you make in the web editor will not be saved. Please unlock this note to make changes.", [{text: 'OK'}])
Expand Down

0 comments on commit 6f1620f

Please sign in to comment.