Skip to content

Commit

Permalink
put our node back in the original list to avoid it showing when for o…
Browse files Browse the repository at this point in the history
…ther search results
  • Loading branch information
liamcottle committed Nov 17, 2024
1 parent 77a6092 commit 200616d
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/components/nodes/NodesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@

<!-- nodes -->
<div class="h-full overflow-y-auto">

<!-- always show connected node first -->
<NodeListItem v-if="myNode" :key="myNode.num" :node="myNode" @click="onNodeClick(myNode)" class="border-b"/>

<!-- other nodes -->
<NodeListItem :key="node.num" v-for="node of searchedNodes" :node="node" @click="onNodeClick(node)"/>

</div>

</div>
Expand Down Expand Up @@ -53,30 +47,38 @@ export default {
GlobalState() {
return GlobalState;
},
myNode() {
return this.nodes.find((node) => {
orderedNodes() {
// get ordered nodes
var orderedNodes = this.nodesOrderedByLastHeard;
// find our node in the list
const myNode = orderedNodes.find((node) => {
return node.num === GlobalState.myNodeId;
});
},
otherNodes() {
return this.nodes.filter((node) => {
// remove our node from the list
orderedNodes = orderedNodes.filter((node) => {
return node.num !== GlobalState.myNodeId;
});
},
orderedNodes() {
return this.nodesOrderedByLastHeard;
// add our node to the start of the list
orderedNodes.unshift(myNode);
return orderedNodes;
},
nodesOrderedByName() {
// sort nodes by name asc
return this.otherNodes.sort((nodeA, nodeB) => {
// sort nodes by name asc (using a shallow copy to ensure it updates automatically)
return [...this.nodes].sort((nodeA, nodeB) => {
const nodeALongName = this.getNodeLongName(nodeA.num);
const nodeBLongName = this.getNodeLongName(nodeB.num);
return nodeALongName.localeCompare(nodeBLongName);
});
},
nodesOrderedByLastHeard() {
// sort nodes by last heard desc
return this.otherNodes.sort((nodeA, nodeB) => {
// sort nodes by last heard desc (using a shallow copy to ensure it updates automatically)
return [...this.nodes].sort((nodeA, nodeB) => {
const nodeALastHeard = nodeA.lastHeard;
const nodeBLastHeard = nodeB.lastHeard;
return nodeBLastHeard - nodeALastHeard;
Expand Down

0 comments on commit 200616d

Please sign in to comment.