Skip to content

Commit

Permalink
cleaner asset names
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed Oct 7, 2024
1 parent b296191 commit 03d5dba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions frontend/src/scenes/frame/panels/Assets/Assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function humaniseSize(size: number) {

export function Assets(): JSX.Element {
const { frame } = useValues(frameLogic)
const { assetsLoading, assets } = useValues(assetsLogic({ frameId: frame.id }))
const { assetsLoading, cleanedAssets } = useValues(assetsLogic({ frameId: frame.id }))
const { openAsset } = useActions(panelsLogic({ frameId: frame.id }))
return (
<div className="space-y-2">
Expand All @@ -26,7 +26,7 @@ export function Assets(): JSX.Element {
) : (
<table className="w-full">
<tbody>
{assets.map((asset) => (
{cleanedAssets.map((asset) => (
<tr key={asset.path} className="even:bg-gray-700 hover:bg-gray-900">
<td onClick={() => openAsset(asset.path)} className="hover:underline cursor-pointer">
{asset.path}
Expand Down
21 changes: 17 additions & 4 deletions frontend/src/scenes/frame/panels/Assets/assetsLogic.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { actions, afterMount, connect, kea, key, path, props, reducers } from 'kea'
import { actions, afterMount, connect, kea, key, path, props, reducers, selectors } from 'kea'

import { AssetType } from '../../../../types'
import { loaders } from 'kea-loaders'
import { socketLogic } from '../../../socketLogic'

import type { assetsLogicType } from './assetsLogicType'
import { frameLogic } from '../../frameLogic'

export interface assetsLogicProps {
export interface AssetsLogicProps {
frameId: number
}

export const assetsLogic = kea<assetsLogicType>([
path(['src', 'scenes', 'frame', 'assetsLogic']),
props({} as assetsLogicProps),
connect({ logic: [socketLogic] }),
props({} as AssetsLogicProps),
connect(({ frameId }: AssetsLogicProps) => ({ logic: [socketLogic], values: [frameLogic({ frameId }), ['frame']] })),
key((props) => props.frameId),
loaders(({ props }) => ({
assets: [
Expand All @@ -35,6 +36,18 @@ export const assetsLogic = kea<assetsLogicType>([
},
],
})),
selectors({
cleanedAssets: [
(s) => [s.assets, s.frame],
(assets, frame) => {
const assetsPath = frame.assets_path ?? '/srv/assets'
return assets.map((asset) => ({
...asset,
path: asset.path.startsWith(assetsPath + '/') ? asset.path.substring(assetsPath.length + 1) : asset.path,
}))
},
],
}),
afterMount(({ actions, cache }) => {
actions.loadAssets()
}),
Expand Down

0 comments on commit 03d5dba

Please sign in to comment.