Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Jul 6, 2017
1 parent 765c713 commit 3f0712f
Show file tree
Hide file tree
Showing 24 changed files with 575 additions and 436 deletions.
6 changes: 5 additions & 1 deletion app/browser/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const frameStateUtil = require('../../js/state/frameStateUtil')
const menuUtil = require('../common/lib/menuUtil')
const {getSetting} = require('../../js/settings')
const locale = require('../locale')
// TODO REMOVE
const appStore = require('../../js/stores/appStore')
const {isLocationBookmarked} = require('../../js/state/siteUtil')
const {isDarwin, isLinux} = require('../common/lib/platformUtil')

Expand Down Expand Up @@ -266,7 +268,7 @@ const createViewSubmenu = (state) => {
accelerator: isDarwin ? 'Cmd+Alt+I' : 'Ctrl+Shift+I',
click: function () {
const win = BrowserWindow.getActiveWindow()
const activeTab = tabState.getActiveTab(state, win.id)
const activeTab = tabState.getActiveTab(appStore.getState(), win.id)
appActions.toggleDevTools(activeTab.get('tabId'))
}
},
Expand Down Expand Up @@ -676,6 +678,8 @@ const doAction = (state, action) => {
}
break
case appConstants.APP_ADD_SITE:
case appConstants.APP_ADD_BOOKMARK:
case appConstants.APP_EDIT_BOOKMARK:
{
if (action.tag === siteTags.BOOKMARK || action.tag === siteTags.BOOKMARK_FOLDER) {
createMenu(state)
Expand Down
53 changes: 37 additions & 16 deletions app/browser/reducers/sitesReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,56 @@ const sitesReducer = (state, action, immutableAction) => {
break
}
case appConstants.APP_ADD_SITE:
const isSyncEnabled = syncEnabled()
if (Immutable.List.isList(action.siteDetail)) {
action.siteDetail.forEach((s) => {
state = siteUtil.addSite(state, s, action.tag, undefined, action.skipSync)
{
const isSyncEnabled = syncEnabled()
if (Immutable.List.isList(action.siteDetail)) {
action.siteDetail.forEach((s) => {
state = siteUtil.addSite(state, s, action.tag, action.skipSync)
if (isSyncEnabled) {
state = syncUtil.updateSiteCache(state, s)
}
})
} else {
let sites = state.get('sites')
if (!action.siteDetail.get('folderId') && siteUtil.isFolder(action.siteDetail)) {
action.siteDetail = action.siteDetail.set('folderId', siteUtil.getNextFolderId(sites))
}
state = siteUtil.addSite(state, action.siteDetail, action.tag, action.skipSync)
if (isSyncEnabled) {
state = syncUtil.updateSiteCache(state, s)
state = syncUtil.updateSiteCache(state, action.siteDetail)
}
})
} else {
}
state = updateActiveTabBookmarked(state)
break
}
case appConstants.APP_ADD_BOOKMARK:
case appConstants.APP_EDIT_BOOKMARK:
{
const isSyncEnabled = syncEnabled()
let destination = null // TODO add it
let sites = state.get('sites')
if (!action.siteDetail.get('folderId') && siteUtil.isFolder(action.siteDetail)) {
if (!action.siteDetail.get('folderId') && action.tag === siteTags.BOOKMARK_FOLDER) {
action.siteDetail = action.siteDetail.set('folderId', siteUtil.getNextFolderId(sites))
}
state = siteUtil.addSite(state, action.siteDetail, action.tag, action.originalSiteDetail, action.skipSync)
if (action.destinationDetail) {
state = siteUtil.addSite(state, action.siteDetail, action.tag, action.editKey)

// TODO do we need it?
if (destination) {
const sourceKey = siteUtil.getSiteKey(action.siteDetail)
const destinationKey = siteUtil.getSiteKey(action.destinationDetail)
const destinationKey = siteUtil.getSiteKey(destination)

if (sourceKey != null) {
state = siteUtil.moveSite(state,
sourceKey, destinationKey, false, false, true)
state = siteUtil.moveSite(state, sourceKey, destinationKey, false, false, true)
}
}

if (isSyncEnabled) {
state = syncUtil.updateSiteCache(state, action.destinationDetail || action.siteDetail)
state = syncUtil.updateSiteCache(state, destination || action.siteDetail)
}

state = updateActiveTabBookmarked(state)
break
}
state = updateActiveTabBookmarked(state)
break
case appConstants.APP_REMOVE_SITE:
const removeSiteSyncCallback = action.skipSync ? undefined : syncActions.removeSite
state = siteUtil.removeSite(state, action.siteDetail, action.tag, true, removeSiteSyncCallback)
Expand Down
2 changes: 2 additions & 0 deletions app/browser/reducers/urlBarSuggestionsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const tabState = require('../../common/state/tabState')
const urlBarSuggestionsReducer = (state, action) => {
switch (action.actionType) {
case appConstants.APP_ADD_SITE:
case appConstants.APP_ADD_BOOKMARK:
case appConstants.APP_EDIT_BOOKMARK:
if (Immutable.List.isList(action.siteDetail)) {
action.siteDetail.forEach((s) => {
add(s)
Expand Down
24 changes: 13 additions & 11 deletions app/common/lib/bookmarkUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ const {calculateTextWidth} = require('../../../js/lib/textCalculator')
const {iconSize} = require('../../../js/constants/config')
const {getSetting} = require('../../../js/settings')

const bookmarkHangerHeading = (detail, isFolder, shouldShowLocation) => {
function bookmarkHangerHeading (editMode, isFolder, isAdded) {
if (isFolder) {
return shouldShowLocation
return editMode
? 'bookmarkFolderEditing'
: 'bookmarkFolderAdding'
}
return shouldShowLocation
? (!detail || !detail.has('location'))
? 'bookmarkCreateNew'
: 'bookmarkEdit'
: 'bookmarkAdded'

if (isAdded) {
return 'bookmarkAdded'
}

return editMode
? 'bookmarkEdit'
: 'bookmarkCreateNew'
}

const displayBookmarkName = (detail) => {
Expand All @@ -37,11 +40,10 @@ const displayBookmarkName = (detail) => {
return detail.get('title') || ''
}

const isBookmarkNameValid = (detail, isFolder) => {
const title = detail.get('title') || detail.get('customTitle')
const location = detail.get('location')
const isBookmarkNameValid = (title, location, isFolder, customTitle) => {
const newTitle = title || customTitle
return isFolder
? (title != null && title.trim().length > 0)
? (newTitle != null && newTitle.trim().length > 0)
: (location != null && location.trim().length > 0)
}

Expand Down
Loading

0 comments on commit 3f0712f

Please sign in to comment.