feat: show feed name and the author of the post inside the list
This commit is contained in:
parent
046b50942d
commit
0a1db64a08
|
@ -1,13 +1,12 @@
|
||||||
import { View, Text, StyleSheet, ScrollView } from 'react-native'
|
import { View, Text, StyleSheet, ScrollView } from 'react-native'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { useAuthStore } from '../store'
|
import { useAuthStore, useSubscription } from '../store'
|
||||||
|
|
||||||
const Separator = () => <View style={styles.separator} />
|
const Separator = () => <View style={styles.separator} />
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
separator: {
|
separator: {
|
||||||
marginVertical: 8,
|
|
||||||
borderBottomColor: '#cccccc',
|
borderBottomColor: '#cccccc',
|
||||||
borderBottomWidth: 1
|
borderBottomWidth: 1
|
||||||
},
|
},
|
||||||
|
@ -18,6 +17,10 @@ const styles = StyleSheet.create({
|
||||||
|
|
||||||
export default function FeedListView() {
|
export default function FeedListView() {
|
||||||
const { credential } = useAuthStore()
|
const { credential } = useAuthStore()
|
||||||
|
|
||||||
|
const { fetch: fetchSubs, subscriptions } = useSubscription()
|
||||||
|
fetchSubs()
|
||||||
|
|
||||||
const [entries, setEntries] = useState<Entry[]>([])
|
const [entries, setEntries] = useState<Entry[]>([])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -32,7 +35,7 @@ export default function FeedListView() {
|
||||||
const res = await axios.get("https://api.feedbin.com/v2/entries.json", { auth: credential })
|
const res = await axios.get("https://api.feedbin.com/v2/entries.json", { auth: credential })
|
||||||
const entriesRes = res.data as Entry[]
|
const entriesRes = res.data as Entry[]
|
||||||
setEntries(entriesRes)
|
setEntries(entriesRes)
|
||||||
console.log(entries)
|
console.log(entriesRes[3])
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("`fetchList has an error`")
|
console.log("`fetchList has an error`")
|
||||||
console.log(e)
|
console.log(e)
|
||||||
|
@ -45,7 +48,7 @@ export default function FeedListView() {
|
||||||
entries.map(entry => <View key={entry.id}>
|
entries.map(entry => <View key={entry.id}>
|
||||||
<View style={styles.entryItem}>
|
<View style={styles.entryItem}>
|
||||||
<Text>{entry.title}</Text>
|
<Text>{entry.title}</Text>
|
||||||
<Text>{entry.author}</Text>
|
<Text>{entry.author && <Text>{entry.author} · </Text>}{subscriptions[entry.feed_id].title}</Text>
|
||||||
</View>
|
</View>
|
||||||
<Separator />
|
<Separator />
|
||||||
</View>)
|
</View>)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
import useAuthStore from './useAuthStore'
|
import useAuthStore from './useAuthStore'
|
||||||
|
import useSubscription from './useSubscription'
|
||||||
|
|
||||||
export { useAuthStore }
|
export { useAuthStore, useSubscription }
|
||||||
|
|
28
store/useSubscription.ts
Normal file
28
store/useSubscription.ts
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}))
|
Loading…
Reference in New Issue
Block a user