Skip to content

Commit

Permalink
fix: favorites colour, icon, unwanted eslint-disable, typing and preview
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv committed Jul 5, 2023
1 parent 9b0e3a9 commit 7fab7ec
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 75 deletions.
2 changes: 1 addition & 1 deletion apps/files/src/components/FilesListVirtual.vue
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export default Vue.extend({
position: absolute;
top: 4px;
right: -8px;
color: #ffcc00;
color: #a08b00;
}
}
Expand Down
5 changes: 2 additions & 3 deletions apps/files/src/services/Favorites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/
import { File, Folder, parseWebdavPermissions } from '@nextcloud/files'
import { generateRemoteUrl, generateUrl } from '@nextcloud/router'
import { generateRemoteUrl } from '@nextcloud/router'
import { getClient, rootPath } from './WebdavClient'
import { getCurrentUser } from '@nextcloud/auth'
import { getDavNameSpaces, getDavProperties, getDefaultPropfind } from './DavProperties'
Expand Down Expand Up @@ -49,7 +49,6 @@ const resultToNode = function(node: FileStat): File | Folder {
const props = node.props as ResponseProps
const permissions = parseWebdavPermissions(props?.permissions)
const owner = getCurrentUser()?.uid as string
const previewUrl = generateUrl('/core/preview?fileId={fileid}&x=32&y=32&forceIcon=0', props)

const nodeData = {
id: props?.fileid as number || 0,
Expand All @@ -63,7 +62,7 @@ const resultToNode = function(node: FileStat): File | Folder {
attributes: {
...node,
...props,
previewUrl,
hasPreview: props?.['has-preview'],
},
}

Expand Down
1 change: 0 additions & 1 deletion apps/files/src/services/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* eslint-disable */
import type { Folder, Node } from '@nextcloud/files'
import isSvg from 'is-svg'

Expand Down
1 change: 0 additions & 1 deletion apps/files/src/store/actionsmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* eslint-disable */
import { defineStore } from 'pinia'
import type { ActionsMenuStore } from '../types'

Expand Down
16 changes: 7 additions & 9 deletions apps/files/src/store/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* eslint-disable */
import type { Folder, Node } from '@nextcloud/files'
import type { FilesStore, RootsStore, RootOptions, Service, FilesState } from '../types'
import type { FilesStore, RootsStore, RootOptions, Service, FilesState, FileId } from '../types'

import { defineStore } from 'pinia'
import { subscribe } from '@nextcloud/event-bus'
import logger from '../logger'
import type { FileId } from '../types'
import Vue from 'vue'

export const useFilesStore = function() {
export const useFilesStore = function(...args) {
const store = defineStore('files', {
state: (): FilesState => ({
files: {} as FilesStore,
Expand All @@ -40,7 +38,7 @@ export const useFilesStore = function() {
/**
* Get a file or folder by id
*/
getNode: (state) => (id: FileId): Node|undefined => state.files[id],
getNode: (state) => (id: FileId): Node|undefined => state.files[id],

/**
* Get a list of files or folders by their IDs
Expand All @@ -52,7 +50,7 @@ export const useFilesStore = function() {
/**
* Get a file or folder by id
*/
getRoot: (state) => (service: Service): Folder|undefined => state.roots[service],
getRoot: (state) => (service: Service): Folder|undefined => state.roots[service],
},

actions: {
Expand All @@ -67,7 +65,7 @@ export const useFilesStore = function() {
return acc
}, {} as FilesStore)

Vue.set(this, 'files', {...this.files, ...files})
Vue.set(this, 'files', { ...this.files, ...files })
},

deleteNodes(nodes: Node[]) {
Expand All @@ -85,10 +83,10 @@ export const useFilesStore = function() {
onDeletedNode(node: Node) {
this.deleteNodes([node])
},
}
},
})

const fileStore = store(...arguments)
const fileStore = store(...args)
// Make sure we only register the listeners once
if (!fileStore._initialized) {
// subscribe('files:node:created', fileStore.onCreatedNode)
Expand Down
9 changes: 4 additions & 5 deletions apps/files/src/store/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* eslint-disable */
import { defineStore } from 'pinia'
import Vue from 'vue'

Expand All @@ -28,9 +27,9 @@ import Vue from 'vue'
* special keys states. Useful for checking the
* current status of a key when executing a method.
*/
export const useKeyboardStore = function() {
export const useKeyboardStore = function(...args) {
const store = defineStore('keyboard', {
state: () => ({
state: () => ({
altKey: false,
ctrlKey: false,
metaKey: false,
Expand All @@ -47,10 +46,10 @@ export const useKeyboardStore = function() {
Vue.set(this, 'metaKey', !!event.metaKey)
Vue.set(this, 'shiftKey', !!event.shiftKey)
},
}
},
})

const keyboardStore = store(...arguments)
const keyboardStore = store(...args)
// Make sure we only register the listeners once
if (!keyboardStore._initialized) {
window.addEventListener('keydown', keyboardStore.onEvent)
Expand Down
14 changes: 5 additions & 9 deletions apps/files/src/store/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* eslint-disable */
import type { PathOptions, ServicesState } from '../types'

import type { FileId, PathsStore, PathOptions, ServicesState } from '../types'
import { defineStore } from 'pinia'
import { subscribe } from '@nextcloud/event-bus'
import type { FileId, PathsStore } from '../types'
import Vue from 'vue'

export const usePathsStore = function() {
export const usePathsStore = function(...args) {
const store = defineStore('paths', {
state: () => ({
paths: {} as ServicesState
paths: {} as ServicesState,
} as PathsStore),

getters: {
Expand All @@ -54,10 +50,10 @@ export const usePathsStore = function() {
// Now we can set the provided path
Vue.set(this.paths[payload.service], payload.path, payload.fileid)
},
}
},
})

const pathsStore = store(...arguments)
const pathsStore = store(...args)
// Make sure we only register the listeners once
if (!pathsStore._initialized) {
// TODO: watch folders to update paths?
Expand Down
5 changes: 2 additions & 3 deletions apps/files/src/store/renaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* eslint-disable */
import { defineStore } from 'pinia'
import { subscribe } from '@nextcloud/event-bus'
import type { Node } from '@nextcloud/files'
import type { RenamingStore } from '../types'

export const useRenamingStore = function() {
export const useRenamingStore = function(...args) {
const store = defineStore('renaming', {
state: () => ({
renamingNode: undefined,
newName: '',
} as RenamingStore),
})

const renamingStore = store(...arguments)
const renamingStore = store(...args)

// Make sure we only register the listeners once
if (!renamingStore._initialized) {
Expand Down
5 changes: 2 additions & 3 deletions apps/files/src/store/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* eslint-disable */
import { defineStore } from 'pinia'
import Vue from 'vue'
import { FileId, SelectionStore } from '../types'
Expand Down Expand Up @@ -55,6 +54,6 @@ export const useSelectionStore = defineStore('selection', {
Vue.set(this, 'selected', [])
Vue.set(this, 'lastSelection', [])
Vue.set(this, 'lastSelectedIndex', null)
}
}
},
},
})
20 changes: 9 additions & 11 deletions apps/files/src/store/userconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* eslint-disable */
import { loadState } from '@nextcloud/initial-state'
import { generateUrl } from '@nextcloud/router'
import { defineStore } from 'pinia'
import Vue from 'vue'
import axios from '@nextcloud/axios'
import type { UserConfig, UserConfigStore } from '../types'
import { defineStore } from 'pinia'
import { emit, subscribe } from '@nextcloud/event-bus'
import { generateUrl } from '@nextcloud/router'
import { loadState } from '@nextcloud/initial-state'
import axios from '@nextcloud/axios'
import Vue from 'vue'

const userConfig = loadState('files', 'config', {
show_hidden: false,
crop_image_previews: true,
sort_favorites_first: true,
}) as UserConfig

export const useUserConfigStore = function() {
export const useUserConfigStore = function(...args) {
const store = defineStore('userconfig', {
state: () => ({
userConfig,
Expand All @@ -57,11 +56,11 @@ export const useUserConfigStore = function() {
})

emit('files:config:updated', { key, value })
}
}
},
},
})

const userConfigStore = store(...arguments)
const userConfigStore = store(...args)

// Make sure we only register the listeners once
if (!userConfigStore._initialized) {
Expand All @@ -73,4 +72,3 @@ export const useUserConfigStore = function() {

return userConfigStore
}

23 changes: 10 additions & 13 deletions apps/files/src/store/viewConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* eslint-disable */
import { defineStore } from 'pinia'
import { emit, subscribe } from '@nextcloud/event-bus'
import { generateUrl } from '@nextcloud/router'
import { loadState } from '@nextcloud/initial-state'
import axios from '@nextcloud/axios'
import Vue from 'vue'

import type { ViewConfigs, ViewConfigStore, ViewId } from '../types'
import type { ViewConfig } from '../types'
import type { ViewConfigs, ViewConfigStore, ViewId, ViewConfig } from '../types'

const viewConfig = loadState('files', 'viewConfigs', {}) as ViewConfigs

export const useViewConfigStore = function() {
export const useViewConfigStore = function(...args) {
const store = defineStore('viewconfig', {
state: () => ({
viewConfig,
Expand Down Expand Up @@ -69,26 +67,26 @@ export const useViewConfigStore = function() {
* The key param must be a valid key of a File object
* If not found, will be searched within the File attributes
*/
setSortingBy(key: string = 'basename', view: string = 'files') {
setSortingBy(key = 'basename', view = 'files') {
// Save new config
this.update(view, 'sorting_mode', key)
this.update(view, 'sorting_direction', 'asc')
},

/**
* Toggle the sorting direction
*/
toggleSortingDirection(view: string = 'files') {
const config = this.getConfig(view) || { 'sorting_direction': 'asc' }
toggleSortingDirection(view = 'files') {
const config = this.getConfig(view) || { sorting_direction: 'asc' }
const newDirection = config.sorting_direction === 'asc' ? 'desc' : 'asc'

// Save new config
this.update(view, 'sorting_direction', newDirection)
}
}
},
},
})

const viewConfigStore = store(...arguments)
const viewConfigStore = store(...args)

// Make sure we only register the listeners once
if (!viewConfigStore._initialized) {
Expand All @@ -100,4 +98,3 @@ export const useViewConfigStore = function() {

return viewConfigStore
}

22 changes: 10 additions & 12 deletions apps/files/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* eslint-disable */
import type { Folder } from '@nextcloud/files'
import type { Node } from '@nextcloud/files'
import type { Folder, Node } from '@nextcloud/files'

// Global definitions
export type Service = string
export type FileId = number
export type ViewId = string

// Files store
export type FilesState = {
files: FilesStore,
roots: RootsStore,
}

export type FilesStore = {
[fileid: FileId]: Node
}
Expand All @@ -42,20 +35,25 @@ export type RootsStore = {
[service: Service]: Folder
}

export type FilesState = {
files: FilesStore,
roots: RootsStore,
}

export interface RootOptions {
root: Folder
service: Service
}

// Paths store
export type ServicesState = {
[service: Service]: PathConfig
}

export type PathConfig = {
[path: string]: number
}

export type ServicesState = {
[service: Service]: PathConfig
}

export type PathsStore = {
paths: ServicesState
}
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/views/favorites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const generateIdFromPath = function(path: string): string {

export default () => {
// Load state in function for mock testing purposes
const favoriteFolders = loadState('files', 'favoriteFolders', []) as string[]
const favoriteFolders = loadState<string[]>('files', 'favoriteFolders', [])
const favoriteFoldersViews = favoriteFolders.map((folder, index) => generateFolderView(folder, index))

const Navigation = window.OCP.Files.Navigation as NavigationService
Expand Down
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

0 comments on commit 7fab7ec

Please sign in to comment.