-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom Show Programming Picker - next steps
- Loading branch information
1 parent
7722091
commit ae1e1e0
Showing
16 changed files
with
607 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 144 additions & 1 deletion
145
web/src/components/channel_config/CustomShowProgrammingSelector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,146 @@ | ||
import { | ||
Box, | ||
Button, | ||
Divider, | ||
LinearProgress, | ||
List, | ||
ListItem, | ||
ListItemText, | ||
} from '@mui/material'; | ||
import { ContentProgram, isContentProgram } from '@tunarr/types'; | ||
import dayjs from 'dayjs'; | ||
import duration from 'dayjs/plugin/duration'; | ||
import { chain, isEmpty, isNil, property } from 'lodash-es'; | ||
import { MouseEvent, useCallback, useState } from 'react'; | ||
import { useIntersectionObserver } from 'usehooks-ts'; | ||
import { forProgramType } from '../../helpers/util'; | ||
import { useCustomShow } from '../../hooks/useCustomShows'; | ||
import useStore from '../../store'; | ||
import { addSelectedMedia } from '../../store/programmingSelector/actions'; | ||
|
||
dayjs.extend(duration); | ||
|
||
export function CustomShowProgrammingSelector() { | ||
return <div></div>; | ||
const selectedCustomShow = useStore((s) => | ||
s.currentLibrary?.type === 'custom-show' ? s.currentLibrary : null, | ||
); | ||
const viewType = useStore((state) => state.theme.programmingSelectorView); | ||
const [scrollParams, setScrollParams] = useState({ limit: 0, max: -1 }); | ||
|
||
const [showResult, programsResult] = useCustomShow( | ||
/*id=*/ selectedCustomShow?.library.id ?? '', | ||
/*enabled=*/ !isNil(selectedCustomShow), | ||
/*includePrograms=*/ true, | ||
); | ||
|
||
const isLoading = showResult.isLoading || programsResult.isLoading; | ||
|
||
const formattedTitle = useCallback( | ||
forProgramType({ | ||
content: (p) => p.title, | ||
}), | ||
[], | ||
); | ||
|
||
const formattedEpisodeTitle = useCallback( | ||
forProgramType({ | ||
custom: (p) => p.program?.episodeTitle ?? '', | ||
}), | ||
[], | ||
); | ||
|
||
const { ref } = useIntersectionObserver({ | ||
onChange: (_, entry) => { | ||
if (entry.isIntersecting && scrollParams.limit < scrollParams.max) { | ||
setScrollParams(({ limit: prevLimit, max }) => ({ | ||
max, | ||
limit: prevLimit + 10, | ||
})); | ||
} | ||
}, | ||
threshold: 0.5, | ||
}); | ||
|
||
const handleItem = useCallback( | ||
(e: MouseEvent<HTMLButtonElement>, item: ContentProgram) => { | ||
e.stopPropagation(); | ||
if (selectedCustomShow) { | ||
addSelectedMedia({ | ||
type: 'custom-show', | ||
customShowId: selectedCustomShow.library.id, | ||
program: item, | ||
}); | ||
} | ||
}, | ||
[], | ||
); | ||
|
||
const renderListItems = () => { | ||
if ( | ||
showResult.data && | ||
programsResult.data && | ||
programsResult.data.length > 0 | ||
) { | ||
return chain(programsResult.data) | ||
.filter(isContentProgram) | ||
.filter(property('persisted')) | ||
.map((program) => { | ||
let title = formattedTitle(program); | ||
let epTitle = formattedEpisodeTitle(program); | ||
if (!isEmpty(epTitle)) { | ||
title += ` - ${epTitle}`; | ||
} | ||
|
||
return ( | ||
<ListItem dense key={program.id}> | ||
<ListItemText | ||
// TODO add season and episode number? | ||
primary={title} | ||
secondary={dayjs.duration(program.duration).humanize()} | ||
/> | ||
<Button | ||
onClick={(e) => handleItem(e, program)} | ||
variant="contained" | ||
> | ||
Add | ||
</Button> | ||
</ListItem> | ||
); | ||
}) | ||
.compact() | ||
.value(); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
return ( | ||
<Box> | ||
<LinearProgress | ||
sx={{ | ||
visibility: isLoading ? 'visible' : 'hidden', | ||
height: 10, | ||
marginTop: 1, | ||
}} | ||
/> | ||
<List | ||
component="nav" | ||
sx={{ | ||
mt: 2, | ||
width: '100%', | ||
maxHeight: 1200, | ||
overflowY: 'scroll', | ||
display: viewType === 'grid' ? 'flex' : 'block', | ||
flexWrap: 'wrap', | ||
gap: '10px', | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
{renderListItems()} | ||
<div style={{ height: 40 }} ref={ref}></div> | ||
</List> | ||
|
||
<Divider sx={{ mt: 3, mb: 2 }} /> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.