-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #581 from danactive/danactive/walk
Admin Walk
- Loading branch information
Showing
14 changed files
with
975 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import '@testing-library/jest-dom' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { List, ListDivider, ListItem } from '@mui/joy' | ||
import { useRouter } from 'next/router' | ||
import { Fragment, useEffect, useState } from 'react' | ||
|
||
import ListFile from '../../src/components/Walk/ListFile' | ||
import type { Filesystem, FilesystemBody } from '../../src/lib/filesystems' | ||
import { | ||
addParentDirectoryNav, | ||
isImage, | ||
organizeByMedia, | ||
parseHash, | ||
} from '../../src/utils/walk' | ||
|
||
type ItemFile = Partial<Filesystem> & { | ||
id: Filesystem['id']; | ||
path: Filesystem['path']; | ||
label: string; | ||
grouped?: string; | ||
flat?: string; | ||
} | ||
|
||
function WalkPage() { | ||
const { asPath } = useRouter() | ||
const [data, setData] = useState<FilesystemBody | null>(null) | ||
const [isLoading, setLoading] = useState(false) | ||
const pathQs = parseHash('path', asPath) | ||
|
||
useEffect(() => { | ||
setLoading(true) | ||
fetch(`/api/admin/filesystems?path=${pathQs ?? '/'}`) | ||
.then((response) => response.json()) | ||
.then((result: FilesystemBody) => { | ||
setData(result) | ||
setLoading(false) | ||
}) | ||
}, [asPath]) | ||
|
||
if (isLoading) return <p>Loading...</p> | ||
if (!data) return <p>No filesystem data</p> | ||
|
||
const itemImages = data.files.filter((file) => isImage(file)) | ||
const hasImages = !isLoading && itemImages.length > 0 | ||
const fsItems = addParentDirectoryNav(organizeByMedia(data.files), pathQs) | ||
|
||
return ( | ||
<> | ||
<List> | ||
{fsItems.map((item, i) => ( | ||
<Fragment key={item.id}> | ||
{i > 0 && <ListDivider />} | ||
<ListFile item={item} /> | ||
</Fragment> | ||
))} | ||
</List> | ||
{hasImages && (<div>TODO display OrganizeThumbs</div>)} | ||
</> | ||
) | ||
} | ||
|
||
export { type ItemFile } | ||
export default WalkPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ListItem } from '@mui/joy' | ||
|
||
import { type ItemFile } from '../../../pages/admin/walk' | ||
import Link from '../Link' | ||
|
||
function ListFile({ item: file }: { item: ItemFile }) { | ||
if (file.mediumType === 'folder') { | ||
const href = file.path ? `#path=${file.path}` : '' | ||
return ( | ||
<ListItem> | ||
<Link href={href}>{file.label}</Link> | ||
</ListItem> | ||
) | ||
} | ||
|
||
return <ListItem>{file.label}</ListItem> | ||
} | ||
|
||
export default ListFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { render } from '@testing-library/react' | ||
|
||
import ListFile from '../ListFile' | ||
import { type ItemFile } from '../../../../pages/admin/walk' | ||
|
||
describe('<ListFile />', () => { | ||
const mockItemFile: ItemFile = { | ||
id: '123', | ||
label: 'One Two Three', | ||
path: '123', | ||
} | ||
test('should render file label', () => { | ||
const label = 'label' | ||
const { getByText } = render(<ListFile item={{ ...mockItemFile, label }} />) | ||
expect(getByText(label)).toBeInTheDocument() | ||
}) | ||
test('should render a folder with path', () => { | ||
const path = 'testPath' | ||
const label = 'Link text' | ||
const { getByText } = render(<ListFile | ||
item={{ | ||
...mockItemFile, | ||
mediumType: 'folder', | ||
path, | ||
label, | ||
}} | ||
/>) | ||
expect(getByText(label).closest('a')?.href).toBe(`http://localhost/#path=${path}`) | ||
}) | ||
test('should render a folder with path', () => { | ||
const path = '' | ||
const label = 'Link text' | ||
const { getByText } = render(<ListFile | ||
item={{ | ||
...mockItemFile, | ||
mediumType: 'folder', | ||
path, | ||
label, | ||
}} | ||
/>) | ||
expect(getByText(label).closest('a')?.href).toBe('http://localhost/') | ||
}) | ||
}) |
Oops, something went wrong.
de5dac0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
history – ./
history-git-main-danactive.vercel.app
history-danactive.vercel.app
history.domaindesign.ca