Skip to content

Commit

Permalink
Show message upon current folder has been deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAndBear committed Mar 12, 2024
1 parent f7f75b2 commit 098122f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
9 changes: 8 additions & 1 deletion packages/web-runtime/src/container/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
useSharesStore,
useResourcesStore,
ResourcesStore,
SpacesStore
SpacesStore,
MessageStore
} from '@ownclouders/web-pkg'
import { authService } from '../services/auth'
import {
Expand Down Expand Up @@ -646,15 +647,19 @@ export const announceCustomStyles = ({ configStore }: { configStore?: ConfigStor
}

export const registerSSEEventListeners = ({
language,
resourcesStore,
spacesStore,
messageStore,
clientService,
previewService,
configStore,
router
}: {
language: Language
resourcesStore: ResourcesStore
spacesStore: SpacesStore
messageStore: MessageStore
clientService: ClientService
previewService: PreviewService
configStore: ConfigStore
Expand Down Expand Up @@ -717,7 +722,9 @@ export const registerSSEEventListeners = ({
clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.ITEM_TRASHED, (msg) =>
onSSEItemTrashedEvent({
topic: MESSAGE_TYPE.ITEM_TRASHED,
language,
resourcesStore,
messageStore,
msg
})
)
Expand Down
21 changes: 18 additions & 3 deletions packages/web-runtime/src/container/sse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
createFileRouteOptions,
getIndicators,
ImageDimension,
MessageStore,
PreviewService,
ResourcesStore,
SpacesStore
Expand All @@ -11,6 +12,7 @@ import PQueue from 'p-queue'
import { extractNodeId, extractStorageId } from '@ownclouders/web-client/src/helpers'
import { z } from 'zod'
import { Router } from 'vue-router'
import { Language } from 'vue3-gettext'

const fileReadyEventSchema = z.object({
itemid: z.string(),
Expand Down Expand Up @@ -207,15 +209,30 @@ export const onSSEProcessingFinishedEvent = async ({

export const onSSEItemTrashedEvent = ({
topic,
language,
messageStore,
resourcesStore,
msg
}: {
topic: string
language: Language
resourcesStore: ResourcesStore
messageStore: MessageStore
msg: MessageEvent
}) => {
try {
const sseData = fileReadyEventSchema.parse(JSON.parse(msg.data))
const currentFolder = resourcesStore.currentFolder
const resourceIsCurrentFolder = currentFolder.id === sseData.itemid

if (resourceIsCurrentFolder) {
return messageStore.showMessage({
title: language.$gettext(
'The folder you were accessing has been removed. Please navigate to another location.'
)
})
}

const resource = resourcesStore.resources.find((f) => f.id === sseData.itemid)

if (!resource) {
Expand Down Expand Up @@ -243,10 +260,8 @@ export const onSSEItemRestoredEvent = async ({
}) => {
try {
const sseData = fileReadyEventSchema.parse(JSON.parse(msg.data))
console.log(sseData.spaceid)
console.log(spacesStore.spaces)

const space = spacesStore.spaces.find((space) => space.id === sseData.spaceid)
console.log(space)
if (!space) {
return
}
Expand Down
3 changes: 3 additions & 0 deletions packages/web-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const bootstrapApp = async (configurationPath: string): Promise<void> =>
spacesStore,
userStore,
resourcesStore,
messagesStore,
sharesStore
} = announcePiniaStores()

Expand Down Expand Up @@ -192,8 +193,10 @@ export const bootstrapApp = async (configurationPath: string): Promise<void> =>
// Register SSE event listeners
if (capabilityStore.supportSSE) {
registerSSEEventListeners({
language: gettext,
resourcesStore,
spacesStore,
messageStore: messagesStore,
clientService,
previewService,
configStore,
Expand Down

0 comments on commit 098122f

Please sign in to comment.