Skip to content

Commit

Permalink
fix: refactor PublicShareSidebar
Browse files Browse the repository at this point in the history
- wrap mounting in function
- adjust shareToken receiving to server API
- adjust mountpoint to #content-vue

Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Oct 24, 2024
1 parent fa84b49 commit d36b4dc
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/mainPublicShareSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,13 @@ const pinia = createPinia()
*/
function adjustLayout() {
document.querySelector('#app-content').appendChild(document.querySelector('footer'))

const talkSidebarElement = document.createElement('div')
talkSidebarElement.setAttribute('id', 'talk-sidebar')
document.querySelector('#content').appendChild(talkSidebarElement)
}

adjustLayout()

// An "isOpen" boolean should be passed to the component, but as it is a
// primitive it would not be reactive; it needs to be wrapped in an object and

// that object passed to the component to get reactivity.
const sidebarState = reactive({
isOpen: false,
Expand Down Expand Up @@ -93,21 +90,27 @@ function addTalkSidebarTrigger() {
addTalkSidebarTrigger()

/**
*
* Mount the Talk sidebar next to the main content.
*/
function getShareToken() {
const shareTokenElement = document.getElementById('sharingToken')
return shareTokenElement.value
function addTalkSidebar() {
// location.pathname is expected to be like /index.php/s/<shareToken>
const shareToken = window.location.pathname.split('/').pop()

const talkSidebarElement = document.createElement('div')
talkSidebarElement.setAttribute('id', 'talk-sidebar')
document.getElementById('content-vue').appendChild(talkSidebarElement)

const talkSidebarVm = new Vue({
store,
pinia,
id: 'talk-chat-tab',
propsData: {
shareToken,
state: sidebarState,
},
...PublicShareSidebar,
})
talkSidebarVm.$mount(document.querySelector('#talk-sidebar'))
}

const talkSidebarVm = new Vue({
store,
pinia,
id: 'talk-chat-tab',
propsData: {
shareToken: getShareToken(),
state: sidebarState,
},
...PublicShareSidebar,
})
talkSidebarVm.$mount(document.querySelector('#talk-sidebar'))
addTalkSidebar()

0 comments on commit d36b4dc

Please sign in to comment.