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

Commit

Permalink
Tag selection and SideMenuManager
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Dec 29, 2018
1 parent 31082f3 commit 45aad1d
Show file tree
Hide file tree
Showing 13 changed files with 573 additions and 301 deletions.
12 changes: 8 additions & 4 deletions src/OptionsState.js
Expand Up @@ -20,7 +20,7 @@ export default class OptionsState {
}

init() {
this.selectedTags = [];
this.selectedTagIds = [];
this.sortBy = "created_at";
}

Expand All @@ -44,7 +44,7 @@ export default class OptionsState {
toJSON() {
return _.merge({
sortBy: this.sortBy,
selectedTags: this.selectedTags
selectedTagIds: this.selectedTagIds
}, this.getDisplayOptionValues());
}

Expand Down Expand Up @@ -81,11 +81,15 @@ export default class OptionsState {
this.notifyObservers(OptionsState.OptionsStateChangeEventSort);
}

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

getSelectedTagIds() {
return this.selectedTagIds;
}

getDisplayOptionValues() {
if(!this.displayOptions) {
this.rebuildOptions();
Expand Down
21 changes: 12 additions & 9 deletions src/app.js
Expand Up @@ -15,12 +15,12 @@ import ReviewManager from './lib/reviewManager';
import Compose from "./screens/Compose"
import Notes from "./screens/Notes"
import SideMenu from "@SideMenu/SideMenu"
import NoteSideMenu from "@SideMenu/NoteSideMenu"
import Settings from "./screens/Settings"
import NoteOptions from "./screens/NoteOptions"
import InputModal from "./screens/InputModal"

let leftDrawerLocked = false;
let rightDrawerLocked = true;
import SideMenuManager from "@SideMenu/SideMenuManager"

const AppStack = createStackNavigator({
Notes: {screen: Notes},
Expand All @@ -31,13 +31,15 @@ const AppStack = createStackNavigator({
})

AppStack.navigationOptions = ({ navigation }) => {
return {drawerLockMode: rightDrawerLocked ? "locked-closed" : null}
return {drawerLockMode: SideMenuManager.get().isRightSideMenuLocked() ? "locked-closed" : null}
};

const AppDrawerStack = createDrawerNavigator({
Main: AppStack
}, {
contentComponent: SideMenu,
contentComponent: ({ navigation }) => (
<NoteSideMenu ref={(ref) => {SideMenuManager.get().setRightSideMenuReference(ref)}} navigation={navigation} />
),
drawerPosition: "right",
drawerType: 'slide',
getCustomActionCreators: (route, stateKey) => {
Expand All @@ -46,7 +48,7 @@ const AppDrawerStack = createDrawerNavigator({
closeRightDrawer: () => DrawerActions.closeDrawer({ key: stateKey }),
lockRightDrawer: (lock) => {
// this is the key part
rightDrawerLocked = lock;
SideMenuManager.get().setLockedForRightSideMenu(lock);
// We have to return something
return NavigationActions.setParams({params: { dummy: true }, key: route.key})
}
Expand All @@ -72,14 +74,15 @@ const AppDrawer = createStackNavigator({
})

AppDrawer.navigationOptions = ({ navigation }) => {
return {drawerLockMode: leftDrawerLocked ? "locked-closed" : null}
return {drawerLockMode: SideMenuManager.get().isLeftSideMenuLocked() ? "locked-closed" : null}
};


const DrawerStack = createDrawerNavigator({
Main: AppDrawer,
}, {
contentComponent: SideMenu,
contentComponent: ({ navigation }) => (
<SideMenu ref={(ref) => {SideMenuManager.get().setLeftSideMenuReference(ref)}} navigation={navigation} />
),
drawerPosition: "left",
drawerType: 'slide',
getCustomActionCreators: (route, stateKey) => {
Expand All @@ -88,7 +91,7 @@ const DrawerStack = createDrawerNavigator({
closeLeftDrawer: () => DrawerActions.closeDrawer({ key: stateKey }),
lockLeftDrawer: (lock) => {
// this is the key part
leftDrawerLocked = lock;
SideMenuManager.get().setLockedForLeftSideMenu(lock)
// We have to return something
return NavigationActions.setParams({params: { dummy: true }, key: route.key})
}
Expand Down
8 changes: 4 additions & 4 deletions src/containers/NoteCell.js
Expand Up @@ -27,7 +27,7 @@ export default class NoteCell extends React.PureComponent {
backgroundColor: StyleKit.variable("stylekitInfoColor"),
},

noteTags: {
noteTagsContainer: {
flex: 1,
flexDirection: 'row',
marginBottom: 5,
Expand Down Expand Up @@ -59,6 +59,7 @@ export default class NoteCell extends React.PureComponent {

noteTagSelected: {
color: StyleKit.variable("stylekitInfoContrastColor"),
opacity: 0.8
},

noteTitle: {
Expand All @@ -73,7 +74,6 @@ export default class NoteCell extends React.PureComponent {

noteText: {
fontSize: 15,
// fontSize: StyleKit.constants().mainTextFontSize,
marginTop: 4,
color: StyleKit.variable("stylekitForegroundColor"),
opacity: 0.8,
Expand Down Expand Up @@ -196,9 +196,9 @@ export default class NoteCell extends React.PureComponent {
}

{this.props.renderTags && !this.state.options.hideTags && note.tags.length > 0 &&
<View style={this.styles.noteTags}>
<View style={this.styles.noteTagsContainer}>
<Text numberOfLines={1} style={this.aggregateStyles(this.styles.noteTag, this.styles.noteTagSelected, this.state.selected)}>
{this.props.tagsString}
{this.props.tagsString}
</Text>
</View>
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/sfjs/modelManager.js
Expand Up @@ -81,8 +81,9 @@ export default class ModelManager extends SFModelManager {
getNotes(options = {}) {
var notes;
var tags = [];
if(options.selectedTags && options.selectedTags.length > 0 && options.selectedTags[0].key !== "all") {
tags = ModelManager.get().findItems(options.selectedTags);
// if(options.selectedTagIds && options.selectedTagIds.length > 0 && options.selectedTagIds[0].key !== "all") {
if(options.selectedTagIds && options.selectedTagIds.length > 0) {
tags = ModelManager.get().findItems(options.selectedTagIds);
if(tags.length > 0) {
var taggedNotes = new Set();
for(var tag of tags) {
Expand Down
61 changes: 33 additions & 28 deletions src/screens/Compose.js
Expand Up @@ -2,6 +2,9 @@ import React, { Component } from 'react';
import Sync from '../lib/sfjs/syncManager'
import ModelManager from '../lib/sfjs/modelManager'
import Auth from '../lib/sfjs/authManager'
import OptionsState from "@Root/OptionsState"

import SideMenuManager from "@SideMenu/SideMenuManager"

import Abstract from "./Abstract"
import Webview from "./Webview"
Expand Down Expand Up @@ -55,6 +58,7 @@ export default class Compose extends Abstract {
}

this.note = note;

this.constructState({title: note.title, text: note.text});

this.configureHeaderBar();
Expand Down Expand Up @@ -143,40 +147,39 @@ export default class Compose extends Abstract {
this.input.focus();
}
}

SideMenuManager.get().setHandlerForRightSideMenu({
onEditorSelect: (editor) => {
this.needsEditorReload = true;
},
onTagSelect: (tag) => {
let selectedTags = this.note.tags;
var selected = selectedTags.includes(tag);
if(selected) {
// deselect
selectedTags.splice(selectedTags.indexOf(tag), 1);
} else {
// select
selectedTags.push(tag);
}
this.replaceTagsForNote(selectedTags);
this.changesMade();
},
getSelectedTags: () => {
// Return copy so that list re-renders every time if they change
return this.note.tags.slice();
}
})
}

componentDidBlur() {
super.componentDidBlur();

SideMenuManager.get().removeHandlerForRightSideMenu();
this.props.navigation.lockLeftDrawer(false);
this.props.navigation.lockRightDrawer(true);
}

presentOptions() {
if(ApplicationState.isAndroid && this.input) {
this.input.blur();
}

this.previousOptions = {selectedTags: this.note.tags.map((tag) => {return tag.uuid})};

this.props.navigation.navigate("NoteOptions", {
noteId: this.note.uuid,
onManageNoteEvent: () => {this.forceUpdate()},
singleSelectMode: false,
options: JSON.stringify(this.previousOptions),
onEditorSelect: () => {
this.needsEditorReload = true;
},
onOptionsChange: (options) => {
if(!_.isEqual(options.selectedTags, this.previousOptions.selectedTags)) {
var tags = ModelManager.get().findItems(options.selectedTags);
this.replaceTagsForNote(tags);
this.note.setDirty(true);
this.changesMade();
}
}
});
}

replaceTagsForNote(newTags) {
let note = this.note;

Expand All @@ -191,8 +194,10 @@ export default class Compose extends Abstract {
}

for(var newTag of newTags) {
newTag.addItemAsRelationship(note);
newTag.setDirty(true);
if(!oldTags.includes(newTag)) {
newTag.addItemAsRelationship(note);
newTag.setDirty(true);
}
}
}

Expand Down
28 changes: 23 additions & 5 deletions src/screens/Notes.js
Expand Up @@ -10,6 +10,8 @@ import Auth from '../lib/sfjs/authManager'
import KeysManager from '../lib/keysManager'
import Keychain from "../lib/keychain"

import SideMenuManager from "@SideMenu/SideMenuManager"

import Abstract from "./Abstract"
import StyleKit from "../style/StyleKit"
import Icons from '@Style/Icons';
Expand Down Expand Up @@ -109,7 +111,7 @@ export default class Notes extends Abstract {

registerObservers() {
this.optionsObserver = this.options.addChangeObserver((options, eventType) => {
this.props.navigation.closeLeftDrawer();
// this.props.navigation.closeLeftDrawer();
// should only show for non-search term change
if(eventType !== OptionsState.OptionsStateChangeEventSearch) {
this.setTitle(null, "Loading...");
Expand Down Expand Up @@ -254,10 +256,10 @@ export default class Notes extends Abstract {

var options = this.options;
var notesTitle = "Notes";
var numTags = options.selectedTags.length;
var numTags = options.selectedTagIds.length;

if(numTags > 0) {
var tags = ModelManager.get().findItems(options.selectedTags);
var tags = ModelManager.get().findItems(options.selectedTagIds);
if(tags.length > 0) {
var tag = tags[0];
notesTitle = tag.title + " notes";
Expand All @@ -282,9 +284,25 @@ export default class Notes extends Abstract {
}
}

setSideMenuHandler() {
SideMenuManager.get().setHandlerForLeftSideMenu({
onTagSelect: (tag) => {
// Single tag at a time only
this.options.setSelectedTagIds([tag.uuid]);
// this.props.navigation.closeLeftDrawer();
},
getSelectedTags: () => {
let ids = this.options.getSelectedTagIds();
return ModelManager.get().findItems(ids);
}
})
}

componentDidFocus() {
super.componentDidFocus();

this.setSideMenuHandler();

this.forceUpdate();

if(this.needsConfigureNavBar) {
Expand All @@ -300,7 +318,7 @@ export default class Notes extends Abstract {
presentComposer(item) {
this.props.navigation.navigate("Compose", {
noteId: item && item.uuid,
selectedTagId: this.selectedTags.length && this.selectedTags[0].uuid,
selectedTagId: this.options.selectedTagIds.length && this.options.selectedTagIds[0],
});
}

Expand Down Expand Up @@ -394,7 +412,7 @@ export default class Notes extends Abstract {

var result = ModelManager.get().getNotes(this.options);
var notes = result.notes;
var tags = this.selectedTags = result.tags;
var tags = result.tags;

var syncStatus = Sync.get().syncStatus;

Expand Down

0 comments on commit 45aad1d

Please sign in to comment.