Skip to content

Commit

Permalink
fix typeDefs and fragments, better naming, decluttering
Browse files Browse the repository at this point in the history
  • Loading branch information
Soxasora committed Feb 19, 2025
1 parent b689eac commit d8aa1ea
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions api/typeDefs/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default gql`
uploadId: Int
pollCost: Int
deletedAt: Date
originalItemId: Int
}
type Comments {
Expand Down
28 changes: 23 additions & 5 deletions components/item-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@ export function OldItem ({ version }) {
)
}

export default function HistoryDropdownItem ({ item }) {
export default function HistoryDropdown ({ item }) {
const router = useRouter()
const showModal = useShowModal()

const lastEdited = new Date(item.oldVersions[0].cloneDiedAt)

// TODO: overengineering? not handling it just closes the modal
/* const handleLastEdit = () => {
if (!item.parentId) {
router.replace(`/items/${item.id}`)
} else {
router.replace(`/items/${item.parentId}/?commentId=${item.id}`)
}
} */

return (
<Dropdown className='pointer' as='span'>
<Dropdown.Toggle as='span' onPointerDown={e => e.preventDefault()}>
Expand All @@ -33,11 +44,18 @@ export default function HistoryDropdownItem ({ item }) {
edited {item.oldVersions.length} times
</Dropdown.Header>
<hr className='dropdown-divider' />
<Dropdown.Item title={item.oldVersions[0].cloneDiedAt} onClick={() => router.push(`/items/${item.id}`)}>
edited {timeSince(new Date(item.oldVersions[0].cloneDiedAt))} ago (most recent)
<Dropdown.Item
title={lastEdited}
// onClick={handleLastEdit}
>
edited {timeSince(lastEdited)} ago (most recent)
</Dropdown.Item>
{item.oldVersions.map((version) => ( // TODO: prettier
<Dropdown.Item key={version.id} title={version.cloneBornAt} onClick={() => showModal((onClose) => <OldItem version={version} onClose={onClose} />)}>
{item.oldVersions.map((version) => (
<Dropdown.Item
key={version.id}
title={version.cloneBornAt}
onClick={() => showModal((onClose) => <OldItem version={version} onClose={onClose} />)}
>
{!version.cloneBornAt ? 'created' : 'edited'} {timeSince(new Date(version.cloneBornAt || version.createdAt))} ago
</Dropdown.Item>
))}
Expand Down
4 changes: 2 additions & 2 deletions components/item-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { useShowModal } from './modal'
import classNames from 'classnames'
import SubPopover from './sub-popover'
import useCanShadowEdit from './use-can-edit'
import HistoryDropdownItem from './item-history'
import HistoryDropdown from './item-history'

function itemTitle (item) {
let title = ''
Expand Down Expand Up @@ -149,7 +149,7 @@ export default function ItemInfo ({
{item.oldVersions?.length > 0 && !item.deletedAt &&
<>
<span> </span>
<HistoryDropdownItem item={item} />
<HistoryDropdown item={item} />
</>}
</span>
{item.subName &&
Expand Down
1 change: 1 addition & 0 deletions fragments/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const COMMENT_FIELDS = gql`
uploadId
pollCost
deletedAt
originalItemId
}
rel
apiKey
Expand Down
1 change: 1 addition & 0 deletions fragments/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const ITEM_FIELDS = gql`
uploadId
pollCost
deletedAt
originalItemId
}
rel
apiKey
Expand Down

0 comments on commit d8aa1ea

Please sign in to comment.