chore: enable noUncheckedIndexedAccess, better type check (#2608)
This commit is contained in:
@@ -17,7 +17,7 @@ export function PictureItemStateLess({ entry, feed }: EntryItemStatelessProps) {
|
||||
<div
|
||||
className={cn(
|
||||
"relative flex w-full shrink-0 items-center overflow-hidden rounded-md",
|
||||
!entry.media?.[0].url && "aspect-square",
|
||||
!entry.media?.[0]!.url && "aspect-square",
|
||||
)}
|
||||
>
|
||||
{entry.media?.[0] ? (
|
||||
|
||||
@@ -127,7 +127,7 @@ export const PictureWaterFallItem = memo(function PictureWaterFallItem({
|
||||
}}
|
||||
>
|
||||
{media && media.length > 0 ? (
|
||||
<MasonryItemFixedDimensionWrapper url={media[0].url}>
|
||||
<MasonryItemFixedDimensionWrapper url={media[0]!.url}>
|
||||
<SwipeMedia
|
||||
media={media}
|
||||
className={cn("w-full shrink-0 grow rounded-md", isActive && "rounded-b-none")}
|
||||
@@ -196,7 +196,7 @@ const MasonryItemFixedDimensionWrapper = (
|
||||
const style = useMemo(
|
||||
() => ({
|
||||
width: itemWidth,
|
||||
height: itemWidth / stableRadioCtx,
|
||||
height: itemWidth / stableRadioCtx!,
|
||||
}),
|
||||
[itemWidth, stableRadioCtx],
|
||||
)
|
||||
|
||||
@@ -111,10 +111,10 @@ export function VideoItem({ entryId, entryPreview, translation }: UniversalItemP
|
||||
/>
|
||||
) : entry.entries.media ? (
|
||||
<Media
|
||||
key={entry.entries.media?.[0].url}
|
||||
src={entry.entries.media?.[0].url}
|
||||
type={entry.entries.media?.[0].type}
|
||||
previewImageUrl={entry.entries.media?.[0].preview_image_url}
|
||||
key={entry.entries.media?.[0]!.url}
|
||||
src={entry.entries.media?.[0]!.url}
|
||||
type={entry.entries.media?.[0]!.type}
|
||||
previewImageUrl={entry.entries.media?.[0]!.preview_image_url}
|
||||
className={cn(
|
||||
"aspect-video w-full shrink-0 rounded-md object-cover",
|
||||
isActive && "rounded-b-none",
|
||||
|
||||
@@ -187,7 +187,7 @@ const VirtualGridImpl: FC<
|
||||
horizontal: true,
|
||||
count: columns.length,
|
||||
getScrollElement: () => scrollRef,
|
||||
estimateSize: (i) => columns[i],
|
||||
estimateSize: (i) => columns[i]!,
|
||||
overscan: 5,
|
||||
initialOffset: offsetCache.get(columnCacheKey) ?? 0,
|
||||
initialMeasurementsCache: measurementsCache.get(columnCacheKey) ?? [],
|
||||
@@ -205,7 +205,7 @@ const VirtualGridImpl: FC<
|
||||
const rowVirtualizer = useVirtualizer({
|
||||
count: rows.length + 1,
|
||||
estimateSize: () => {
|
||||
return columns[0] / ratioMap[view] + 58
|
||||
return columns[0]! / ratioMap[view] + 58
|
||||
},
|
||||
overscan: 5,
|
||||
gap: 8,
|
||||
@@ -309,7 +309,7 @@ const VirtualGridImpl: FC<
|
||||
>
|
||||
{ready && (
|
||||
<EntryItem
|
||||
entryId={entriesIds[virtualRow.index * columns.length + virtualColumn.index]}
|
||||
entryId={entriesIds[virtualRow.index * columns.length + virtualColumn.index]!}
|
||||
view={view}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -137,7 +137,7 @@ export const useEntriesByView = ({
|
||||
|
||||
const groupByDate = useGeneralSettingKey("groupByDate")
|
||||
const groupedCounts: number[] | undefined = useMemo(() => {
|
||||
if (views[view].gridMode) {
|
||||
if (views[view]!.gridMode) {
|
||||
return
|
||||
}
|
||||
if (!groupByDate) {
|
||||
@@ -184,8 +184,11 @@ function sortEntriesIdByEntryPublishedAt(entries: string[]) {
|
||||
const entriesId2Map = entryActions.getFlattenMapEntries()
|
||||
return entries
|
||||
.slice()
|
||||
.sort((a, b) =>
|
||||
entriesId2Map[b]?.entries.publishedAt.localeCompare(entriesId2Map[a]?.entries.publishedAt),
|
||||
.sort(
|
||||
(a, b) =>
|
||||
entriesId2Map[b]?.entries.publishedAt.localeCompare(
|
||||
entriesId2Map[a]?.entries.publishedAt!,
|
||||
) || 0,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -203,8 +206,10 @@ function sortEntriesIdByEntryInsertedAt(entries: string[]) {
|
||||
const entriesId2Map = entryActions.getFlattenMapEntries()
|
||||
return entries
|
||||
.slice()
|
||||
.sort((a, b) =>
|
||||
entriesId2Map[b]?.entries.insertedAt.localeCompare(entriesId2Map[a]?.entries.insertedAt),
|
||||
.sort(
|
||||
(a, b) =>
|
||||
entriesId2Map[b]?.entries.insertedAt.localeCompare(entriesId2Map[a]?.entries.insertedAt!) ||
|
||||
0,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -217,7 +222,7 @@ const useFetchEntryContentByStream = (remoteEntryIds?: string[]) => {
|
||||
const nextIds = [] as string[]
|
||||
if (onlyNoStored) {
|
||||
for (const id of remoteEntryIds) {
|
||||
const entry = getEntry(id)
|
||||
const entry = getEntry(id)!
|
||||
if (entry.entries.content) {
|
||||
continue
|
||||
}
|
||||
@@ -253,8 +258,8 @@ const useFetchEntryContentByStream = (remoteEntryIds?: string[]) => {
|
||||
|
||||
// Process all complete lines
|
||||
for (let i = 0; i < lines.length - 1; i++) {
|
||||
if (lines[i].trim()) {
|
||||
const json = JSON.parse(lines[i])
|
||||
if (lines[i]!.trim()) {
|
||||
const json = JSON.parse(lines[i]!)
|
||||
// Handle each JSON line here
|
||||
entryActions.updateEntryContent(json.id, json.content)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export const useEntryMarkReadHandler = (entriesIds: string[]) => {
|
||||
)
|
||||
|
||||
return useMemo(() => {
|
||||
if (views[feedView].wideMode && renderAsRead) {
|
||||
if (views[feedView]!.wideMode && renderAsRead) {
|
||||
return handleRenderAsRead
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ function EntryColumnImpl() {
|
||||
|
||||
// Determine if the archived button should be shown
|
||||
const showArchivedButton = commonConditions && feed?.type === "feed"
|
||||
const hasNoEntries = entries.data?.pages?.[0].data?.length === 0 && !entries.isLoading
|
||||
const hasNoEntries = entries.data?.pages?.[0]?.data?.length === 0 && !entries.isLoading
|
||||
|
||||
// Determine if archived entries should be loaded
|
||||
const shouldLoadArchivedEntries =
|
||||
@@ -140,7 +140,7 @@ function EntryColumnImpl() {
|
||||
}
|
||||
|
||||
if (!renderAsRead) return
|
||||
if (!views[view].wideMode) {
|
||||
if (!views[view]!.wideMode) {
|
||||
return
|
||||
}
|
||||
// For gird, render as mark read logic
|
||||
@@ -156,7 +156,7 @@ function EntryColumnImpl() {
|
||||
}, [entries])
|
||||
const isMobile = useMobile()
|
||||
|
||||
const ListComponent = views[view].gridMode ? EntryColumnGrid : EntryList
|
||||
const ListComponent = views[view]!.gridMode ? EntryColumnGrid : EntryList
|
||||
return (
|
||||
<div
|
||||
data-hide-in-print
|
||||
|
||||
@@ -68,7 +68,7 @@ export const EntryItemSkeleton: FC<{
|
||||
}
|
||||
|
||||
return SkeletonItem ? (
|
||||
<div className={cn(views[view].gridMode ? girdClassNames : "flex flex-col")}>
|
||||
<div className={cn(views[view]!.gridMode ? girdClassNames : "flex flex-col")}>
|
||||
{SkeletonItem}
|
||||
{SkeletonItem}
|
||||
{SkeletonItem}
|
||||
|
||||
@@ -85,7 +85,7 @@ export const EntryListHeader: FC<{
|
||||
)}
|
||||
onClick={stopPropagation}
|
||||
>
|
||||
{views[view].wideMode && entryId && entryId !== ROUTE_ENTRY_PENDING && (
|
||||
{views[view]!.wideMode && entryId && entryId !== ROUTE_ENTRY_PENDING && (
|
||||
<>
|
||||
<EntryHeader view={view} entryId={entryId} />
|
||||
<DividerVertical className="mx-2 w-px" />
|
||||
@@ -93,7 +93,7 @@ export const EntryListHeader: FC<{
|
||||
)}
|
||||
|
||||
<AppendTaildingDivider>
|
||||
{!views[view].wideMode && <WideModeButton />}
|
||||
{!views[view]!.wideMode && <WideModeButton />}
|
||||
{view === FeedViewType.SocialMedia && <DailyReportButton />}
|
||||
{view === FeedViewType.Pictures && <SwitchToMasonryButton />}
|
||||
{view === FeedViewType.Pictures && <FilterNoImageButton />}
|
||||
|
||||
@@ -149,7 +149,7 @@ export const SwitchToMasonryButton = () => {
|
||||
step={1}
|
||||
defaultValue={[masonryColumnValue]}
|
||||
onValueCommit={(value) => {
|
||||
setMasonryColumnValue(value[0])
|
||||
setMasonryColumnValue(value[0]!)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -12,13 +12,15 @@ export const TimelineTabs = () => {
|
||||
|
||||
const listsData = useSubscriptionStore(
|
||||
useCallback(
|
||||
(state) => state.feedIdByView[view].map((id) => state.data[id]).filter((s) => "listId" in s),
|
||||
(state) =>
|
||||
state.feedIdByView[view].map((id) => state.data[id]).filter((s) => s && "listId" in s),
|
||||
[view],
|
||||
),
|
||||
)
|
||||
const inboxData = useSubscriptionStore(
|
||||
useCallback(
|
||||
(state) => state.feedIdByView[view].map((id) => state.data[id]).filter((s) => "inboxId" in s),
|
||||
(state) =>
|
||||
state.feedIdByView[view].map((id) => state.data[id]).filter((s) => s && "inboxId" in s),
|
||||
[view],
|
||||
),
|
||||
)
|
||||
@@ -27,7 +29,7 @@ export const TimelineTabs = () => {
|
||||
(state) => {
|
||||
const categoryNames = new Set<string>()
|
||||
for (const subId of state.feedIdByView[view]) {
|
||||
const sub = state.data[subId]
|
||||
const sub = state.data[subId]!
|
||||
if (sub.category) {
|
||||
categoryNames.add(sub.category)
|
||||
}
|
||||
@@ -63,16 +65,18 @@ export const TimelineTabs = () => {
|
||||
<TabsTrigger className="p-0" value="">
|
||||
<span>Yours</span>
|
||||
</TabsTrigger>
|
||||
{listsData.map((s) => (
|
||||
<TabsTrigger className="p-0" key={s.listId} value={s.listId!}>
|
||||
<ListItem
|
||||
listId={s.listId!}
|
||||
view={view}
|
||||
iconSize={16}
|
||||
className="h-5 !bg-transparent p-0"
|
||||
/>
|
||||
</TabsTrigger>
|
||||
))}
|
||||
{listsData
|
||||
.filter((s) => !!s)
|
||||
.map((s) => (
|
||||
<TabsTrigger className="p-0" key={s.listId} value={s.listId!}>
|
||||
<ListItem
|
||||
listId={s.listId!}
|
||||
view={view}
|
||||
iconSize={16}
|
||||
className="h-5 !bg-transparent p-0"
|
||||
/>
|
||||
</TabsTrigger>
|
||||
))}
|
||||
{categoriesData.map((s) => (
|
||||
<TabsTrigger
|
||||
key={s}
|
||||
@@ -89,16 +93,18 @@ export const TimelineTabs = () => {
|
||||
</span>
|
||||
</TabsTrigger>
|
||||
))}
|
||||
{inboxData.map((s) => (
|
||||
<TabsTrigger key={s.inboxId} value={s.inboxId!}>
|
||||
<InboxItem
|
||||
inboxId={s.inboxId!}
|
||||
view={view}
|
||||
iconSize={16}
|
||||
className="h-5 !bg-transparent p-0"
|
||||
/>
|
||||
</TabsTrigger>
|
||||
))}
|
||||
{inboxData
|
||||
.filter((s) => !!s)
|
||||
.map((s) => (
|
||||
<TabsTrigger key={s.inboxId} value={s.inboxId!}>
|
||||
<InboxItem
|
||||
inboxId={s.inboxId!}
|
||||
view={view}
|
||||
iconSize={16}
|
||||
className="h-5 !bg-transparent p-0"
|
||||
/>
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
)
|
||||
|
||||
@@ -110,7 +110,7 @@ export const EntryList: FC<EntryListProps> = memo(
|
||||
groupCounts
|
||||
? groupCounts.reduce(
|
||||
(acc, count, index) => {
|
||||
acc[index + 1] = acc[index] + count
|
||||
acc[index + 1] = acc[index]! + count
|
||||
return acc
|
||||
},
|
||||
[0],
|
||||
@@ -263,7 +263,7 @@ export const EntryList: FC<EntryListProps> = memo(
|
||||
}
|
||||
>
|
||||
<EntryHeadDateItem
|
||||
entryId={entriesIds[virtualRow.index]}
|
||||
entryId={entriesIds[virtualRow.index]!}
|
||||
isSticky={isActiveStickyItem}
|
||||
/>
|
||||
</div>
|
||||
@@ -277,7 +277,7 @@ export const EntryList: FC<EntryListProps> = memo(
|
||||
ref={rowVirtualizer.measureElement}
|
||||
data-index={virtualRow.index}
|
||||
>
|
||||
<EntryItem entryId={entriesIds[virtualRow.index]} view={view} />
|
||||
<EntryItem entryId={entriesIds[virtualRow.index]!} view={view} />
|
||||
</div>
|
||||
</Fragment>
|
||||
)
|
||||
|
||||
@@ -83,7 +83,7 @@ export function ListItem({
|
||||
|
||||
const related = feed || inbox
|
||||
|
||||
const hasAudio = entry.entries?.attachments?.[0].url
|
||||
const hasAudio = entry.entries?.attachments?.[0]!.url
|
||||
const hasMedia = entry.entries?.media?.[0]?.url
|
||||
|
||||
const marginWidth = 8 * (isMobile ? 1.125 : 1)
|
||||
@@ -180,9 +180,9 @@ export function ListItem({
|
||||
{withAudio && !!hasAudio && (
|
||||
<AudioCover
|
||||
entryId={entryId}
|
||||
src={entry.entries!.attachments![0].url}
|
||||
src={entry.entries!.attachments![0]!.url}
|
||||
durationInSeconds={Number.parseInt(
|
||||
String(entry.entries!.attachments![0].duration_in_seconds ?? 0),
|
||||
String(entry.entries!.attachments![0]!.duration_in_seconds ?? 0),
|
||||
10,
|
||||
)}
|
||||
feedIcon={
|
||||
|
||||
@@ -15,10 +15,10 @@ export const EntryColumnWrapper = forwardRef<HTMLDivElement, EntryColumnWrapperP
|
||||
return (
|
||||
<div className={clsx(styles, animationStyles, "mt-2")}>
|
||||
<ScrollArea
|
||||
scrollbarClassName={clsx(!views[view].wideMode ? "w-[5px] p-0" : "", "z-[3]")}
|
||||
scrollbarClassName={clsx(!views[view]!.wideMode ? "w-[5px] p-0" : "", "z-[3]")}
|
||||
mask={false}
|
||||
ref={ref}
|
||||
rootClassName={clsx("h-full", views[view].wideMode ? "mt-2" : "")}
|
||||
rootClassName={clsx("h-full", views[view]!.wideMode ? "mt-2" : "")}
|
||||
viewportClassName="[&>div]:grow flex"
|
||||
onScroll={onScroll}
|
||||
>
|
||||
|
||||
@@ -19,7 +19,10 @@ export const EntryColumnWrapper = forwardRef<HTMLDivElement, EntryColumnWrapperP
|
||||
const [scrollElement, setScrollElement] = useState<HTMLElement | null>(null)
|
||||
return (
|
||||
<div className={clsx(styles, "relative flex flex-col")}>
|
||||
<div ref={ref} className={clsx("grow overflow-hidden", views[view].wideMode ? "mt-2" : "")}>
|
||||
<div
|
||||
ref={ref}
|
||||
className={clsx("grow overflow-hidden", views[view]!.wideMode ? "mt-2" : "")}
|
||||
>
|
||||
<PullToRefresh className="h-full" onRefresh={onPullToRefresh || noop}>
|
||||
<ScrollElementContext.Provider value={scrollElement}>
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user