feat: add pinning

This commit is contained in:
ammarahm-ed
2020-01-11 23:06:41 +05:00
parent 0dbd0960aa
commit d2a68dca62

View File

@@ -31,7 +31,7 @@ export const Folders = ({navigation}) => {
const [buttonHide, setButtonHide] = useState(false);
const [margin, setMargin] = useState(180);
const [numColumns, setNumColumns] = useState(1);
const [pinned, setPinned] = useState([]);
const isFocused = useIsFocused();
const params = navigation.state.params;
@@ -44,7 +44,11 @@ export const Folders = ({navigation}) => {
useEffect(() => {
if (isFocused) {
setNotebooks(db.getNotebooks());
setNotebooks([...db.getNotebooks()]);
let pinItems = db.getPinned();
setPinned([...pinItems]);
}
}, [isFocused]);
@@ -139,10 +143,39 @@ export const Folders = ({navigation}) => {
: notebooks[0]
? 155
: 155 - 60,
}}>
{pinned && pinned.length > 0 ? (
<>
<FlatList
data={pinned}
keyExtractor={(item, index) => item.dateCreated.toString()}
renderItem={({item, index}) =>
item.type === 'notebook' ? (
<NoteItem
customStyle={{
backgroundColor: colors.shade,
width: '100%',
paddingHorizontal: '5%',
paddingTop: 20,
marginBottom: 10,
marginTop: 20,
borderBottomWidth: 0,
}}
pinned={true}
refresh={() => refresh()}
item={item}
numColumns={1}
index={index}
/>
) : null
}
/>
</>
) : null}
</View>
}
ListEmptyComponent={
pinned && pinned.length > 0 ? null : (
<View
style={{
height: '80%',
@@ -174,6 +207,7 @@ export const Folders = ({navigation}) => {
No Notebooks found
</Text>
</View>
)
}
contentContainerStyle={{
width: '100%',