Skip to content

Commit

Permalink
Move an item to bottom of the list (#141)
Browse files Browse the repository at this point in the history
* docs(contributor): contrib-readme-action has updated readme

* Move item to bottom of list

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
cj13579 and github-actions[bot] authored Sep 28, 2024
1 parent c0c6479 commit 69ea252
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 20 deletions.
31 changes: 12 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ Hi, I'm Wingy. I made this app. My website is [samwing.dev](https://samwing.dev)
<table>
<tr>
<td align="center">
<a href="https://github.com/Wingysam">
<img src="https://avatars.githubusercontent.com/u/18403742?v=4" width="100;" alt="Wingysam"/>
<a href="https://github.com/cj13579">
<img src="https://avatars.githubusercontent.com/u/1965454?v=4" width="100;" alt="cj13579"/>
<br />
<sub><b>Wingysam</b></sub>
<sub><b>cj13579</b></sub>
</a>
</td></tr>
</table>
Expand Down Expand Up @@ -191,13 +191,6 @@ Hi, I'm Wingy. I made this app. My website is [samwing.dev](https://samwing.dev)
<sub><b>cj13579</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/frostyfrog">
<img src="https://avatars.githubusercontent.com/u/509363?v=4" width="100;" alt="frostyfrog"/>
<br />
<sub><b>frostyfrog</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/dbarenholz">
<img src="https://avatars.githubusercontent.com/u/25849034?v=4" width="100;" alt="dbarenholz"/>
Expand All @@ -211,15 +204,15 @@ Hi, I'm Wingy. I made this app. My website is [samwing.dev](https://samwing.dev)
<br />
<sub><b>Laeborg</b></sub>
</a>
</td></tr>
<tr>
</td>
<td align="center">
<a href="https://github.com/LarsStegman">
<img src="https://avatars.githubusercontent.com/u/9332816?v=4" width="100;" alt="LarsStegman"/>
<br />
<sub><b>LarsStegman</b></sub>
</a>
</td>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/BootVirtual">
<img src="https://avatars.githubusercontent.com/u/64020530?v=4" width="100;" alt="BootVirtual"/>
Expand Down Expand Up @@ -254,15 +247,15 @@ Hi, I'm Wingy. I made this app. My website is [samwing.dev](https://samwing.dev)
<br />
<sub><b>Na0mir</b></sub>
</a>
</td></tr>
<tr>
</td>
<td align="center">
<a href="https://github.com/ndlanier">
<img src="https://avatars.githubusercontent.com/u/14913926?v=4" width="100;" alt="ndlanier"/>
<br />
<sub><b>ndlanier</b></sub>
</a>
</td>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/RestartFU">
<img src="https://avatars.githubusercontent.com/u/45609733?v=4" width="100;" alt="RestartFU"/>
Expand Down Expand Up @@ -297,15 +290,15 @@ Hi, I'm Wingy. I made this app. My website is [samwing.dev](https://samwing.dev)
<br />
<sub><b>StS82</b></sub>
</a>
</td></tr>
<tr>
</td>
<td align="center">
<a href="https://github.com/jskiddie">
<img src="https://avatars.githubusercontent.com/u/153759737?v=4" width="100;" alt="jskiddie"/>
<br />
<sub><b>jskiddie</b></sub>
</a>
</td>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/toastie89">
<img src="https://avatars.githubusercontent.com/u/19393929?v=4" width="100;" alt="toastie89"/>
Expand Down
2 changes: 2 additions & 0 deletions src/languages/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,11 @@ export const strings = {
WISHLIST_IMAGE: 'Image',
WISHLIST_ITEM_MISSING: 'Failed to find item',
WISHLIST_MOVE_DOWN: 'Move Down',
WISHLIST_MOVE_BOTTOM: 'Move Bottom',
WISHLIST_MOVE_GUARD: 'Not correct user',
WISHLIST_MOVE_INVALID: 'Invalid move',
WISHLIST_MOVE_ITEM_DOWN: 'Move Item Down',
WISHLIST_MOVE_ITEM_BOTTOM: 'Move Item Bottom',
WISHLIST_MOVE_ITEM_TOP: 'Move Item Top',
WISHLIST_MOVE_ITEM_UP: 'Move Item Up',
WISHLIST_MOVE_SUCCESS: 'Successfully moved item!',
Expand Down
4 changes: 3 additions & 1 deletion src/routes/wishlist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ export default function (db) {

if (req.params.direction === 'top') {
await wishlist.moveTop(req.params.itemId)
} else if (req.params.direction === 'up') {
} else if (req.params.direction === 'bottom') {
await wishlist.moveBottom(req.params.itemId)
}else if (req.params.direction === 'up') {
await wishlist.move(req.params.itemId, -1)
} else if (req.params.direction === 'down') {
await wishlist.move(req.params.itemId, 1)
Expand Down
9 changes: 9 additions & 0 deletions src/structures/Wishlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ export class Wishlist {
await this.save()
}

async moveBottom (id) {
const index = this.items.findIndex(item => item.id === id)
if (index === -1) throw new Error(_CC.lang('WISHLIST_ITEM_MISSING'))

const item = this.items.splice(index, 1)[0]
this.items.push(item)
await this.save()
}

async setItemData (id, data) {
const item = await this.get(id)

Expand Down
17 changes: 17 additions & 0 deletions src/views/wishlist.pug
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ block content
th= lang('WISHLIST_MOVE_TOP')
th= lang('WISHLIST_MOVE_UP')
th= lang('WISHLIST_MOVE_DOWN')
th= lang('WISHLIST_MOVE_BOTTOM')
else
th= lang('WISHLIST_PLEDGE')
th= lang('WISHLIST_DELETE')
Expand Down Expand Up @@ -129,6 +130,17 @@ block content
)
span.icon
i.fas.fa-arrow-down
td(data-label=lang('WISHLIST_MOVE_ITEM_BOTTOM'))
form.bottomForm.inline(method='POST', action=`${_CC.config.base}wishlist/${req.params.user}/move/bottom/${item.id}`)
.field.inline
.control.inline
button.button.is-text(
type='submit',
style='text-decoration: none;',
disabled=index === items.length - 1
)
span.icon
i.fas.fa-angle-double-down
else
td(data-label=lang('WISHLIST_PLEDGE'))
if req.params.user !== req.user._id && !item.pledgedBy
Expand Down Expand Up @@ -238,6 +250,11 @@ block content
.field.inline
.control.inline
input.inline.button(type='submit' value=lang('WISHLIST_MOVE_ITEM_DOWN'))
if index !== items.length - 1 && req.user._id === req.params.user
form.inline(method='POST', action=`${_CC.config.base}wishlist/${req.params.user}/move/bottom/${item.id}`)
.field.inline
.control.inline
input.inline.button(type='submit' value=lang('WISHLIST_MOVE_ITEM_BOTTOM'))
form(method='POST')
.field
label.label!=lang('WISHLIST_URL_LABEL')
Expand Down

0 comments on commit 69ea252

Please sign in to comment.