mirror of
https://github.com/discourse/discourse.git
synced 2025-04-27 16:24:28 +08:00
refactor
This commit is contained in:
parent
37c7d23011
commit
9622785e0e
@ -0,0 +1,39 @@
|
|||||||
|
export function getNext(list, currentIdentifier = null) {
|
||||||
|
if (list.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
list = list.filterBy("enabled");
|
||||||
|
|
||||||
|
if (currentIdentifier) {
|
||||||
|
const currentIndex = list.mapBy("identifier").indexOf(currentIdentifier);
|
||||||
|
|
||||||
|
if (currentIndex < list.length - 1) {
|
||||||
|
return list.objectAt(currentIndex + 1);
|
||||||
|
} else {
|
||||||
|
return list[0];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return list[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPrevious(list, currentIdentifier = null) {
|
||||||
|
if (list.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
list = list.filterBy("enabled");
|
||||||
|
|
||||||
|
if (currentIdentifier) {
|
||||||
|
const currentIndex = list.mapBy("identifier").indexOf(currentIdentifier);
|
||||||
|
|
||||||
|
if (currentIndex > 0) {
|
||||||
|
return list.objectAt(currentIndex - 1);
|
||||||
|
} else {
|
||||||
|
return list.objectAt(list.length - 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return list.objectAt(list.length - 1);
|
||||||
|
}
|
||||||
|
}
|
@ -20,46 +20,6 @@ export default class List extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#getNext(list, currentIdentifier = null) {
|
|
||||||
if (list.length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
list = list.filterBy("enabled");
|
|
||||||
|
|
||||||
if (currentIdentifier) {
|
|
||||||
const currentIndex = list.mapBy("identifier").indexOf(currentIdentifier);
|
|
||||||
|
|
||||||
if (currentIndex < list.length - 1) {
|
|
||||||
return list.objectAt(currentIndex + 1);
|
|
||||||
} else {
|
|
||||||
return list[0];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return list[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#getPrevious(list, currentIdentifier = null) {
|
|
||||||
if (list.length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
list = list.filterBy("enabled");
|
|
||||||
|
|
||||||
if (currentIdentifier) {
|
|
||||||
const currentIndex = list.mapBy("identifier").indexOf(currentIdentifier);
|
|
||||||
|
|
||||||
if (currentIndex > 0) {
|
|
||||||
return list.objectAt(currentIndex - 1);
|
|
||||||
} else {
|
|
||||||
return list.objectAt(list.length - 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return list.objectAt(list.length - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
handleEnter(item, event) {
|
handleEnter(item, event) {
|
||||||
if (event.key !== "Enter") {
|
if (event.key !== "Enter") {
|
||||||
|
@ -5,6 +5,7 @@ import { action } from "@ember/object";
|
|||||||
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
|
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
|
||||||
import icon from "discourse-common/helpers/d-icon";
|
import icon from "discourse-common/helpers/d-icon";
|
||||||
import eq from "truth-helpers/helpers/eq";
|
import eq from "truth-helpers/helpers/eq";
|
||||||
|
import { getNext, getPrevious } from "./lib/iterate-list";
|
||||||
import Member from "./member";
|
import Member from "./member";
|
||||||
|
|
||||||
export default class members extends Component {
|
export default class members extends Component {
|
||||||
@ -38,7 +39,7 @@ export default class members extends Component {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
this.args.onHighlightMember(
|
this.args.onHighlightMember(
|
||||||
this.#getPrevious(this.args.members, this.args.highlightedMember)
|
getPrevious(this.args.members, this.args.highlightedMember)
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -48,7 +49,7 @@ export default class members extends Component {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
this.args.onHighlightMember(
|
this.args.onHighlightMember(
|
||||||
this.#getNext(this.args.members, this.args.highlightedMember)
|
getNext(this.args.members, this.args.highlightedMember)
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -66,50 +67,6 @@ export default class members extends Component {
|
|||||||
this.highlightedMember = null;
|
this.highlightedMember = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
#getNext(list, current = null) {
|
|
||||||
if (list.length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
list = list.filterBy("enabled");
|
|
||||||
|
|
||||||
if (current?.identifier) {
|
|
||||||
const currentIndex = list
|
|
||||||
.mapBy("identifier")
|
|
||||||
.indexOf(current?.identifier);
|
|
||||||
|
|
||||||
if (currentIndex < list.length - 1) {
|
|
||||||
return list.objectAt(currentIndex + 1);
|
|
||||||
} else {
|
|
||||||
return list[0];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return list[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#getPrevious(list, current = null) {
|
|
||||||
if (list.length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
list = list.filterBy("enabled");
|
|
||||||
|
|
||||||
if (current?.identifier) {
|
|
||||||
const currentIndex = list
|
|
||||||
.mapBy("identifier")
|
|
||||||
.indexOf(current?.identifier);
|
|
||||||
|
|
||||||
if (currentIndex > 0) {
|
|
||||||
return list.objectAt(currentIndex - 1);
|
|
||||||
} else {
|
|
||||||
return list.objectAt(list.length - 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return list.objectAt(list.length - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="chat-message-creator__members-container">
|
<div class="chat-message-creator__members-container">
|
||||||
<div class="chat-message-creator__members">
|
<div class="chat-message-creator__members">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user