Skip to content

Commit

Permalink
improvement: update view status
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglun committed Sep 14, 2023
1 parent 3dc8320 commit f7ee665
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src-tauri/src/server/handlers/article.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ pub async fn handle_mark_as_read(
Ok(web::Json(res))
}

#[get("/api/articles/{uuid}/source")]
pub async fn handle_get_article_source(uuid: web::Path<String>) -> Result<impl Responder> {
Ok(web::Json("hahah".to_string()))
}

#[get("/api/articles")]
pub async fn handle_articles(
query: web::Query<feed::article::ArticleFilter>,
Expand Down
43 changes: 38 additions & 5 deletions src/containers/Article/ReadingOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useEffect } from "react";
import clsx from "clsx";
import { Icon } from "@/components/Icon";
import { ExternalLink, Ghost, Link, Paintbrush, Share } from "lucide-react";
import { useBearStore } from "@/stores";
Expand Down Expand Up @@ -35,14 +36,39 @@ export const ReadingOptions = (props: NavigatorProps) => {
setFilter: state.setFilter,

userConfig: state.userConfig,
viewOrigin: state.viewOrigin,
updateViewOrigin: state.updateViewOrigin,
viewOriginLoading: state.viewOriginLoading,
updateViewOriginLoading: state.updateViewOriginLoading,
}));

const handleViewSourcePage = () => {
if (!store.article) {
return;
}

const { link } = store.article as Article;

dataAgent.getPageSources(link).then((res) => {
console.log(res);
});
if (store.viewOrigin) {
store.updateViewOrigin(false);

return;
}

store.updateViewOrigin(true);
store.updateViewOriginLoading(true);

dataAgent
.getPageSources(link)
.then((res) => {
console.log(res);
})
.finally(() => {
store.updateViewOriginLoading(false);
});
// .catch((err) => {
// store.updateViewOrigin(false);
// });
// TODO: parse web content
};

Expand Down Expand Up @@ -80,8 +106,15 @@ export const ReadingOptions = (props: NavigatorProps) => {
</PopoverContent>
</Popover>
<TooltipBox content="View full page">
<Icon onClick={handleViewSourcePage}>
<Ghost size={16} />
<Icon
onClick={handleViewSourcePage}
disable={!store.article}
active={store.viewOrigin}
>
<Ghost
size={16}
className={clsx({ "animate-bounce": store.viewOrigin })}
/>
</Icon>
</TooltipBox>
<TooltipBox content="Open in browser">
Expand Down
27 changes: 26 additions & 1 deletion src/stores/createUserConfigSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ export interface UserConfigSlice {
userConfig: UserConfig;
getUserConfig: any;
updateUserConfig: (cfg: UserConfig) => void;

viewOrigin: boolean;
updateViewOrigin: (status: boolean) => void;
viewOriginLoading: boolean;
updateViewOriginLoading: (status: boolean) => void;
}

export const createUserConfigSlice: StateCreator<UserConfigSlice> = (set, get) => ({
export const createUserConfigSlice: StateCreator<UserConfigSlice> = (
set,
get
) => ({
userConfig: {},

getUserConfig: () => {
Expand All @@ -27,4 +35,21 @@ export const createUserConfigSlice: StateCreator<UserConfigSlice> = (set, get) =
}));
});
},

viewOrigin: false,

updateViewOrigin: (status: boolean) => {
console.log("%c Line:40 🥃 status", "color:#ea7e5c", status);
set(() => ({
viewOrigin: status,
}));
},

viewOriginLoading: false,

updateViewOriginLoading: (status: boolean) => {
set(() => ({
viewOriginLoading: status,
}));
},
});

0 comments on commit f7ee665

Please sign in to comment.