feat: show feed name and the author of the post inside the list

This commit is contained in:
Astrian Zheng 2025-07-01 09:24:25 +10:00
parent 046b50942d
commit 0a1db64a08
Signed by: Astrian
SSH Key Fingerprint: SHA256:rVnhx3DAKjujCwWE13aDl7uV6+9U1MvydLkNRXJrBiA
3 changed files with 37 additions and 5 deletions

View File

@ -1,13 +1,12 @@
import { View, Text, StyleSheet, ScrollView } from 'react-native'
import { useEffect, useState } from 'react'
import axios from 'axios'
import { useAuthStore } from '../store'
import { useAuthStore, useSubscription } from '../store'
const Separator = () => <View style={styles.separator} />
const styles = StyleSheet.create({
separator: {
marginVertical: 8,
borderBottomColor: '#cccccc',
borderBottomWidth: 1
},
@ -18,6 +17,10 @@ const styles = StyleSheet.create({
export default function FeedListView() {
const { credential } = useAuthStore()
const { fetch: fetchSubs, subscriptions } = useSubscription()
fetchSubs()
const [entries, setEntries] = useState<Entry[]>([])
useEffect(() => {
@ -32,7 +35,7 @@ export default function FeedListView() {
const res = await axios.get("https://api.feedbin.com/v2/entries.json", { auth: credential })
const entriesRes = res.data as Entry[]
setEntries(entriesRes)
console.log(entries)
console.log(entriesRes[3])
} catch (e) {
console.log("`fetchList has an error`")
console.log(e)
@ -45,7 +48,7 @@ export default function FeedListView() {
entries.map(entry => <View key={entry.id}>
<View style={styles.entryItem}>
<Text>{entry.title}</Text>
<Text>{entry.author}</Text>
<Text>{entry.author && <Text>{entry.author} &middot; </Text>}{subscriptions[entry.feed_id].title}</Text>
</View>
<Separator />
</View>)

View File

@ -1,3 +1,4 @@
import useAuthStore from './useAuthStore'
import useSubscription from './useSubscription'
export { useAuthStore }
export { useAuthStore, useSubscription }

28
store/useSubscription.ts Normal file
View File

@ -0,0 +1,28 @@
import { create } from 'zustand'
import axios from 'axios'
import useAuthStore from './useAuthStore'
type SubState = {
subscriptions: { [key: number]: Subscription }
fetch: () => Promise<void>
}
export default create<SubState>(set => ({
subscriptions: {},
fetch: async () => {
const credential = useAuthStore.getState().credential
if (!credential) return
try {
const res = await axios.get('https://api.feedbin.com/v2/subscriptions.json', { auth: credential })
let subs: { [key: number]: Subscription } = {}
for (let i in res.data) {
subs[res.data[i].feed_id] = res.data[i]
}
set({ subscriptions: subs })
// console.log(subs)
} catch(e) {
console.log("`fetch` (useSubscription) has encounted an error")
console.log(e)
}
}
}))