Skip to content

Commit

Permalink
fix: get today list
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglun committed Oct 26, 2023
1 parent 6343e5e commit e0f5d08
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 40 deletions.
6 changes: 0 additions & 6 deletions src-tauri/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,6 @@ pub async fn add_feed(url: String) -> (usize, String) {
Err(err) => (0, err),
}
}

#[command]
pub async fn get_today_articles(filter: feed::article::ArticleFilter) -> feed::article::ArticleQueryResult {
feed::article::Article::get_today_articles(filter)
}

#[command]
pub async fn import_channels(list: Vec<String>) -> usize {
println!("{:?}", &list);
Expand Down
15 changes: 7 additions & 8 deletions src-tauri/src/feed/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use feed_rs::parser;
use log::info;
use log;
use reqwest;

use crate::core::config;

pub mod article;
Expand All @@ -14,7 +13,7 @@ pub fn create_client() -> reqwest::Client {

if let Some(user_config) = user_config {
if let Some(proxy) = user_config.local_proxy {
info!("user_config.local_proxy {:?}", proxy);
log::info!("user_config.local_proxy {:?}", proxy);

let mut scheme = String::from("socks5h://");

Expand Down Expand Up @@ -55,26 +54,26 @@ pub async fn parse_feed(url: &str) -> Result<feed_rs::model::Feed, String> {
match res {
Ok(res) => Ok(res),
Err(error) => {
println!("content parse error{:?}", error);
log::error!("content parse error{:?}", error);
Err(error.to_string())
}
}
}
Err(error) => {
println!("response not OK {:?}", error);
log::error!("response not OK {:?}", error);
Err(error.to_string())
}
}
}
reqwest::StatusCode::NOT_FOUND => Err(String::from("Could not find a feed at the location.")),
_ => {
println!("o {:?}", response);
log::error!("o {:?}", response);
Err("Not 200 OK".to_string())
}
},
Err(error) => {
println!("ERROR: {:?}", error);
println!("URL: {:?}", url);
log::error!("ERROR: {:?}", error);
log::error!("URL: {:?}", url);

Err(error.to_string())
}
Expand Down
1 change: 0 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ async fn main() {
.invoke_handler(tauri::generate_handler![
cmd::fetch_feed,
cmd::add_feed,
cmd::get_today_articles,
cmd::import_channels,
cmd::update_article_read_status,
cmd::update_user_config,
Expand Down
32 changes: 20 additions & 12 deletions src-tauri/src/server/handlers/article.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,44 +80,51 @@ pub async fn handle_mark_as_read(
pub async fn handle_articles(
query: web::Query<feed::article::ArticleFilter>,
) -> Result<impl Responder> {
let obj = feed::article::ArticleFilter {
let filter = feed::article::ArticleFilter {
channel_uuid: query.channel_uuid.clone(),
item_type: query.item_type.clone(),
read_status: query.read_status.clone(),
cursor: query.cursor.clone(),
limit: query.limit.clone(),
};

let res = feed::article::Article::get_article(obj);
let res = feed::article::Article::get_article(filter);

Ok(web::Json(res))
}

#[get("/api/all-articles")]
pub async fn handle_get_all_article(
pub async fn handle_get_all_articles(
query: web::Query<feed::article::ArticleFilter>,
) -> Result<impl Responder> {
let obj = feed::article::ArticleFilter {
let filter = feed::article::ArticleFilter {
channel_uuid: query.channel_uuid.clone(),
item_type: query.item_type.clone(),
read_status: query.read_status.clone(),
cursor: query.cursor.clone(),
limit: query.limit.clone(),
};

let res = feed::article::Article::get_all_articles(obj);
let res = feed::article::Article::get_all_articles(filter);

Ok(web::Json(res))
}


#[get("/api/articles/today")]
pub async fn handle_today_articles() -> Result<impl Responder> {
let obj = MyObj {
name: "hahah".to_string(),
#[get("/api/today-articles")]
pub async fn handle_get_today_articles(
query: web::Query<feed::article::ArticleFilter>,
) -> Result<impl Responder> {
let filter = feed::article::ArticleFilter {
channel_uuid: query.channel_uuid.clone(),
item_type: query.item_type.clone(),
read_status: query.read_status.clone(),
cursor: query.cursor.clone(),
limit: query.limit.clone(),
};

Ok(web::Json(obj))
let res = feed::article::Article::get_today_articles(filter);

Ok(web::Json(res))
}

pub fn config(cfg: &mut web::ServiceConfig) {
Expand All @@ -129,6 +136,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
.service(handle_sync_feed)
.service(handle_mark_as_read)
.service(handle_articles)
.service(handle_get_all_article)
.service(handle_get_all_articles)
.service(handle_get_today_articles)
;
}
13 changes: 5 additions & 8 deletions src/components/Subscribes/List.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import update from "immutability-helper";
import { useCallback, useEffect, useState } from "react";
import { SubscribeItem } from "./SubscribeItem";
import { useBearStore } from "@/stores";
import { FeedResItem } from "@/db";
import {useCallback, useEffect, useState} from "react";
import {SubscribeItem} from "./SubscribeItem";
import {useBearStore} from "@/stores";
import {FeedResItem} from "@/db";
import * as dataAgent from "@/helpers/dataAgent";
import {
adjustedTargetIndex,
Expand Down Expand Up @@ -160,7 +160,6 @@ export const List = () => {
);

const requestUpdateOrder = (list: FeedResItem[]) => {
console.log("%c Line:175 🍕 list", "color:#2eafb0", list);
const body = list.reduce(
(acu, feed, idx) => {
let item = {
Expand Down Expand Up @@ -196,8 +195,6 @@ export const List = () => {
}[]
);

console.log("%c Line:55 🥚 body", "color:#ffdd4d", body);

dataAgent.updateFeedSort(body).then((res) => {
console.log("%c Line:47 🥔 res", "color:#b03734", res);
});
Expand Down Expand Up @@ -228,7 +225,7 @@ export const List = () => {
uuid={feed.uuid}
text={feed.title}
level={level}
feed={{ ...feed }}
feed={{...feed}}
isActive={isActive}
isExpanded={feed.is_expanded}
toggleFolder={toggleFolder}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Subscribes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const ChannelList = (): JSX.Element => {

const afterDeleteFolder = () => {
if (store.feedContextMenuTarget) {
const { uuid } = store.feedContextMenuTarget;
const {uuid} = store.feedContextMenuTarget;
if (store.feed?.uuid === uuid) {
store.setArticleList([])
}
Expand All @@ -175,7 +175,7 @@ const ChannelList = (): JSX.Element => {

const afterUnsubscribeFeed = () => {
if (store.feedContextMenuTarget) {
const { uuid } = store.feedContextMenuTarget;
const {uuid} = store.feedContextMenuTarget;
if (store.feed?.uuid === uuid) {
store.setArticleList([])
}
Expand Down
7 changes: 5 additions & 2 deletions src/helpers/dataAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ export const getArticleList = async (
};

export const getTodayArticleList = async (filter: any) => {
console.warn("%c Line:70 🥔 get_today_articles", "color:#7f2b82");
return invoke("get_today_articles", { filter });
return request.get('/today-articles', {
params: {
...filter
}
});
};

export const getAllArticleList = async (filter: any) => {
Expand Down
2 changes: 1 addition & 1 deletion src/stores/createArticleSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const createArticleSlice: StateCreator<
getTodayArticleList: (filter: any) => {
const currentList = get().articleList;

return dataAgent.getTodayArticleList(filter).then((res) => {
return dataAgent.getTodayArticleList(filter).then(({ data: res }) => {
const { list } = res as { list: ArticleResItem[] };

get().setArticleList([...currentList, ...list]);
Expand Down

0 comments on commit e0f5d08

Please sign in to comment.