Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not load user config for each previews #1108

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/components/FilePicker/FileList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
:can-pick="multiselect || selectedFiles.length === 0 || selectedFiles.includes(file)"
:selected="selectedFiles.includes(file)"
:node="file"
:crop-image-previews="cropImagePreviews"
@update:selected="onNodeSelected(file)"
@enter-directory="onChangeDirectory" />
</template>
Expand Down Expand Up @@ -132,7 +133,7 @@ const toggleSorting = (sortBy: ISortingAttributes) => {
}
}

const { sortFavoritesFirst } = useFilesSettings()
const { sortFavoritesFirst, cropImagePreviews } = useFilesSettings()

/**
* Files sorted by columns
Expand Down
6 changes: 6 additions & 0 deletions lib/components/FilePicker/FileListRow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('FilePicker: FileListRow', () => {
showCheckbox: true,
canPick: true,
node,
cropImagePreviews: true,
},
})

Expand All @@ -70,6 +71,7 @@ describe('FilePicker: FileListRow', () => {
showCheckbox: true,
canPick: true,
node,
cropImagePreviews: true,
},
})

Expand All @@ -86,6 +88,7 @@ describe('FilePicker: FileListRow', () => {
showCheckbox: true,
canPick: true,
node,
cropImagePreviews: true,
},
})

Expand All @@ -103,6 +106,7 @@ describe('FilePicker: FileListRow', () => {
showCheckbox: true,
canPick: true,
node,
cropImagePreviews: true,
},
})

Expand All @@ -120,6 +124,7 @@ describe('FilePicker: FileListRow', () => {
showCheckbox: false,
canPick: true,
node,
cropImagePreviews: true,
},
})

Expand All @@ -137,6 +142,7 @@ describe('FilePicker: FileListRow', () => {
showCheckbox: false,
canPick: true,
node,
cropImagePreviews: true,
},
})

Expand Down
4 changes: 3 additions & 1 deletion lib/components/FilePicker/FileListRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</td>
<td class="row-name">
<div class="file-picker__name-container" data-testid="row-name">
<FilePreview :node="node" />
<FilePreview :node="node" :crop-image-previews="cropImagePreviews" />
<div class="file-picker__file-name" :title="displayName" v-text="displayName" />
<div class="file-picker__file-extension" v-text="fileExtension" />
</div>
Expand Down Expand Up @@ -55,6 +55,8 @@ const props = defineProps<{
canPick: boolean
/** The current node */
node: Node
/** Whether the preview should be cropped */
cropImagePreviews: Boolean
}>()

const emit = defineEmits<{
Expand Down
3 changes: 1 addition & 2 deletions lib/components/FilePicker/FilePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import { FileType, type Node } from '@nextcloud/files'
import { computed, ref, watch } from 'vue'
import { getPreviewURL } from '../../composables/preview'
import { useFilesSettings } from '../../composables/filesSettings'
import { t } from '../../utils/l10n'

import IconFile from 'vue-material-design-icons/File.vue'
Expand All @@ -26,9 +25,9 @@ const fileListIconStyles = ref(fileListIconStylesModule)

const props = defineProps<{
node: Node
cropImagePreviews: Boolean
}>()

const { cropImagePreviews } = useFilesSettings()
const previewURL = computed(() => getPreviewURL(props.node, { cropPreview: cropImagePreviews.value }))

const isFile = computed(() => props.node.type === FileType.File)
Expand Down
8 changes: 4 additions & 4 deletions lib/composables/filesSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export const useFilesSettings = () => {
const cropImagePreviews = ref(filesUserState?.crop_image_previews ?? true)

onMounted(() => {
axios.get(generateUrl('/apps/files/api/v1/configs')).then((respose) => {
showHiddenFiles.value = respose.data?.data?.show_hidden ?? false
sortFavoritesFirst.value = respose.data?.data?.sort_favorites_first ?? true
cropImagePreviews.value = respose.data?.data?.crop_image_previews ?? true
axios.get(generateUrl('/apps/files/api/v1/configs')).then((response) => {
showHiddenFiles.value = response.data?.data?.show_hidden ?? false
sortFavoritesFirst.value = response.data?.data?.sort_favorites_first ?? true
cropImagePreviews.value = response.data?.data?.crop_image_previews ?? true
})
})

Expand Down