feat: ai daily in article content column
This commit is contained in:
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="#fff" fill-opacity=".01" d="M24 0v24H0V0z"/><path fill="#10161F" d="M12 7a1 1 0 1 0 0 2zm.002 2a1 1 0 0 0 0-2zM11 10a1 1 0 1 0 0 2zm1.5 8a1 1 0 1 0 0-2zm7.5-6a8 8 0 0 1-8 8v2c5.523 0 10-4.477 10-10zm-8 8a8 8 0 0 1-8-8H2c0 5.523 4.477 10 10 10zm-8-8a8 8 0 0 1 8-8V2C6.477 2 2 6.477 2 12zm8-8a8 8 0 0 1 8 8h2c0-5.523-4.477-10-10-10zm0 5h.002V7H12zm-1 2.5v5h2v-5zm.5-1.5H11v2h.5zm-.5 6.5a1.5 1.5 0 0 0 1.5 1.5v-2a.5.5 0 0 1 .5.5zm2-5a1.5 1.5 0 0 0-1.5-1.5v2a.5.5 0 0 1-.5-.5z"/></svg>
|
||||
|
After Width: | Height: | Size: 568 B |
@@ -39,6 +39,7 @@
|
||||
"@hookform/resolvers": "3.9.0",
|
||||
"@iconify/tools": "4.0.4",
|
||||
"@mozilla/readability": "^0.5.0",
|
||||
"@radix-ui/react-accordion": "1.2.0",
|
||||
"@radix-ui/react-alert-dialog": "1.1.1",
|
||||
"@radix-ui/react-avatar": "1.1.0",
|
||||
"@radix-ui/react-checkbox": "1.1.1",
|
||||
|
||||
Generated
+33
@@ -46,6 +46,9 @@ importers:
|
||||
'@mozilla/readability':
|
||||
specifier: ^0.5.0
|
||||
version: 0.5.0(patch_hash=fgkvsbckled47trggkhdkimzbm)
|
||||
'@radix-ui/react-accordion':
|
||||
specifier: 1.2.0
|
||||
version: 1.2.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
'@radix-ui/react-alert-dialog':
|
||||
specifier: 1.1.1
|
||||
version: 1.1.1(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
@@ -1383,6 +1386,19 @@ packages:
|
||||
'@radix-ui/primitive@1.1.0':
|
||||
resolution: {integrity: sha512-4Z8dn6Upk0qk4P74xBhZ6Hd/w0mPEzOOLxy4xiPXOXqjF7jZS0VAKk7/x/H6FyY2zCkYJqePf1G5KmkmNJ4RBA==}
|
||||
|
||||
'@radix-ui/react-accordion@1.2.0':
|
||||
resolution: {integrity: sha512-HJOzSX8dQqtsp/3jVxCU3CXEONF7/2jlGAB28oX8TTw1Dz8JYbEI1UcL8355PuLBE41/IRRMvCw7VkiK/jcUOQ==}
|
||||
peerDependencies:
|
||||
'@types/react': '*'
|
||||
'@types/react-dom': '*'
|
||||
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
|
||||
react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
|
||||
peerDependenciesMeta:
|
||||
'@types/react':
|
||||
optional: true
|
||||
'@types/react-dom':
|
||||
optional: true
|
||||
|
||||
'@radix-ui/react-alert-dialog@1.1.1':
|
||||
resolution: {integrity: sha512-wmCoJwj7byuVuiLKqDLlX7ClSUU0vd9sdCeM+2Ls+uf13+cpSJoMgwysHq1SGVVkJj5Xn0XWi1NoRCdkMpr6Mw==}
|
||||
peerDependencies:
|
||||
@@ -8261,6 +8277,23 @@ snapshots:
|
||||
|
||||
'@radix-ui/primitive@1.1.0': {}
|
||||
|
||||
'@radix-ui/react-accordion@1.2.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)':
|
||||
dependencies:
|
||||
'@radix-ui/primitive': 1.1.0
|
||||
'@radix-ui/react-collapsible': 1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
'@radix-ui/react-collection': 1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
'@radix-ui/react-compose-refs': 1.1.0(@types/react@18.3.3)(react@18.3.1)
|
||||
'@radix-ui/react-context': 1.1.0(@types/react@18.3.3)(react@18.3.1)
|
||||
'@radix-ui/react-direction': 1.1.0(@types/react@18.3.3)(react@18.3.1)
|
||||
'@radix-ui/react-id': 1.1.0(@types/react@18.3.3)(react@18.3.1)
|
||||
'@radix-ui/react-primitive': 2.0.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
'@radix-ui/react-use-controllable-state': 1.1.0(@types/react@18.3.3)(react@18.3.1)
|
||||
react: 18.3.1
|
||||
react-dom: 18.3.1(react@18.3.1)
|
||||
optionalDependencies:
|
||||
'@types/react': 18.3.3
|
||||
'@types/react-dom': 18.3.0
|
||||
|
||||
'@radix-ui/react-alert-dialog@1.1.1(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)':
|
||||
dependencies:
|
||||
'@radix-ui/primitive': 1.1.0
|
||||
|
||||
+16
@@ -2723,6 +2723,22 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
|
||||
status: 200;
|
||||
};
|
||||
};
|
||||
"/ai/daily": {
|
||||
$get: {
|
||||
input: {
|
||||
query: {
|
||||
view: "0" | "1";
|
||||
startDate: string;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 0;
|
||||
data: string;
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
};
|
||||
};
|
||||
} & {
|
||||
"/actions": {
|
||||
$get: {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import * as AccordionPrimitive from "@radix-ui/react-accordion"
|
||||
import { cn } from "@renderer/lib/utils"
|
||||
import * as React from "react"
|
||||
|
||||
const Accordion = AccordionPrimitive.Root
|
||||
|
||||
const AccordionItem = React.forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AccordionPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn("border-b", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
AccordionItem.displayName = "AccordionItem"
|
||||
|
||||
const AccordionTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<AccordionPrimitive.Header className="flex">
|
||||
<AccordionPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{/* <ChevronDownIcon className="h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200" /> */}
|
||||
</AccordionPrimitive.Trigger>
|
||||
</AccordionPrimitive.Header>
|
||||
))
|
||||
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName
|
||||
|
||||
const AccordionContent = React.forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<AccordionPrimitive.Content
|
||||
ref={ref}
|
||||
className="overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
|
||||
{...props}
|
||||
>
|
||||
<div className={cn("pb-4 pt-0", className)}>{children}</div>
|
||||
</AccordionPrimitive.Content>
|
||||
))
|
||||
AccordionContent.displayName = AccordionPrimitive.Content.displayName
|
||||
|
||||
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger }
|
||||
@@ -0,0 +1,173 @@
|
||||
import {
|
||||
Accordion,
|
||||
AccordionContent,
|
||||
AccordionItem,
|
||||
AccordionTrigger,
|
||||
} from "@renderer/components/ui/accordion"
|
||||
import { Card, CardHeader } from "@renderer/components/ui/card"
|
||||
import { LoadingCircle } from "@renderer/components/ui/loading"
|
||||
import { Markdown } from "@renderer/components/ui/markdown"
|
||||
import { ScrollArea } from "@renderer/components/ui/scroll-area"
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@renderer/components/ui/tooltip"
|
||||
import { useAuthQuery } from "@renderer/hooks/common"
|
||||
import { apiClient } from "@renderer/lib/api-fetch"
|
||||
import { defineQuery } from "@renderer/lib/defineQuery"
|
||||
import { cn } from "@renderer/lib/utils"
|
||||
import { MarkAllButton } from "@renderer/modules/entry-column/mark-all-button"
|
||||
import { useState } from "react"
|
||||
|
||||
export const DailyItem = ({
|
||||
value,
|
||||
index,
|
||||
view,
|
||||
}: {
|
||||
value?: string
|
||||
index: 0 | 1
|
||||
view: 0 | 1
|
||||
}) => {
|
||||
const dateObj = new Date()
|
||||
|
||||
const nowHour = dateObj.getHours()
|
||||
let startDate: number
|
||||
let endDate: number
|
||||
let title: string
|
||||
|
||||
const today8AM = dateObj.setHours(8, 0, 0, 0)
|
||||
const today8PM = dateObj.setHours(20, 0, 0, 0)
|
||||
dateObj.setDate(dateObj.getDate() - 1)
|
||||
const yesterday8AM = dateObj.setHours(8, 0, 0, 0)
|
||||
const yesterday8PM = dateObj.setHours(20, 0, 0, 0)
|
||||
dateObj.setDate(dateObj.getDate() - 1)
|
||||
const dayBeforeYesterday8PM = dateObj.setHours(20, 0, 0, 0)
|
||||
|
||||
// For index 0, get the last past 8 AM or 8 PM; for index 1, get the second last past 8 AM or 8 PM.
|
||||
if (nowHour >= 20) {
|
||||
if (index === 0) {
|
||||
endDate = today8PM - 1
|
||||
startDate = today8AM
|
||||
title = "Today"
|
||||
} else {
|
||||
endDate = today8AM - 1
|
||||
startDate = yesterday8PM
|
||||
title = "Last Night"
|
||||
}
|
||||
} else if (nowHour >= 8) {
|
||||
if (index === 0) {
|
||||
endDate = today8AM - 1
|
||||
startDate = yesterday8PM
|
||||
title = "Last Night"
|
||||
} else {
|
||||
endDate = yesterday8PM - 1
|
||||
startDate = yesterday8AM
|
||||
title = "Yesterday"
|
||||
}
|
||||
} else {
|
||||
if (index === 0) {
|
||||
endDate = yesterday8PM - 1
|
||||
startDate = yesterday8AM
|
||||
title = "Yesterday"
|
||||
} else {
|
||||
endDate = yesterday8AM - 1
|
||||
startDate = dayBeforeYesterday8PM
|
||||
title = "The Night Before Last"
|
||||
}
|
||||
}
|
||||
|
||||
const content = useAuthQuery(
|
||||
defineQuery(["daily", view, startDate, endDate], async () => {
|
||||
const res = await apiClient.ai.daily.$get({
|
||||
query: {
|
||||
startDate: `${+startDate}`,
|
||||
view: `${view}`,
|
||||
},
|
||||
})
|
||||
return res.data
|
||||
}),
|
||||
{
|
||||
enabled: value === `${index}`,
|
||||
},
|
||||
)
|
||||
|
||||
return (
|
||||
<AccordionItem value={`${index}`} className="mx-auto max-w-lg last:border-b-0">
|
||||
<Card className="border-none">
|
||||
<CardHeader className="space-y-0 p-0">
|
||||
<AccordionTrigger className="justify-center py-6 pt-2 hover:no-underline">
|
||||
<div className="flex items-center gap-2 text-base">
|
||||
<i className="i-mgc-magic-2-cute-re" />
|
||||
<div className="font-medium">
|
||||
{title}
|
||||
's Top News
|
||||
</div>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<i className="i-mgc-information-cute-re" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<ul className="list-decimal pl-4 text-left text-sm">
|
||||
<li>
|
||||
Here is news selected by AI from your timeline
|
||||
{" ("}
|
||||
{new Date(startDate).toLocaleTimeString("en-US", { weekday: "short", hour: "numeric", minute: "numeric" })}
|
||||
{" "}
|
||||
-
|
||||
{" "}
|
||||
{new Date(endDate + 1).toLocaleTimeString("en-US", { weekday: "short", hour: "numeric", minute: "numeric" })}
|
||||
{") "}
|
||||
that may be important to you.
|
||||
</li>
|
||||
<li>Update daily at 8 AM and 8 PM.</li>
|
||||
</ul>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
<ScrollArea.ScrollArea
|
||||
mask={false}
|
||||
flex
|
||||
viewportClassName="max-h-[calc(100vh-500px)]"
|
||||
>
|
||||
{content.isLoading ? (
|
||||
<LoadingCircle size="large" className="text-center" />
|
||||
) : (
|
||||
content.data && (
|
||||
<Markdown className="prose-sm px-6 prose-p:my-1 prose-ul:my-1">{content.data}</Markdown>
|
||||
)
|
||||
)}
|
||||
</ScrollArea.ScrollArea>
|
||||
<div className="mt-4 flex items-center pl-3.5">
|
||||
<MarkAllButton
|
||||
filter={{
|
||||
startTime: startDate,
|
||||
endTime: endDate,
|
||||
}}
|
||||
className="text-[1.05rem]"
|
||||
/>
|
||||
<span>Mark all as read</span>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</CardHeader>
|
||||
</Card>
|
||||
</AccordionItem>
|
||||
)
|
||||
}
|
||||
|
||||
export const Daily = ({
|
||||
view,
|
||||
className,
|
||||
}: {
|
||||
view: 0 | 1
|
||||
className?: string
|
||||
}) => {
|
||||
const [value, setValue] = useState<string>()
|
||||
|
||||
return (
|
||||
<div className={cn(className, "mx-auto w-[75ch] gap-3")}>
|
||||
<Accordion type="single" className="space-y-4" collapsible value={value} onValueChange={setValue}>
|
||||
<DailyItem value={value} index={0} view={view} />
|
||||
<DailyItem value={value} index={1} view={view} />
|
||||
</Accordion>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -11,10 +11,12 @@ import { Logo } from "@renderer/components/icons/logo"
|
||||
import { AutoResizeHeight } from "@renderer/components/ui/auto-resize-height"
|
||||
import { StyledButton } from "@renderer/components/ui/button"
|
||||
import { ScrollArea } from "@renderer/components/ui/scroll-area"
|
||||
import { ROUTE_FEED_PENDING } from "@renderer/constants"
|
||||
import { useEntryReadabilityToggle } from "@renderer/hooks/biz/useEntryActions"
|
||||
import { useRouteParamsSelector } from "@renderer/hooks/biz/useRouteParams"
|
||||
import { useRouteParamsSelector, useRouteParms } from "@renderer/hooks/biz/useRouteParams"
|
||||
import { useAuthQuery, useTitle } from "@renderer/hooks/common"
|
||||
import { stopPropagation } from "@renderer/lib/dom"
|
||||
import { FeedViewType } from "@renderer/lib/enum"
|
||||
import { parseHtml } from "@renderer/lib/parse-html"
|
||||
import type { ActiveEntryId } from "@renderer/models"
|
||||
import {
|
||||
@@ -30,23 +32,32 @@ import { useEffect, useLayoutEffect, useState } from "react"
|
||||
import { LoadingCircle } from "../../components/ui/loading"
|
||||
import { EntryTranslation } from "../entry-column/translation"
|
||||
import { setEntryContentScrollToTop, setEntryTitleMeta } from "./atoms"
|
||||
import { Daily } from "./daily"
|
||||
import { EntryHeader } from "./header"
|
||||
import { EntryContentProvider } from "./provider"
|
||||
|
||||
export const EntryContent = ({ entryId }: { entryId: ActiveEntryId }) => {
|
||||
const title = useFeedHeaderTitle()
|
||||
const { feedId, view } = useRouteParms()
|
||||
|
||||
useTitle(title)
|
||||
if (!entryId) {
|
||||
return (
|
||||
<m.div
|
||||
onContextMenu={stopPropagation}
|
||||
className="-mt-2 flex size-full min-w-0 flex-col items-center justify-center gap-1 text-balance px-12 text-center text-lg font-medium text-zinc-400"
|
||||
className="center size-full flex-col"
|
||||
initial={{ opacity: 0.01, y: 300 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
>
|
||||
<Logo className="size-16 opacity-40 grayscale" />
|
||||
<span className="max-w-[60ch]">{title}</span>
|
||||
<div
|
||||
onContextMenu={stopPropagation}
|
||||
className="flex w-full min-w-0 flex-col items-center justify-center gap-1 text-balance px-12 pb-6 text-center text-lg font-medium text-zinc-400"
|
||||
>
|
||||
<Logo className="size-16 opacity-40 grayscale" />
|
||||
<span className="max-w-[60ch]">{title}</span>
|
||||
</div>
|
||||
{feedId === ROUTE_FEED_PENDING && view === FeedViewType.Articles && (
|
||||
<Daily view={view} />
|
||||
)}
|
||||
</m.div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user