Last active
January 19, 2018 15:36
-
-
Save amlwwalker/42615108cf2c3bfa870fef4f4142f36a to your computer and use it in GitHub Desktop.
Changing the icon of a list button in InboxSDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InboxSDK.load('1.0', 'app-id').then(function(sdk){ | |
var threadDataManager = new ThreadDataManager(); | |
sdk.Lists.registerThreadRowViewHandler(threadRowView => { | |
var threadID = threadRowView.getThreadID(); | |
threadDataManager.setThreadData(threadID, chrome.runtime.getURL('images/logo1.png')); | |
threadRowView.addButton( | |
threadDataManager.getThreadStream(threadID) | |
.toProperty(() => threadDataManager.getThreadData(threadID)) | |
.map(threadData => { | |
console.log("thread data: ", threadData) | |
if(!threadData){ | |
return null; | |
} | |
else{ | |
return { | |
iconUrl: threadDataManager.getThreadData(threadID), | |
iconClass: '', | |
onClick: (event) => { | |
console.log("thread data changing"); | |
threadDataManager.setThreadData(threadID, chrome.runtime.getURL('images/logo2.jpg')) | |
console.log("clicked: ", threadDataManager.getThreadData(threadID)) | |
}, | |
hasDropdown: false | |
}; | |
} | |
}) | |
); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ThreadDataManager { | |
constructor(){ | |
var self = this; | |
this._emitter; | |
this._stream = Kefir.stream(emitter => { | |
self._emitter = emitter; | |
return () => null | |
}); | |
this._stream.onAny(event => { | |
console.log('Stream event:', event); | |
}); | |
this._threadData = {}; //map from threadID to thread data | |
} | |
setThreadData(threadID, data){ | |
console.log("setting data for ", threadID, " to: ", data) | |
this._threadData[threadID] = data; | |
this._emitter.emit({threadID, data}); | |
} | |
getThreadData(threadID){ | |
return this._threadData[threadID]; | |
} | |
getThreadStream(threadID){ | |
console.log(this._emitter) | |
return this._stream.filter(event => event.threadID === threadID); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment