Skip to content

Commit

Permalink
Move stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Mar 3, 2023
1 parent 078810c commit c13b609
Showing 1 changed file with 55 additions and 56 deletions.
111 changes: 55 additions & 56 deletions packages/web-runtime/src/components/Topbar/Notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,65 @@ export default {
const notificationsInterval = ref()
const dropdownOpened = ref(false)
const setAdditionalDataTask = useTask(function* (signal) {
const formatDate = (date) => {
return formatDateFromISO(date, currentLanguage)
}
const formatDateRelative = (date) => {
return formatRelativeDateFromISO(date, currentLanguage)
}
const messageParameters = [
{ name: 'user', labelAttribute: 'displayname' },
{ name: 'resource', labelAttribute: 'name' },
{ name: 'space', labelAttribute: 'name' }
]
const getMessage = ({ message, messageRich, messageRichParameters }: Notification) => {
if (messageRich) {
let interpolatedMessage = messageRich
for (const param of messageParameters) {
if (interpolatedMessage.includes(`{${param.name}}`)) {
const label = messageRichParameters[param.name][param.labelAttribute]
interpolatedMessage = interpolatedMessage.replace(
`{${param.name}}`,
`<strong>${label}</strong>`
)
}
}
return interpolatedMessage
}
return message
}
const getLink = ({ messageRichParameters, object_type }: Notification) => {
if (!messageRichParameters) {
return null
}
if (object_type === 'share' && messageRichParameters?.resource?.id) {
return {
name: 'files-shares-with-me',
query: {
scrollTo: messageRichParameters.resource.name
}
}
}
if (object_type === 'storagespace' && messageRichParameters?.space?.id) {
const space = store.getters['runtime/spaces/spaces'].find(
(s) => s.fileId === messageRichParameters?.space?.id.split('!')[0]
)
if (space) {
return { name: 'files-spaces-generic', params: { driveAliasAndItem: space.driveAlias } }
}
}
return null
}
const setAdditionalData = () => {
loading.value = true
for (const notification of unref(notifications)) {
notification.computedMessage = getMessage(notification)
notification.computedLink = getLink(notification)
}
loading.value = false
}).restartable()
}
const fetchNotificationsTask = useTask(function* (signal) {
loading.value = true
Expand All @@ -141,7 +192,7 @@ export default {
console.error(e)
} finally {
if (unref(dropdownOpened)) {
setAdditionalDataTask.perform()
setAdditionalData()
}
loading.value = false
}
Expand Down Expand Up @@ -211,64 +262,12 @@ export default {
}
}
const formatDate = (date) => {
return formatDateFromISO(date, currentLanguage)
}
const formatDateRelative = (date) => {
return formatRelativeDateFromISO(date, currentLanguage)
}
const messageParameters = [
{ name: 'user', labelAttribute: 'displayname' },
{ name: 'resource', labelAttribute: 'name' },
{ name: 'space', labelAttribute: 'name' }
]
const getMessage = ({ message, messageRich, messageRichParameters }: Notification) => {
if (messageRich) {
let interpolatedMessage = messageRich
for (const param of messageParameters) {
if (interpolatedMessage.includes(`{${param.name}}`)) {
const label = messageRichParameters[param.name][param.labelAttribute]
interpolatedMessage = interpolatedMessage.replace(
`{${param.name}}`,
`<strong>${label}</strong>`
)
}
}
return interpolatedMessage
}
return message
}
const getLink = ({ messageRichParameters, object_type }: Notification) => {
if (!messageRichParameters) {
return null
}
if (object_type === 'share' && messageRichParameters?.resource?.id) {
return {
name: 'files-shares-with-me',
query: {
scrollTo: messageRichParameters.resource.name
}
}
}
if (object_type === 'storagespace' && messageRichParameters?.space?.id) {
const space = store.getters['runtime/spaces/spaces'].find(
(s) => s.fileId === messageRichParameters?.space?.id.split('!')[0]
)
if (space) {
return { name: 'files-spaces-generic', params: { driveAliasAndItem: space.driveAlias } }
}
}
return null
}
const hideDrop = () => {
dropdownOpened.value = false
}
const showDrop = () => {
dropdownOpened.value = true
setAdditionalDataTask.perform()
setAdditionalData()
}
onMounted(() => {
Expand Down

0 comments on commit c13b609

Please sign in to comment.