Merge branch 'navigation-update' into shigusegubu-vue3

* navigation-update:
  add and remove users to/from lists from their profile
  edit mode
  fix anon user issues
This commit is contained in:
Henry Jameson 2022-08-15 23:20:03 +03:00
commit 6ad00a239b
14 changed files with 158 additions and 64 deletions

View file

@ -80,7 +80,7 @@ export default (store) => {
{ name: 'lists', path: '/lists', component: Lists }, { name: 'lists', path: '/lists', component: Lists },
{ name: 'lists-timeline', path: '/lists/:id', component: ListsTimeline }, { name: 'lists-timeline', path: '/lists/:id', component: ListsTimeline },
{ name: 'lists-edit', path: '/lists/:id/edit', component: ListsEdit }, { name: 'lists-edit', path: '/lists/:id/edit', component: ListsEdit },
{ name: 'edit-navigation', path: '/nav-edit', component: NavPanel, props: () => ({ forceExpand: true }), beforeEnter: validateAuthenticatedRoute } { name: 'edit-navigation', path: '/nav-edit', component: NavPanel, props: () => ({ forceExpand: true, forceEditMode: true }), beforeEnter: validateAuthenticatedRoute }
] ]
if (store.state.instance.pleromaChatMessagesAvailable) { if (store.state.instance.pleromaChatMessagesAvailable) {

View file

@ -1,6 +1,7 @@
import { mapState } from 'vuex' import { mapState } from 'vuex'
import ProgressButton from '../progress_button/progress_button.vue' import ProgressButton from '../progress_button/progress_button.vue'
import Popover from '../popover/popover.vue' import Popover from '../popover/popover.vue'
import UserListMenu from 'src/components/user_list_menu/user_list_menu.vue'
import { library } from '@fortawesome/fontawesome-svg-core' import { library } from '@fortawesome/fontawesome-svg-core'
import { import {
faEllipsisV faEllipsisV
@ -19,7 +20,8 @@ const AccountActions = {
}, },
components: { components: {
ProgressButton, ProgressButton,
Popover Popover,
UserListMenu
}, },
methods: { methods: {
showRepeats () { showRepeats () {

View file

@ -28,6 +28,7 @@
class="dropdown-divider" class="dropdown-divider"
/> />
</template> </template>
<UserListMenu :user="user" />
<button <button
v-if="relationship.blocking" v-if="relationship.blocking"
class="btn button-default btn-block dropdown-item" class="btn button-default btn-block dropdown-item"

View file

@ -27,9 +27,9 @@ const ListsNew = {
} }
}, },
created () { created () {
this.$store.dispatch('fetchList', { id: this.id }) this.$store.dispatch('fetchList', { listId: this.id })
.then(() => { this.title = this.findListTitle(this.id) }) .then(() => { this.title = this.findListTitle(this.id) })
this.$store.dispatch('fetchListAccounts', { id: this.id }) this.$store.dispatch('fetchListAccounts', { listId: this.id })
.then(() => { .then(() => {
this.selectedUserIds = this.findListAccounts(this.id) this.selectedUserIds = this.findListAccounts(this.id)
this.selectedUserIds.forEach(userId => { this.selectedUserIds.forEach(userId => {
@ -76,13 +76,13 @@ const ListsNew = {
this.userIds = results this.userIds = results
}, },
updateList () { updateList () {
this.$store.dispatch('setList', { id: this.id, title: this.title }) this.$store.dispatch('setList', { listId: this.id, title: this.title })
this.$store.dispatch('setListAccounts', { id: this.id, accountIds: this.selectedUserIds }) this.$store.dispatch('setListAccounts', { listId: this.id, accountIds: this.selectedUserIds })
this.$router.push({ name: 'lists-timeline', params: { id: this.id } }) this.$router.push({ name: 'lists-timeline', params: { id: this.id } })
}, },
deleteList () { deleteList () {
this.$store.dispatch('deleteList', { id: this.id }) this.$store.dispatch('deleteList', { listId: this.id })
this.$router.push({ name: 'lists' }) this.$router.push({ name: 'lists' })
} }
} }

View file

@ -69,8 +69,8 @@ const ListsNew = {
// and "updating the accounts on the list". // and "updating the accounts on the list".
this.$store.dispatch('createList', { title: this.title }) this.$store.dispatch('createList', { title: this.title })
.then((list) => { .then((list) => {
this.$store.dispatch('setListAccounts', { id: list.id, accountIds: this.selectedUserIds }) this.$store.dispatch('setListAccounts', { listId: list.id, accountIds: this.selectedUserIds })
this.$router.push({ name: 'lists-timeline', params: { id: list.id } }) this.$router.push({ name: 'lists-timeline', params: { listId: list.id } })
}) })
} }
} }

View file

@ -4,6 +4,7 @@ import { TIMELINES, ROOT_ITEMS } from 'src/components/navigation/navigation.js'
import { getListEntries, filterNavigation } from 'src/components/navigation/filter.js' import { getListEntries, filterNavigation } from 'src/components/navigation/filter.js'
import NavigationEntry from 'src/components/navigation/navigation_entry.vue' import NavigationEntry from 'src/components/navigation/navigation_entry.vue'
import NavigationPins from 'src/components/navigation/navigation_pins.vue' import NavigationPins from 'src/components/navigation/navigation_pins.vue'
import Checkbox from 'src/components/checkbox/checkbox.vue'
import { library } from '@fortawesome/fontawesome-svg-core' import { library } from '@fortawesome/fontawesome-svg-core'
import { import {
@ -34,16 +35,18 @@ library.add(
faList faList
) )
const NavPanel = { const NavPanel = {
props: ['forceExpand'], props: ['forceExpand', 'forceEditMode'],
created () { created () {
}, },
components: { components: {
ListsMenuContent, ListsMenuContent,
NavigationEntry, NavigationEntry,
NavigationPins NavigationPins,
Checkbox
}, },
data () { data () {
return { return {
editMode: false,
showTimelines: false, showTimelines: false,
showLists: false, showLists: false,
timelinesList: Object.entries(TIMELINES).map(([k, v]) => ({ ...v, name: k })), timelinesList: Object.entries(TIMELINES).map(([k, v]) => ({ ...v, name: k })),
@ -57,6 +60,9 @@ const NavPanel = {
toggleLists () { toggleLists () {
this.showLists = !this.showLists this.showLists = !this.showLists
}, },
toggleEditMode () {
this.editMode = !this.editMode
},
toggleCollapse () { toggleCollapse () {
this.$store.commit('setPreference', { path: 'simple.collapseNav', value: !this.collapsed }) this.$store.commit('setPreference', { path: 'simple.collapseNav', value: !this.collapsed })
this.$store.dispatch('pushServerSideStorage') this.$store.dispatch('pushServerSideStorage')

View file

@ -46,7 +46,7 @@
<NavigationEntry <NavigationEntry
v-for="item in timelinesItems" v-for="item in timelinesItems"
:key="item.name" :key="item.name"
:show-pin="true" :show-pin="editMode"
:item="item" :item="item"
/> />
</ul> </ul>
@ -83,7 +83,7 @@
class="timelines-background" class="timelines-background"
> >
<ListsMenuContent <ListsMenuContent
:show-pin="true" :show-pin="editMode"
class="timelines" class="timelines"
/> />
</div> </div>
@ -91,9 +91,17 @@
<NavigationEntry <NavigationEntry
v-for="item in rootItems" v-for="item in rootItems"
:key="item.name" :key="item.name"
:show-pin="true" :show-pin="editMode || forceEditMode"
:item="item" :item="item"
/> />
<div
v-if="!forceEditMode"
class="panel-footer"
>
<Checkbox v-model="editMode">
{{ $t('nav.edit_pinned') }}
</Checkbox>
</div>
</ul> </ul>
</div> </div>
</div> </div>

View file

@ -4,7 +4,7 @@ const Popover = {
// Action to trigger popover: either 'hover' or 'click' // Action to trigger popover: either 'hover' or 'click'
trigger: String, trigger: String,
// Either 'top' or 'bottom' // 'top', 'bottom', 'left', 'right'
placement: String, placement: String,
// Takes object with properties 'x' and 'y', values of these can be // Takes object with properties 'x' and 'y', values of these can be
@ -84,6 +84,8 @@ const Popover = {
const anchorStyle = getComputedStyle(anchorEl) const anchorStyle = getComputedStyle(anchorEl)
const topPadding = parseFloat(anchorStyle.paddingTop) const topPadding = parseFloat(anchorStyle.paddingTop)
const bottomPadding = parseFloat(anchorStyle.paddingBottom) const bottomPadding = parseFloat(anchorStyle.paddingBottom)
const rightPadding = parseFloat(anchorStyle.paddingRight)
const leftPadding = parseFloat(anchorStyle.paddingLeft)
// Screen position of the origin point for popover = center of the anchor // Screen position of the origin point for popover = center of the anchor
const origin = { const origin = {
@ -170,7 +172,7 @@ const Popover = {
if (overlayCenter) { if (overlayCenter) {
translateX = origin.x + horizOffset translateX = origin.x + horizOffset
translateY = origin.y + vertOffset translateY = origin.y + vertOffset
} else { } else if (this.placement !== 'right' && this.placement !== 'left') {
// Default to whatever user wished with placement prop // Default to whatever user wished with placement prop
let usingTop = this.placement !== 'bottom' let usingTop = this.placement !== 'bottom'
@ -189,6 +191,25 @@ const Popover = {
const xOffset = (this.offset && this.offset.x) || 0 const xOffset = (this.offset && this.offset.x) || 0
translateX = origin.x + horizOffset + xOffset translateX = origin.x + horizOffset + xOffset
} else {
// Default to whatever user wished with placement prop
let usingRight = this.placement !== 'left'
// Handle special cases, first force to displaying on top if there's not space on bottom,
// regardless of what placement value was. Then check if there's not space on top, and
// force to bottom, again regardless of what placement value was.
const rightBoundary = origin.x - anchorWidth * 0.5 + (this.removePadding ? rightPadding : 0)
const leftBoundary = origin.x + anchorWidth * 0.5 - (this.removePadding ? leftPadding : 0)
if (leftBoundary + content.offsetWidth > xBounds.max) usingRight = true
if (rightBoundary - content.offsetWidth < xBounds.min) usingRight = false
const xOffset = (this.offset && this.offset.x) || 0
translateX = usingRight
? rightBoundary - xOffset - content.offsetWidth
: leftBoundary + xOffset
const yOffset = (this.offset && this.offset.y) || 0
translateY = origin.y + vertOffset + yOffset
} }
this.styles = { this.styles = {

View file

@ -150,7 +150,8 @@
"timelines": "Timelines", "timelines": "Timelines",
"chats": "Chats", "chats": "Chats",
"lists": "Lists", "lists": "Lists",
"edit_nav_mobile": "Customize navigation bar" "edit_nav_mobile": "Customize navigation bar",
"edit_pinned": "Edit pinned items"
}, },
"notifications": { "notifications": {
"broken_favorite": "Unknown status, searching for it…", "broken_favorite": "Unknown status, searching for it…",
@ -979,7 +980,8 @@
"create": "Create", "create": "Create",
"save": "Save changes", "save": "Save changes",
"delete": "Delete list", "delete": "Delete list",
"following_only": "Limit to Following" "following_only": "Limit to Following",
"manage_lists": "Manage lists"
}, },
"file_type": { "file_type": {
"audio": "Audio", "audio": "Audio",

View file

@ -9,27 +9,42 @@ export const mutations = {
setLists (state, value) { setLists (state, value) {
state.allLists = value state.allLists = value
}, },
setList (state, { id, title }) { setList (state, { listId, title }) {
if (!state.allListsObject[id]) { if (!state.allListsObject[listId]) {
state.allListsObject[id] = {} state.allListsObject[listId] = { accountIds: [] }
} }
state.allListsObject[id].title = title state.allListsObject[listId].title = title
if (!find(state.allLists, { id })) { if (!find(state.allLists, { listId })) {
state.allLists.push({ id, title }) state.allLists.push({ listId, title })
} else { } else {
find(state.allLists, { id }).title = title find(state.allLists, { listId }).title = title
} }
}, },
setListAccounts (state, { id, accountIds }) { setListAccounts (state, { listId, accountIds }) {
if (!state.allListsObject[id]) { if (!state.allListsObject[listId]) {
state.allListsObject[id] = {} state.allListsObject[listId] = { accountIds: [] }
} }
state.allListsObject[id].accountIds = accountIds state.allListsObject[listId].accountIds = accountIds
}, },
deleteList (state, { id }) { addListAccount (state, { listId, accountId }) {
delete state.allListsObject[id] if (!state.allListsObject[listId]) {
remove(state.allLists, list => list.id === id) state.allListsObject[listId] = { accountIds: [] }
}
state.allListsObject[listId].accountIds.push(accountId)
},
removeListAccount (state, { listId, accountId }) {
if (!state.allListsObject[listId]) {
state.allListsObject[listId] = { accountIds: [] }
}
const { accountIds } = state.allListsObject[listId]
const set = new Set(accountIds)
set.delete(accountId)
state.allListsObject[listId].accountIds = [...set]
},
deleteList (state, { listId }) {
delete state.allListsObject[listId]
remove(state.allLists, list => list.id === listId)
} }
} }
@ -40,37 +55,57 @@ const actions = {
createList ({ rootState, commit }, { title }) { createList ({ rootState, commit }, { title }) {
return rootState.api.backendInteractor.createList({ title }) return rootState.api.backendInteractor.createList({ title })
.then((list) => { .then((list) => {
commit('setList', { id: list.id, title }) commit('setList', { listId: list.id, title })
return list return list
}) })
}, },
fetchList ({ rootState, commit }, { id }) { fetchList ({ rootState, commit }, { listId }) {
return rootState.api.backendInteractor.getList({ id }) return rootState.api.backendInteractor.getList({ listId })
.then((list) => commit('setList', { id: list.id, title: list.title })) .then((list) => commit('setList', { id: list.id, title: list.title }))
}, },
fetchListAccounts ({ rootState, commit }, { id }) { fetchListAccounts ({ rootState, commit }, { listId }) {
return rootState.api.backendInteractor.getListAccounts({ id }) return rootState.api.backendInteractor.getListAccounts({ listId })
.then((accountIds) => commit('setListAccounts', { id, accountIds })) .then((accountIds) => commit('setListAccounts', { listId, accountIds }))
}, },
setList ({ rootState, commit }, { id, title }) { setList ({ rootState, commit }, { listId, title }) {
rootState.api.backendInteractor.updateList({ id, title }) rootState.api.backendInteractor.updateList({ listId, title })
commit('setList', { id, title }) commit('setList', { listId, title })
}, },
setListAccounts ({ rootState, commit }, { id, accountIds }) { setListAccounts ({ rootState, commit }, { listId, accountIds }) {
const saved = rootState.lists.allListsObject[id].accountIds || [] const saved = rootState.lists.allListsObject[listId].accountIds || []
const added = accountIds.filter(id => !saved.includes(id)) const added = accountIds.filter(id => !saved.includes(id))
const removed = saved.filter(id => !accountIds.includes(id)) const removed = saved.filter(id => !accountIds.includes(id))
commit('setListAccounts', { id, accountIds }) commit('setListAccounts', { listId, accountIds })
if (added.length > 0) { if (added.length > 0) {
rootState.api.backendInteractor.addAccountsToList({ id, accountIds: added }) rootState.api.backendInteractor.addAccountsToList({ listId, accountIds: added })
} }
if (removed.length > 0) { if (removed.length > 0) {
rootState.api.backendInteractor.removeAccountsFromList({ id, accountIds: removed }) rootState.api.backendInteractor.removeAccountsFromList({ listId, accountIds: removed })
} }
}, },
deleteList ({ rootState, commit }, { id }) { addListAccount ({ rootState, commit }, { listId, accountId }) {
rootState.api.backendInteractor.deleteList({ id }) return rootState
commit('deleteList', { id }) .api
.backendInteractor
.addAccountsToList({ listId, accountIds: [accountId] })
.then((result) => {
commit('addListAccount', { listId, accountId })
return result
})
},
removeListAccount ({ rootState, commit }, { listId, accountId }) {
return rootState
.api
.backendInteractor
.removeAccountsFromList({ listId, accountIds: [accountId] })
.then((result) => {
commit('removeListAccount', { listId, accountId })
return result
})
},
deleteList ({ rootState, commit }, { listId }) {
rootState.api.backendInteractor.deleteList({ listId })
commit('deleteList', { listId })
} }
} }

View file

@ -26,7 +26,7 @@ export const defaultState = {
collapseNav: false collapseNav: false
}, },
collections: { collections: {
pinnedNavItems: ['home', 'dms', 'chats', 'about'] pinnedNavItems: ['home', 'dms', 'chats']
} }
}, },
// raw data // raw data
@ -262,7 +262,7 @@ export const mutations = {
const live = userData.storage const live = userData.storage
state.raw = live state.raw = live
let cache = state.cache let cache = state.cache
if (cache._user !== userData.fqn) { if (cache && cache._user !== userData.fqn) {
console.warn('cache belongs to another user! reinitializing local cache!') console.warn('cache belongs to another user! reinitializing local cache!')
cache = null cache = null
} }

View file

@ -170,6 +170,9 @@ export const mutations = {
state.relationships[relationship.id] = relationship state.relationships[relationship.id] = relationship
}) })
}, },
updateUserInLists (state, { id, inLists }) {
state.usersObject[id].inLists = inLists
},
saveBlockIds (state, blockIds) { saveBlockIds (state, blockIds) {
state.currentUser.blockIds = blockIds state.currentUser.blockIds = blockIds
}, },
@ -291,6 +294,12 @@ const users = {
.then((relationships) => store.commit('updateUserRelationship', relationships)) .then((relationships) => store.commit('updateUserRelationship', relationships))
} }
}, },
fetchUserInLists (store, id) {
if (store.state.currentUser) {
store.rootState.api.backendInteractor.fetchUserInLists({ id })
.then((inLists) => store.commit('updateUserInLists', { id, inLists }))
}
},
fetchBlocks (store) { fetchBlocks (store) {
return store.rootState.api.backendInteractor.fetchBlocks() return store.rootState.api.backendInteractor.fetchBlocks()
.then((blocks) => { .then((blocks) => {

View file

@ -52,6 +52,7 @@ const MASTODON_STATUS_CONTEXT_URL = id => `/api/v1/statuses/${id}/context`
const MASTODON_USER_URL = '/api/v1/accounts' const MASTODON_USER_URL = '/api/v1/accounts'
const MASTODON_USER_RELATIONSHIPS_URL = '/api/v1/accounts/relationships' const MASTODON_USER_RELATIONSHIPS_URL = '/api/v1/accounts/relationships'
const MASTODON_USER_TIMELINE_URL = id => `/api/v1/accounts/${id}/statuses` const MASTODON_USER_TIMELINE_URL = id => `/api/v1/accounts/${id}/statuses`
const MASTODON_USER_IN_LISTS = id => `/api/v1/accounts/${id}/lists`
const MASTODON_LIST_URL = id => `/api/v1/lists/${id}` const MASTODON_LIST_URL = id => `/api/v1/lists/${id}`
const MASTODON_LIST_TIMELINE_URL = id => `/api/v1/timelines/list/${id}` const MASTODON_LIST_TIMELINE_URL = id => `/api/v1/timelines/list/${id}`
const MASTODON_LIST_ACCOUNTS_URL = id => `/api/v1/lists/${id}/accounts` const MASTODON_LIST_ACCOUNTS_URL = id => `/api/v1/lists/${id}/accounts`
@ -262,6 +263,13 @@ const unfollowUser = ({ id, credentials }) => {
}).then((data) => data.json()) }).then((data) => data.json())
} }
const fetchUserInLists = ({ id, credentials }) => {
const url = MASTODON_USER_IN_LISTS(id)
return fetch(url, {
headers: authHeaders(credentials)
}).then((data) => data.json())
}
const pinOwnStatus = ({ id, credentials }) => { const pinOwnStatus = ({ id, credentials }) => {
return promisedRequest({ url: MASTODON_PIN_OWN_STATUS(id), credentials, method: 'POST' }) return promisedRequest({ url: MASTODON_PIN_OWN_STATUS(id), credentials, method: 'POST' })
.then((data) => parseStatus(data)) .then((data) => parseStatus(data))
@ -408,14 +416,14 @@ const createList = ({ title, credentials }) => {
}).then((data) => data.json()) }).then((data) => data.json())
} }
const getList = ({ id, credentials }) => { const getList = ({ listId, credentials }) => {
const url = MASTODON_LIST_URL(id) const url = MASTODON_LIST_URL(listId)
return fetch(url, { headers: authHeaders(credentials) }) return fetch(url, { headers: authHeaders(credentials) })
.then((data) => data.json()) .then((data) => data.json())
} }
const updateList = ({ id, title, credentials }) => { const updateList = ({ listId, title, credentials }) => {
const url = MASTODON_LIST_URL(id) const url = MASTODON_LIST_URL(listId)
const headers = authHeaders(credentials) const headers = authHeaders(credentials)
headers['Content-Type'] = 'application/json' headers['Content-Type'] = 'application/json'
@ -426,15 +434,15 @@ const updateList = ({ id, title, credentials }) => {
}) })
} }
const getListAccounts = ({ id, credentials }) => { const getListAccounts = ({ listId, credentials }) => {
const url = MASTODON_LIST_ACCOUNTS_URL(id) const url = MASTODON_LIST_ACCOUNTS_URL(listId)
return fetch(url, { headers: authHeaders(credentials) }) return fetch(url, { headers: authHeaders(credentials) })
.then((data) => data.json()) .then((data) => data.json())
.then((data) => data.map(({ id }) => id)) .then((data) => data.map(({ id }) => id))
} }
const addAccountsToList = ({ id, accountIds, credentials }) => { const addAccountsToList = ({ listId, accountIds, credentials }) => {
const url = MASTODON_LIST_ACCOUNTS_URL(id) const url = MASTODON_LIST_ACCOUNTS_URL(listId)
const headers = authHeaders(credentials) const headers = authHeaders(credentials)
headers['Content-Type'] = 'application/json' headers['Content-Type'] = 'application/json'
@ -445,8 +453,8 @@ const addAccountsToList = ({ id, accountIds, credentials }) => {
}) })
} }
const removeAccountsFromList = ({ id, accountIds, credentials }) => { const removeAccountsFromList = ({ listId, accountIds, credentials }) => {
const url = MASTODON_LIST_ACCOUNTS_URL(id) const url = MASTODON_LIST_ACCOUNTS_URL(listId)
const headers = authHeaders(credentials) const headers = authHeaders(credentials)
headers['Content-Type'] = 'application/json' headers['Content-Type'] = 'application/json'
@ -457,8 +465,8 @@ const removeAccountsFromList = ({ id, accountIds, credentials }) => {
}) })
} }
const deleteList = ({ id, credentials }) => { const deleteList = ({ listId, credentials }) => {
const url = MASTODON_LIST_URL(id) const url = MASTODON_LIST_URL(listId)
return fetch(url, { return fetch(url, {
method: 'DELETE', method: 'DELETE',
headers: authHeaders(credentials) headers: authHeaders(credentials)
@ -1563,7 +1571,8 @@ const apiService = {
sendChatMessage, sendChatMessage,
readChat, readChat,
deleteChatMessage, deleteChatMessage,
setReportState setReportState,
fetchUserInLists
} }
export default apiService export default apiService

View file

@ -43,6 +43,7 @@ export const parseUser = (data) => {
// case for users in "mentions" property for statuses in MastoAPI // case for users in "mentions" property for statuses in MastoAPI
const mastoShort = masto && !Object.prototype.hasOwnProperty.call(data, 'avatar') const mastoShort = masto && !Object.prototype.hasOwnProperty.call(data, 'avatar')
output.inLists = null
output.id = String(data.id) output.id = String(data.id)
output._original = data // used for server-side settings output._original = data // used for server-side settings