Skip to content

Commit

Permalink
Do not load user config for each previews
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Nov 15, 2023
1 parent 318d22c commit 53cf1b8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/components/FilePicker/FileList.vue
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
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
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
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
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

0 comments on commit 53cf1b8

Please sign in to comment.