Skip to content

Commit

Permalink
improvement: artcile api fields
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglun committed Nov 25, 2023
1 parent 42a1609 commit 4ebea05
Show file tree
Hide file tree
Showing 10 changed files with 1,784 additions and 1,600 deletions.
3,271 changes: 1,730 additions & 1,541 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions src-tauri/src/feed/article.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ pub struct ArticleQueryItem {
#[diesel(sql_type = Text)]
pub feed_uuid: String,
#[diesel(sql_type = Text)]
pub channel_title: String,
pub feed_title: String,
#[diesel(sql_type = Text)]
pub channel_link: String,
pub feed_url: String,
#[diesel(sql_type = Text)]
pub link: String,
#[diesel(sql_type = Text)]
pub title: String,
#[diesel(sql_type = Text)]
pub feed_url: String,
#[diesel(sql_type = Text)]
pub description: String,
#[diesel(sql_type = Text)]
pub pub_date: String,
#[diesel(sql_type = Text)]
pub create_date: String,
#[diesel(sql_type = Integer)]
pub read_status: i32,
}
Expand Down Expand Up @@ -107,13 +107,14 @@ impl Article {
SELECT
A.id, A.uuid,
A.feed_uuid,
C.title as channel_title,
C.link as channel_link,
C.title as feed_title,
C.link as feed_url,
A.link,
A.title,
A.feed_url,
A.description as description,
A.pub_date,
A.create_date,
A.read_status
FROM
feeds as C
Expand Down Expand Up @@ -172,8 +173,8 @@ impl Article {
SELECT
A.id, A.uuid,
A.feed_uuid,
C.title as channel_title,
C.link as channel_link,
C.title as feed_title,
C.link as feed_url,
A.link,
A.title,
A.feed_url,
Expand Down Expand Up @@ -232,8 +233,8 @@ impl Article {
SELECT
A.id, A.uuid,
A.feed_uuid,
C.title as channel_title,
C.link as channel_link,
C.title as feed_title,
C.link as feed_url,
A.link,
A.title,
A.feed_url,
Expand Down
4 changes: 2 additions & 2 deletions src/components/ArticleItem/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const ArticleCardItem = (props: any) => {
updateCurrentArticle(article);
};

const ico = getChannelFavicon(article.channel_link);
const ico = getChannelFavicon(article.feed_url);

useEffect(() => {
setReadStatus(article.read_status);
Expand Down Expand Up @@ -93,7 +93,7 @@ export const ArticleCardItem = (props: any) => {
className="rounded w-4 mr-1"
/>
<span className="text-xs">
{ article.author || article.channel_title }
{ article.author || article.feed_title }
</span>
</div>
<div className="line-clamp-3">
Expand Down
2 changes: 1 addition & 1 deletion src/components/ArticleItem/Line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const ArticleLineItem = (props: any) => {
updateCurrentArticle(article);
};

const ico = getChannelFavicon(article.channel_link);
const ico = getChannelFavicon(article.feed_url);

useEffect(() => {
setReadStatus(article.read_status);
Expand Down
31 changes: 21 additions & 10 deletions src/components/ArticleItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { ForwardedRef, useEffect, useState } from "react";
import { formatDistanceToNow } from "date-fns";
import { formatDistanceToNow, format, parseISO } from "date-fns";
import classnames from "classnames";
import { useBearStore } from "@/stores";
import { getChannelFavicon } from "@/helpers/parseXML";
import { ArticleResItem } from "@/db";

export const ArticleItem = React.forwardRef(
(props: any, ref: ForwardedRef<HTMLLIElement>) => {
(props: { article: ArticleResItem }, ref: ForwardedRef<HTMLLIElement>) => {
const store = useBearStore((state) => ({
updateArticleAndIdx: state.updateArticleAndIdx,
article: state.article,
Expand All @@ -27,7 +28,7 @@ export const ArticleItem = React.forwardRef(
updateCurrentArticle(article);
};

const ico = getChannelFavicon(article.channel_link);
const ico = getChannelFavicon(article.feed_url);

useEffect(() => {
setReadStatus(article.read_status);
Expand All @@ -37,6 +38,13 @@ export const ArticleItem = React.forwardRef(
setHighlight(store.article?.id === article.id);
}, [store.article, article]);

console.log(
formatDistanceToNow(parseISO(article.create_date), {
includeSeconds: true,
addSuffix: true,
})
);

return (
<li
className={classnames(
Expand All @@ -45,7 +53,7 @@ export const ArticleItem = React.forwardRef(
{
"text-[hsl(var(--foreground)_/_80%)]": readStatus === 2,
"bg-article-active-bg": highlight,
},
}
)}
onClick={handleClick}
ref={ref}
Expand All @@ -61,7 +69,7 @@ export const ArticleItem = React.forwardRef(
? "text-article-active-headline"
: "text-article-headline"
}`,
"font-bold text-sm group-hover:text-article-active-headline",
"font-bold text-sm group-hover:text-article-active-headline"
)}
>
{article.title}
Expand All @@ -72,7 +80,7 @@ export const ArticleItem = React.forwardRef(
"text-article-paragraph group-hover:text-article-active-paragraph",
{
"text-article-active-paragraph": highlight,
},
}
)}
>
{(article.description || "").replace(/<[^<>]+>/g, "")}
Expand All @@ -82,7 +90,7 @@ export const ArticleItem = React.forwardRef(
"flex justify-between items-center text-xs text-article-paragraph group-hover:text-article-active-paragraph",
{
"text-article-active-paragraph": highlight,
},
}
)}
>
<div className="flex items-center">
Expand All @@ -92,14 +100,17 @@ export const ArticleItem = React.forwardRef(
className="rounded w-4 mr-1"
/>
<span className="overflow-hidden text-ellipsis mr-1 whitespace-nowrap">
{article.author || article.channel_title}
{article.author || article.feed_title}
</span>
</div>
<div className="whitespace-nowrap">
{formatDistanceToNow(new Date(article.pub_date || article.create_date), { includeSeconds: true, addSuffix: true })}
{formatDistanceToNow(parseISO(article.create_date), {
includeSeconds: true,
addSuffix: true,
})}
</div>
</div>
</li>
);
},
}
);
8 changes: 4 additions & 4 deletions src/components/ArticleView/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export const ArticleDetail = (props: ArticleDetailProps) => {
const store = useBearStore((state) => ({
feed: state.feed,
}));
const { pub_date, channel_link } = article;
const ico = getChannelFavicon(channel_link);
const { pub_date, feed_url } = article;
const ico = getChannelFavicon(feed_url);
const [pageContent, setPageContent] = useState("");
const [banner, setBanner] = useState("");
const [showBanner, setShowBanner] = useState(false);
Expand Down Expand Up @@ -167,7 +167,7 @@ export const ArticleDetail = (props: ArticleDetailProps) => {
<div className={classnames(styles.meta)}>
<span className={styles.channelInfo}>
<img src={store.feed?.logo || ico} alt="" className="rounded" />
{article.channel_title}
{article.feed_title}
</span>
{article.author && (
<span
Expand Down Expand Up @@ -198,7 +198,7 @@ export const ArticleDetail = (props: ArticleDetailProps) => {
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={createMarkup(pageContent)}
/>
{medias.length > 0 && <div>{medias.map(renderMediaBox)}</div>}
{medias && medias.length > 0 && <div>{medias.map(renderMediaBox)}</div>}
{/* <div
className={classnames("reading-content", "text-detail-paragraph")}>
<iframe src={article.link} className="w-full" allowFullScreen></iframe>
Expand Down
8 changes: 3 additions & 5 deletions src/components/WelcomePage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from "react";
import bg from "./bg.svg";
import styles from "./welcome.module.scss";

export const WelcomePage = () => {
return (
<div className={styles.box}>
<div className={styles.placeholder}>
<img src={bg} className={styles.bg} />
<div className="h-full flex items-center justify-center">
<div className="w-[40%] max-w-[500px]">
<img src={bg} className="w-full" />
</div>
</div>
);
Expand Down
15 changes: 0 additions & 15 deletions src/components/WelcomePage/welcome.module.scss

This file was deleted.

20 changes: 10 additions & 10 deletions src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,33 @@ export interface FeedResItem {
export interface Article {
id?: number;
uuid: string;
channel_uuid: string;
channel_link: string;
feed_uuid: string;
feed_title: string;
feed_url: string;
title: string;
link: string;
image: string;
feed_url: string;
description: string;
content?: string;
pub_date?: Date;
create_date?: Date;
pub_date?: string;
create_date: string;
read_status: number;
}

export interface ArticleResItem {
id?: number;
author: string;
uuid: string;
channel_uuid: string;
channel_link: string;
feed_uuid: string;
feed_title: string;
feed_url: string;
title: string;
link: string;
image: string;
feed_url: string;
description: string;
content?: string;
pub_date?: Date;
create_date?: Date;
pub_date?: string;
create_date: string;
read_status: number;
media_object: string;
}
Expand Down
4 changes: 2 additions & 2 deletions src/styles/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
--inline-code-font: monospace !important;
--mono-font: "JetBrains Mono", monospace !important;

--app-feedlist-width: 280px;
--app-article-width: 340px;
--app-feedlist-width: 240px;
--app-article-width: 320px;
--app-toolbar-height: 50px;
--app-setting-sidebar-width: 200px;
--view-helpbar-width: 50px;
Expand Down

0 comments on commit 4ebea05

Please sign in to comment.