Skip to content

Commit

Permalink
feat(Next > Organize Previews > Rename): Allow todo photos to be renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
danactive committed Oct 29, 2023
1 parent e5da75e commit 3d3a680
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
2 changes: 1 addition & 1 deletion next/pages/admin/walk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function WalkPage() {
))}
</List>
{hasImages && (
<OrganizePreviews setItems={setPreviewList} items={previewList} />
<OrganizePreviews setItems={setPreviewList} items={previewList} />
)}
</>
)
Expand Down
45 changes: 45 additions & 0 deletions next/src/components/OrganizePreviews/ActionButtons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Button from '@mui/joy/Button'
import { useRouter } from 'next/router'

import type { Filesystem } from '../../lib/filesystems'
import { parseHash } from '../../utils/walk'

export default function ActionButtons(
{ items }:
{ items: Filesystem[] },
) {
const { asPath } = useRouter()
const pathQs = parseHash('path', asPath)
const path = pathQs ?? '/'
function rename() {
// eslint-disable-next-line no-alert
const date = window.prompt('Date of images (YYYY-MM-DD)?')
// TODO POST http://localhost:8000/admin/rename

const postBody = {
filenames: items.map((i) => i.filename),
prefix: date,
source_folder: path,
preview: false,
raw: true,
rename_associated: true,
}

const options = {
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
body: JSON.stringify(postBody),
};
/*
curl -d '{"filenames":["a.jpg","b.jpg"], "prefix": "2020-06-13",
"source_folder": "/todo/doit", "preview": "false", "raw": "true", "rename_associated": "true"}'
-i http://127.0.0.1:8000/admin/rename -H "Content-Type: application/json"
*/

return fetch('/api/admin/rename', options).then((s) => console.log(s))
}

return <div><Button onClick={() => rename()}>Rename</Button></div>
}
14 changes: 9 additions & 5 deletions next/src/components/OrganizePreviews/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import styled from 'styled-components'

import type { Filesystem } from '../../lib/filesystems'
import { groupIntoColumns, reorderOnRelease } from '../../utils/preview'
import ActionButtons from './ActionButtons'
import PreviewColumn from './PreviewColumn'

const grid = 4
Expand Down Expand Up @@ -52,10 +53,13 @@ export default function OrganizePreviews(
)

return (
<DragDropContext onDragEnd={({ source, destination }) => onDragEnd({ source, destination })}>
<HorizontalScrollContainer>
{columnItems.map(makeColumn)}
</HorizontalScrollContainer>
</DragDropContext>
<>
<ActionButtons items={items} />
<DragDropContext onDragEnd={({ source, destination }) => onDragEnd({ source, destination })}>
<HorizontalScrollContainer>
{columnItems.map(makeColumn)}
</HorizontalScrollContainer>
</DragDropContext>
</>
)
}
2 changes: 1 addition & 1 deletion next/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const removeUndefinedFields = <T>(obj: T): T => Object.keys(obj as object
)

export function isNotEmpty(value: unknown): value is string {
if (typeof value !== 'undefined' || value !== null || value !== '') {
if (typeof value !== 'undefined' && value !== null && value !== '' && value !== undefined) {
return true
}
return false
Expand Down

0 comments on commit 3d3a680

Please sign in to comment.