You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
3.0 KiB
96 lines
3.0 KiB
const {logHeaderApi} = require("../../../../../rpdata/api/LogHeader")
|
|
|
|
module.exports = class {
|
|
onCreate(input) {
|
|
this.state = {
|
|
id: input.log.id,
|
|
channelName: input.log.channelName,
|
|
eventName: input.log.eventName,
|
|
nexts: [],
|
|
prevs: [],
|
|
loaded: false,
|
|
error: null,
|
|
}
|
|
}
|
|
|
|
onMount() {
|
|
this.timeout = setTimeout(() => {
|
|
logHeaderApi.list().then(logs => {
|
|
const index = logs.findIndex(l => l.id === this.state.id);
|
|
if (index === -1) {
|
|
return Promise.reject("This log not found in list.")
|
|
}
|
|
const log = logs[index]
|
|
const characterIds = log.characters.map(c => c.id);
|
|
const nexts = []
|
|
const prevs = []
|
|
let foundGroups = {}
|
|
let foundChannel = false
|
|
|
|
for (let i = index - 1; i >= 0; --i) {
|
|
const log2 = logs[i]
|
|
const hasEvent = (log.eventName ? log.eventName === log2.eventName : false)
|
|
const hasChannel = (log.channelName === log2.channelName)
|
|
|
|
const characters = log2.findCharacters(...characterIds)
|
|
const characterIdsKey = characters.map(c => c.id).sort().join(",")
|
|
|
|
const suggestion = {log: log2, characters, hasEvent, hasChannel}
|
|
|
|
if (hasChannel && !foundChannel) {
|
|
foundChannel = true
|
|
foundGroups[characterIdsKey] = true
|
|
|
|
nexts.push(suggestion)
|
|
} else if (hasEvent) {
|
|
foundGroups[characterIdsKey] = true
|
|
|
|
nexts.push(suggestion)
|
|
} else if (nexts.length < 8 && !hasEvent && characters.length > 1 && !foundGroups[characterIdsKey]) {
|
|
foundGroups[characterIdsKey] = true
|
|
nexts.push(suggestion)
|
|
}
|
|
}
|
|
|
|
foundGroups = {}
|
|
foundChannel = false
|
|
|
|
for (let i = index + 1; i < logs.length; ++i) {
|
|
const log2 = logs[i]
|
|
const hasEvent = (log.eventName ? log.eventName === log2.eventName : false)
|
|
const hasChannel = (log.channelName === log2.channelName)
|
|
|
|
const characters = log2.findCharacters(...characterIds)
|
|
const characterIdsKey = characters.map(c => c.id).sort().join(",")
|
|
|
|
const suggestion = {log: log2, characters, hasEvent, hasChannel}
|
|
|
|
if (hasChannel && !foundChannel) {
|
|
foundChannel = true
|
|
foundGroups[characterIdsKey] = true
|
|
|
|
prevs.push(suggestion)
|
|
} else if (hasEvent) {
|
|
foundGroups[characterIdsKey] = true
|
|
|
|
prevs.push(suggestion)
|
|
} else if (prevs.length < 8 && !hasEvent && characters.length > 1 && !foundGroups[characterIdsKey]) {
|
|
foundGroups[characterIdsKey] = true
|
|
prevs.push(suggestion)
|
|
}
|
|
}
|
|
|
|
this.state.nexts = nexts;
|
|
this.state.prevs = prevs;
|
|
this.state.loaded = true;
|
|
}).catch(err => {
|
|
console.warn("Suggestions load error:", err)
|
|
this.suggestionsError = "Failed to load suggestions: " + err.toString()
|
|
})
|
|
}, 1000)
|
|
}
|
|
|
|
onUnmount() {
|
|
clearTimeout(this.timeout)
|
|
}
|
|
}
|