List cleanup on remove (#1069)
* 💄 Hide Add to List option on own profile * ✨ Remove Lists tab when last list is removed * ✨ Add listener to list delete on profile screen * ✨ Only show save changes in list modal when changes are made
This commit is contained in:
parent
38d78e16bf
commit
eec300d772
6 changed files with 60 additions and 12 deletions
|
@ -217,6 +217,8 @@ export class ListModel {
|
|||
records.map(record => createDel(record.uri)),
|
||||
),
|
||||
})
|
||||
|
||||
this.rootStore.emitListDeleted(this.uri)
|
||||
}
|
||||
|
||||
async subscribe() {
|
||||
|
|
|
@ -48,9 +48,24 @@ export class ListsListModel {
|
|||
return this.hasLoaded && !this.hasContent
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes posts from the feed upon deletion.
|
||||
*/
|
||||
onListDeleted(uri: string) {
|
||||
this.lists = this.lists.filter(l => l.uri !== uri)
|
||||
}
|
||||
|
||||
// public api
|
||||
// =
|
||||
|
||||
/**
|
||||
* Register any event listeners. Returns a cleanup function.
|
||||
*/
|
||||
registerListeners() {
|
||||
const sub = this.rootStore.onListDeleted(this.onListDeleted.bind(this))
|
||||
return () => sub.remove()
|
||||
}
|
||||
|
||||
async refresh() {
|
||||
return this.loadMore(true)
|
||||
}
|
||||
|
|
|
@ -188,6 +188,14 @@ export class RootStoreModel {
|
|||
DeviceEventEmitter.emit('post-deleted', uri)
|
||||
}
|
||||
|
||||
// a list was deleted by the local user
|
||||
onListDeleted(handler: (uri: string) => void): EmitterSubscription {
|
||||
return DeviceEventEmitter.addListener('list-deleted', handler)
|
||||
}
|
||||
emitListDeleted(uri: string) {
|
||||
DeviceEventEmitter.emit('list-deleted', uri)
|
||||
}
|
||||
|
||||
// the session has started and been fully hydrated
|
||||
onSessionLoaded(handler: () => void): EmitterSubscription {
|
||||
return DeviceEventEmitter.addListener('session-loaded', handler)
|
||||
|
|
|
@ -87,7 +87,10 @@ export class ProfileUiModel {
|
|||
}
|
||||
|
||||
get selectedView() {
|
||||
return this.selectorItems[this.selectedViewIndex]
|
||||
// If, for whatever reason, the selected view index is not available, default back to posts
|
||||
// This can happen when the user was focused on a view but performed an action that caused
|
||||
// the view to disappear (e.g. deleting the last list in their list of lists https://imgflip.com/i/7txu1y)
|
||||
return this.selectorItems[this.selectedViewIndex] || Sections.Posts
|
||||
}
|
||||
|
||||
get uiItems() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue