-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
239 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use serde::Serialize; | ||
|
||
#[derive(Debug, Serialize)] | ||
pub struct Image { | ||
pub uri: String, | ||
pub title: Option<String>, | ||
pub width: Option<u32>, | ||
pub height: Option<u32>, | ||
pub description: Option<String>, | ||
} | ||
|
||
impl From<feed_rs::model::Image> for Image { | ||
fn from(image: feed_rs::model::Image) -> Self { | ||
Image { | ||
uri: image.uri, | ||
title: image.title, | ||
width: image.width, | ||
height: image.height, | ||
description: image.description, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod article; | ||
pub mod sync_response; | ||
pub mod sync_request; | ||
pub mod image; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
use serde::Serialize; | ||
use crate::enums::feed_type::FeedType; | ||
use crate::structs::article::Article; | ||
use crate::structs::image::Image; | ||
|
||
#[derive(Debug, serde::Serialize)] | ||
#[derive(Debug, Serialize)] | ||
pub struct SyncResponse { | ||
pub identifier: String, | ||
#[serde(rename = "type")] | ||
pub feed_type: FeedType, | ||
pub articles: Vec<Article> | ||
pub articles: Vec<Article>, | ||
pub image: Option<Image> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import styled from '@emotion/styled'; | ||
import { memo } from 'react'; | ||
import { FaAtom, FaQuestion, FaRss } from 'react-icons/fa'; | ||
import { VscJson } from 'react-icons/vsc'; | ||
|
||
import usePreference from '../../hooks/usePreference'; | ||
import Feed from '../../types/Feed'; | ||
|
||
interface FeedIconProps { | ||
feed: Feed; | ||
} | ||
|
||
const ImageIcon = styled.img` | ||
width: 2rem; | ||
height: 2rem; | ||
border-radius: 50%; | ||
object-fit: cover; | ||
object-position: center; | ||
`; | ||
|
||
function FeedIcon({ feed }: FeedIconProps) { | ||
const { type, image } = feed; | ||
const { showFeedIcons } = usePreference(); | ||
|
||
if (showFeedIcons && image !== null) { | ||
return <ImageIcon src={image.uri} alt={image.description || ''} />; | ||
} | ||
|
||
return ( | ||
<> | ||
{type === 'rss' && <FaRss className="w-8 h-6" />} | ||
{type === 'atom' && <FaAtom className="w-8 h-6" />} | ||
{type === 'json' && <VscJson className="w-8 h-6" />} | ||
{type === null && <FaQuestion className="w-8 h-6" />} | ||
</> | ||
); | ||
} | ||
export default memo(FeedIcon); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { AnyBackup, DataBackup, PreferenceBackup } from '../Backup'; | ||
|
||
import v2 from './v2'; | ||
|
||
export interface Transformer { | ||
data: (backup: DataBackup) => DataBackup; | ||
preference: (backup: PreferenceBackup) => PreferenceBackup; | ||
} | ||
|
||
const transformers: Record<number, Transformer> = { | ||
1: v2, | ||
}; | ||
|
||
export default function transform<T extends AnyBackup>(backup: T) { | ||
const transformer = transformers[backup.version]; | ||
if (!transformer) return backup; | ||
const func = transformer[backup.type] as (backup: AnyBackup) => AnyBackup; | ||
if (!func) throw new Error(`Invalid backup type ${backup.type}`); | ||
return func(backup) as T; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { DataBackup, PreferenceBackup } from '../Backup'; | ||
|
||
export default { | ||
data: (backup: DataBackup) => { | ||
return { | ||
...backup, | ||
state: { | ||
...backup.state, | ||
feeds: backup.state.feeds.map((feed) => ({ | ||
...feed, | ||
image: null, | ||
})), | ||
}, | ||
}; | ||
}, | ||
preference: (backup: PreferenceBackup) => { | ||
return { | ||
...backup, | ||
state: { | ||
...backup.state, | ||
showFeedIcons: true, | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.