@playpilot/tpi 5.27.1 → 5.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/link-injections.js +8 -8
- package/package.json +1 -1
- package/src/routes/components/Debugger.svelte +1 -3
- package/src/routes/components/Editorial/AIIndicator.svelte +1 -1
- package/src/routes/components/Editorial/Editor.svelte +1 -8
- package/src/routes/components/Editorial/ManualInjection.svelte +1 -1
- package/src/routes/components/Editorial/Search/TitleSearch.svelte +1 -1
- package/src/routes/components/Editorial/TextInput.svelte +1 -1
- package/src/routes/components/Rails/ParticipantsRail.svelte +28 -1
- package/src/tests/routes/components/Rails/ParticipantsRail.test.js +18 -2
package/package.json
CHANGED
|
@@ -38,9 +38,7 @@
|
|
|
38
38
|
function onkeydown(event: KeyboardEvent): void {
|
|
39
39
|
if (shown) return
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
lastInputs.push(key)
|
|
41
|
+
lastInputs.push(event.key)
|
|
44
42
|
|
|
45
43
|
// Check all secrets. Both "tpidebug" and "debugtpi" are accepted because remembering is hard.
|
|
46
44
|
// It's checked by comparing the last inputs to each secret.
|
|
@@ -239,14 +239,7 @@
|
|
|
239
239
|
</section>
|
|
240
240
|
|
|
241
241
|
<style lang="scss">
|
|
242
|
-
@use "lib/scss/_theme";
|
|
243
|
-
|
|
244
242
|
.editor {
|
|
245
|
-
// Reset any possible theme overrides back to their defaults
|
|
246
|
-
@each $name, $value in theme.$variables {
|
|
247
|
-
--playpilot-#{$name}: #{$value};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
243
|
z-index: 2147483646; // 1 less than as high as she goes;
|
|
251
244
|
display: flex;
|
|
252
245
|
flex-direction: column;
|
|
@@ -375,7 +368,7 @@
|
|
|
375
368
|
|
|
376
369
|
&[disabled] {
|
|
377
370
|
opacity: 0.75;
|
|
378
|
-
background: theme(
|
|
371
|
+
background: theme(lighter);
|
|
379
372
|
color: theme(content-light);
|
|
380
373
|
}
|
|
381
374
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { fetchParticipantsForTitle } from '$lib/api/participants'
|
|
3
3
|
import { TrackingEvent } from '$lib/enums/TrackingEvent'
|
|
4
|
+
import { getLinkInjectionElements, getLinkInjectionsParentElement, getPageText } from '$lib/injection'
|
|
4
5
|
import { openModal } from '$lib/modal'
|
|
6
|
+
import { cleanPhrase, findNumberOfMatchesInString } from '$lib/text'
|
|
5
7
|
import { track } from '$lib/tracking'
|
|
6
8
|
import type { ParticipantData } from '$lib/types/participant'
|
|
7
9
|
import type { TitleData } from '$lib/types/title'
|
|
@@ -13,6 +15,31 @@
|
|
|
13
15
|
|
|
14
16
|
const { title }: Props = $props()
|
|
15
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Order participants by how often their name appears in an the page text. This only takes into account
|
|
20
|
+
* their full name. If an actor is mentioned by first name only, which is often the case, they won't get
|
|
21
|
+
* boosted. Often times if an actor is mentioned at least once, their full name will be somewhere in the
|
|
22
|
+
* page text, so the goal is still the same; to list participants that are mentioned in the page text before
|
|
23
|
+
* other participants.
|
|
24
|
+
*/
|
|
25
|
+
function orderParticipantsByPageTextOccurrence(participants: ParticipantData[]): ParticipantData[] {
|
|
26
|
+
const pageText = cleanPhrase(getPageText(getLinkInjectionElements(getLinkInjectionsParentElement())))
|
|
27
|
+
|
|
28
|
+
// Create a new object with all participants by their sid with the number of times their names appear in the page text
|
|
29
|
+
const participantsByOccurrence: Record<string, { participant: ParticipantData, count: number }> = {}
|
|
30
|
+
for(const participant of participants) {
|
|
31
|
+
const count = findNumberOfMatchesInString(pageText, cleanPhrase(participant.name))
|
|
32
|
+
|
|
33
|
+
participantsByOccurrence[participant.sid] = { participant, count }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Sort all participants by their occurrences. If a participant did not occur their positioned will be retained
|
|
37
|
+
// relative to where it was before
|
|
38
|
+
const participantsSortedByCount = Object.values(participantsByOccurrence).sort((a, b) => b.count - a.count)
|
|
39
|
+
|
|
40
|
+
return participantsSortedByCount.map(({ participant }) => participant)
|
|
41
|
+
}
|
|
42
|
+
|
|
16
43
|
function onclick(event: MouseEvent, participant: ParticipantData): void {
|
|
17
44
|
openModal({ event, type: 'participant', data: participant })
|
|
18
45
|
track(TrackingEvent.ParticipantClick, null, { title_source: title.original_title, participant: participant.name })
|
|
@@ -28,7 +55,7 @@
|
|
|
28
55
|
{:then participants}
|
|
29
56
|
{#if participants?.length}
|
|
30
57
|
<Rail heading="Cast">
|
|
31
|
-
{#each participants.slice(0, 15) as participant}
|
|
58
|
+
{#each orderParticipantsByPageTextOccurrence(participants).slice(0, 15) as participant}
|
|
32
59
|
<button class="participant" data-testid="participant" onclick={event => onclick(event, participant)}>
|
|
33
60
|
<span class="truncate">{participant.name}</span>
|
|
34
61
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fireEvent, render, waitFor } from '@testing-library/svelte'
|
|
2
|
-
import {
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
4
|
import ParticipantsRail from '../../../../routes/components/Rails/ParticipantsRail.svelte'
|
|
5
5
|
import { openModal } from '$lib/modal'
|
|
@@ -21,10 +21,13 @@ vi.mock('$lib/api/participants', () => ({
|
|
|
21
21
|
}))
|
|
22
22
|
|
|
23
23
|
describe('ParticipantsRail.svelte', () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
document.body.innerHTML = ''
|
|
26
|
+
})
|
|
27
|
+
|
|
24
28
|
it('Should render each given participant', async () => {
|
|
25
29
|
vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
|
|
26
30
|
|
|
27
|
-
// @ts-ignore
|
|
28
31
|
const { getByText } = render(ParticipantsRail, { title })
|
|
29
32
|
|
|
30
33
|
await waitFor(() => {
|
|
@@ -33,6 +36,19 @@ describe('ParticipantsRail.svelte', () => {
|
|
|
33
36
|
})
|
|
34
37
|
})
|
|
35
38
|
|
|
39
|
+
it('Should order participants by their number of occurrences on the page', async () => {
|
|
40
|
+
document.body.innerHTML = `<main>${participants[1].name}. ${participants[2].name}, ${participants[2].name}</main>`
|
|
41
|
+
vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
|
|
42
|
+
|
|
43
|
+
const { getAllByTestId } = render(ParticipantsRail, { title })
|
|
44
|
+
|
|
45
|
+
await waitFor(() => {
|
|
46
|
+
expect(getAllByTestId('participant')[0].innerText).toContain(participants[2].name)
|
|
47
|
+
expect(getAllByTestId('participant')[1].innerText).toContain(participants[1].name)
|
|
48
|
+
expect(getAllByTestId('participant')[2].innerText).toContain(participants[0].name)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
|
|
36
52
|
it('Should not render when no participants are returned', async () => {
|
|
37
53
|
vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce([])
|
|
38
54
|
|