Skip to content

Commit 50005f5

Browse files
authored
feat: add to favorites in preview app (#2251)
1 parent 6cd3fee commit 50005f5

4 files changed

Lines changed: 173 additions & 120 deletions

File tree

packages/web-app-preview/src/App.vue

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
:is-full-screen-mode-activated="isFullScreenModeActivated"
6464
:is-folder-loading="isFolderLoading"
6565
:show-image-controls="activeMediaFile?.isImage && !activeMediaFile?.isError"
66-
:show-delete-button="isDeleteButtonVisible"
6766
:current-image-rotation="currentImageRotation"
6867
:photo-roll-enabled="photoRollEnabled"
6968
@set-rotation-right="imageRotateRight"
@@ -107,7 +106,6 @@ import {
107106
queryItemAsString,
108107
sortHelper,
109108
useAppNavigation,
110-
useFileActionsDelete,
111109
useGetMatchingSpace,
112110
useKeyboardActions,
113111
usePreviewService,
@@ -165,7 +163,6 @@ const { dimensions } = usePreviewDimensions()
165163
const { getMatchingSpace } = useGetMatchingSpace()
166164
const { closeApp } = useAppNavigation({ router, currentFileContext })
167165
const { bindKeyAction, removeKeyAction } = useKeyboardActions()
168-
const { actions: deleteFileActions } = useFileActionsDelete()
169166
const {
170167
currentImageRotation,
171168
imageShrink,
@@ -192,16 +189,6 @@ const space = computed(() => {
192189
return getMatchingSpace(unref(activeMediaFile).resource)
193190
})
194191
195-
const isDeleteButtonVisible = computed(() => {
196-
if (!unref(space)) {
197-
return false
198-
}
199-
return unref(deleteFileActions)[0]?.isVisible({
200-
space: unref(space),
201-
resources: [unref(activeMediaFile).resource]
202-
})
203-
})
204-
205192
const sortBy = computed(() => {
206193
if (!unref(contextRouteQuery)) {
207194
return 'name'

packages/web-app-preview/src/components/MediaControls.vue

Lines changed: 135 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class="preview-controls-previous raw-hover-surface"
1212
appearance="raw"
1313
:aria-label="previousDescription"
14-
@click="$emit('togglePrevious')"
14+
@click="emit('togglePrevious')"
1515
>
1616
<oc-icon size="large" name="arrow-drop-left" />
1717
</oc-button>
@@ -24,7 +24,7 @@
2424
class="preview-controls-next raw-hover-surface"
2525
appearance="raw"
2626
:aria-label="nextDescription"
27-
@click="$emit('toggleNext')"
27+
@click="emit('toggleNext')"
2828
>
2929
<oc-icon size="large" name="arrow-drop-right" />
3030
</oc-button>
@@ -34,7 +34,7 @@
3434
data-testid="toggle-photo-roll"
3535
appearance="raw"
3636
:aria-label="togglePhotoRollDescription"
37-
@click="$emit('togglePhotoRoll')"
37+
@click="emit('togglePhotoRoll')"
3838
>
3939
<oc-icon name="side-bar" :fill-type="photoRollEnabled ? 'fill' : 'line'" />
4040
</oc-button>
@@ -48,7 +48,7 @@
4848
:aria-label="
4949
isFullScreenModeActivated ? exitFullScreenDescription : enterFullScreenDescription
5050
"
51-
@click="$emit('toggleFullScreen')"
51+
@click="emit('toggleFullScreen')"
5252
>
5353
<oc-icon
5454
fill-type="line"
@@ -63,7 +63,7 @@
6363
class="preview-controls-image-shrink raw-hover-surface p-1"
6464
appearance="raw"
6565
:aria-label="imageShrinkDescription"
66-
@click="$emit('setShrink')"
66+
@click="emit('setShrink')"
6767
>
6868
<oc-icon fill-type="line" name="zoom-out" />
6969
</oc-button>
@@ -72,7 +72,7 @@
7272
class="preview-controls-image-zoom raw-hover-surface p-1"
7373
appearance="raw"
7474
:aria-label="imageZoomDescription"
75-
@click="$emit('setZoom')"
75+
@click="emit('setZoom')"
7676
>
7777
<oc-icon fill-type="line" name="zoom-in" />
7878
</oc-button>
@@ -83,7 +83,7 @@
8383
class="preview-controls-rotate-left raw-hover-surface p-1"
8484
appearance="raw"
8585
:aria-label="imageRotateLeftDescription"
86-
@click="$emit('setRotationLeft')"
86+
@click="emit('setRotationLeft')"
8787
>
8888
<oc-icon fill-type="line" name="anticlockwise" />
8989
</oc-button>
@@ -92,7 +92,7 @@
9292
class="preview-controls-rotate-right raw-hover-surface p-1"
9393
appearance="raw"
9494
:aria-label="imageRotateRightDescription"
95-
@click="$emit('setRotationRight')"
95+
@click="emit('setRotationRight')"
9696
>
9797
<oc-icon fill-type="line" name="clockwise" />
9898
</oc-button>
@@ -103,123 +103,156 @@
103103
class="preview-controls-image-reset raw-hover-surface p-1"
104104
appearance="raw"
105105
:aria-label="imageResetDescription"
106-
@click="$emit('resetImage')"
106+
@click="emit('resetImage')"
107107
>
108108
<oc-icon fill-type="line" name="reset-left" />
109109
</oc-button>
110110
</div>
111111
</div>
112+
<oc-button
113+
v-if="showFavoriteButton"
114+
v-oc-tooltip="resourceFavoriteIconDescription"
115+
class="preview-controls-favorite raw-hover-surface p-1"
116+
appearance="raw"
117+
:aria-label="resourceFavoriteIconDescription"
118+
@click="favoriteFileActions[0].handler({ space, resources: [files[activeIndex].resource] })"
119+
>
120+
<oc-icon fill-type="line" :name="resourceFavoriteIcon" />
121+
</oc-button>
112122
<oc-button
113123
v-if="showDeleteButton"
114124
v-oc-tooltip="resourceDeleteDescription"
115125
class="preview-controls-delete raw-hover-surface p-1"
116126
appearance="raw"
117127
:aria-label="resourceDeleteDescription"
118-
@click="$emit('deleteResource')"
128+
@click="emit('deleteResource')"
119129
>
120-
<oc-icon fill-type="line" name="delete-bin" />
130+
<oc-icon fill-type="line" :name="resourceDeleteIcon" />
121131
</oc-button>
122132
</div>
123133
</div>
124134
</template>
125-
<script lang="ts">
126-
import { computed, defineComponent, PropType } from 'vue'
135+
<script setup lang="ts">
136+
import { computed, unref } from 'vue'
127137
import { useGettext } from 'vue3-gettext'
128-
import { isMacOs } from '@opencloud-eu/web-pkg'
138+
import {
139+
ActionOptions,
140+
isMacOs,
141+
useFileActionsDelete,
142+
useFileActionsFavorite,
143+
useGetMatchingSpace
144+
} from '@opencloud-eu/web-pkg'
129145
import { MediaFile } from '../helpers/types'
130146
131-
export default defineComponent({
132-
name: 'MediaControls',
133-
props: {
134-
files: {
135-
type: Array as PropType<MediaFile[]>,
136-
required: true
137-
},
138-
activeIndex: {
139-
type: Number,
140-
default: 0
141-
},
142-
isFullScreenModeActivated: {
143-
type: Boolean,
144-
default: false
145-
},
146-
isFolderLoading: {
147-
type: Boolean,
148-
default: false
149-
},
150-
showImageControls: {
151-
type: Boolean,
152-
default: false
153-
},
154-
showDeleteButton: {
155-
type: Boolean,
156-
default: true
157-
},
158-
currentImageRotation: {
159-
type: Number,
160-
default: 0
161-
},
162-
photoRollEnabled: {
163-
type: Boolean,
164-
default: true
165-
}
166-
},
167-
emits: [
168-
'setRotationLeft',
169-
'setRotationRight',
170-
'setShrink',
171-
'setZoom',
172-
'toggleFullScreen',
173-
'toggleNext',
174-
'togglePrevious',
175-
'resetImage',
176-
'deleteResource',
177-
'togglePhotoRoll'
178-
],
179-
setup(props) {
180-
const { $gettext } = useGettext()
147+
const {
148+
files,
149+
activeIndex = 0,
150+
photoRollEnabled = true,
151+
isFullScreenModeActivated = false,
152+
isFolderLoading = false,
153+
showImageControls = false,
154+
currentImageRotation = 0
155+
} = defineProps<{
156+
files: MediaFile[]
157+
activeIndex?: number
158+
isFullScreenModeActivated?: boolean
159+
isFolderLoading?: boolean
160+
showImageControls?: boolean
161+
currentImageRotation?: number
162+
photoRollEnabled?: boolean
163+
}>()
164+
165+
void currentImageRotation
181166
182-
const ariaHiddenFileCount = computed(() => {
183-
return $gettext('%{ displayIndex } of %{ availableMediaFiles }', {
184-
displayIndex: (props.activeIndex + 1).toString(),
185-
availableMediaFiles: props.files.length.toString()
186-
})
187-
})
188-
const screenreaderFileCount = computed(() => {
189-
return $gettext('Media file %{ displayIndex } of %{ availableMediaFiles }', {
190-
displayIndex: (props.activeIndex + 1).toString(),
191-
availableMediaFiles: props.files.length.toString()
192-
})
193-
})
167+
const emit = defineEmits<{
168+
(e: 'setRotationLeft'): void
169+
(e: 'setRotationRight'): void
170+
(e: 'setShrink'): void
171+
(e: 'setZoom'): void
172+
(e: 'toggleFullScreen'): void
173+
(e: 'toggleNext'): void
174+
(e: 'togglePrevious'): void
175+
(e: 'resetImage'): void
176+
(e: 'deleteResource'): void
177+
(e: 'togglePhotoRoll'): void
178+
}>()
194179
195-
const resourceDeleteDescription = computed(() => {
196-
return $gettext('Delete (%{key})', {
197-
key: isMacOs() ? $gettext('⌘ + Backspace') : $gettext('Del')
198-
})
199-
})
180+
const { $gettext } = useGettext()
181+
const { getMatchingSpace } = useGetMatchingSpace()
182+
const { actions: favoriteFileActions } = useFileActionsFavorite()
183+
const { actions: deleteFileActions } = useFileActionsDelete()
200184
201-
const togglePhotoRollDescription = computed(() => {
202-
if (props.photoRollEnabled) {
203-
return $gettext('Hide photo roll')
204-
}
205-
return $gettext('Show photo roll')
206-
})
185+
const space = computed(() => getMatchingSpace(files[activeIndex].resource))
207186
208-
return {
209-
screenreaderFileCount,
210-
ariaHiddenFileCount,
211-
resourceDeleteDescription,
212-
togglePhotoRollDescription,
213-
enterFullScreenDescription: $gettext('Enter full screen mode'),
214-
exitFullScreenDescription: $gettext('Exit full screen mode'),
215-
imageShrinkDescription: $gettext('Shrink the image (⇧ + Mouse wheel)'),
216-
imageZoomDescription: $gettext('Enlarge the image (⇧ + Mouse wheel)'),
217-
imageResetDescription: $gettext('Reset'),
218-
imageRotateLeftDescription: $gettext('Rotate the image 90 degrees to the left'),
219-
imageRotateRightDescription: $gettext('Rotate the image 90 degrees to the right'),
220-
previousDescription: $gettext('Show previous media file in folder'),
221-
nextDescription: $gettext('Show next media file in folder')
222-
}
187+
const ariaHiddenFileCount = computed(() => {
188+
return $gettext('%{ displayIndex } of %{ availableMediaFiles }', {
189+
displayIndex: (activeIndex + 1).toString(),
190+
availableMediaFiles: files.length.toString()
191+
})
192+
})
193+
const screenreaderFileCount = computed(() => {
194+
return $gettext('Media file %{ displayIndex } of %{ availableMediaFiles }', {
195+
displayIndex: (activeIndex + 1).toString(),
196+
availableMediaFiles: files.length.toString()
197+
})
198+
})
199+
200+
const togglePhotoRollDescription = computed(() => {
201+
if (photoRollEnabled) {
202+
return $gettext('Hide photo roll')
223203
}
204+
return $gettext('Show photo roll')
224205
})
206+
207+
const showDeleteButton = computed(() => {
208+
return unref(deleteFileActions)[0]?.isVisible({
209+
space: unref(space),
210+
resources: [files[activeIndex].resource]
211+
})
212+
})
213+
214+
const showFavoriteButton = computed(() => {
215+
return unref(favoriteFileActions)[0]?.isVisible({
216+
space: unref(space),
217+
resources: [files[activeIndex].resource]
218+
})
219+
})
220+
221+
const resourceDeleteIcon = computed(() => {
222+
return unref(deleteFileActions)[0].icon as string
223+
})
224+
225+
const resourceDeleteDescription = computed(() => {
226+
return $gettext('Delete (%{key})', {
227+
key: isMacOs() ? $gettext('⌘ + Backspace') : $gettext('Del')
228+
})
229+
})
230+
231+
const resourceFavoriteIcon = computed(() => {
232+
return (unref(favoriteFileActions)[0].icon as (options: ActionOptions) => string)({
233+
space: unref(space),
234+
resources: [files[activeIndex].resource]
235+
})
236+
})
237+
238+
const resourceFavoriteIconDescription = computed(() => {
239+
return unref(favoriteFileActions)[0].label({
240+
space: unref(space),
241+
resources: [files[activeIndex].resource]
242+
})
243+
})
244+
245+
const enterFullScreenDescription = computed(() => $gettext('Enter full screen mode'))
246+
const exitFullScreenDescription = computed(() => $gettext('Exit full screen mode'))
247+
const imageShrinkDescription = computed(() => $gettext('Shrink the image (⇧ + Mouse wheel)'))
248+
const imageZoomDescription = computed(() => $gettext('Enlarge the image (⇧ + Mouse wheel)'))
249+
const imageResetDescription = computed(() => $gettext('Reset'))
250+
const imageRotateLeftDescription = computed(() =>
251+
$gettext('Rotate the image 90 degrees to the left')
252+
)
253+
const imageRotateRightDescription = computed(() =>
254+
$gettext('Rotate the image 90 degrees to the right')
255+
)
256+
const previousDescription = computed(() => $gettext('Show previous media file in folder'))
257+
const nextDescription = computed(() => $gettext('Show next media file in folder'))
225258
</script>

0 commit comments

Comments
 (0)