Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues 105 #108

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions components/context/LayoutContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ const LayoutContext = createContext<LayoutContextType | undefined>(undefined);

// Provide the context to children
export const LayoutProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
<<<<<<< Updated upstream
const [layout, setLayout] = useState<'horizontal' | 'vertical' | null>('horizontal');
=======

const [layout, setLayout] = useState<'horizontal' | 'vertical'>('horizontal');
>>>>>>> Stashed changes

return (
<LayoutContext.Provider value={{ layout, setLayout }}>
Expand Down
163 changes: 58 additions & 105 deletions components/user/home-screen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Image,
View,
Button,
SectionList,
} from 'react-native';
import Post from './Post';
import {useJournalEntries} from '@/providers/JournalEntriesProvider';
Expand All @@ -21,12 +22,9 @@ import {Popup, SCROLL_DESTINATION, CLOSED_POSITION, PopupRef} from './Popup';
import {Text} from '@/components/StyledText';
import Navbar from '@/components/Navbar';
import { LayoutProvider } from '@/components/context/LayoutContext';
<<<<<<< Updated upstream
=======
import { useLayout } from '@/components/context/LayoutContext';


>>>>>>> Stashed changes
export default function HomeScreen() {
const { layout } = useLayout();
const {isConnected} = useNet();
Expand Down Expand Up @@ -99,93 +97,28 @@ export default function HomeScreen() {
setSelectedPostId(id);
}
};
// Group entries by month
const [sections, setSections] = useState([]);
useEffect(() => {
const groupedEntries = initialJournalEntries.reduce((acc, entry) => {
const date = new Date(entry.date);
const monthYear = `${date.toLocaleString('default', { month: 'long' })} ${date.getFullYear()}`;
if (!acc[monthYear]) {
acc[monthYear] = [];
}
acc[monthYear].push(entry);
return acc;
}, {});

const formattedSections = Object.entries(groupedEntries).map(([title, data]) => ({ title, data }));
setSections(formattedSections);
}, [initialJournalEntries]);

return (
<SafeAreaView style={styles.view} edges={['left', 'right']}>
{/* Import navbar */}
<Navbar/>
<<<<<<< Updated upstream
<ImageBackground
style={styles.imageBg}
resizeMode="cover"
source={require('../../../assets/images/home-screen/gradient-home-screen.png')}
>
<FlatList
data={journalEntries}
renderItem={({item}) => (
<Post
id={item.id}
date={item.date}
title={item.title}
content={item.content}
tags={item.tags}
onOpen={() => openPopupMenu(item.id)}
/>
)}
style={styles.list}
keyExtractor={item => item.id}
refreshing={isLoading}
onRefresh={handleRefresh}
/>

{/* Popup menu to edit, delete selected post */}
<Popup ref={popupRef}>
<View style={styles.buttons_container}>
<TouchableOpacity
style={[styles.button, styles.button_border]}
onPress={() => {
if (selectedPostId) {
handleEdit(selectedPostId);
}
}}
>
<Image
source={require('../../../assets/images/home-screen/Pencil.png')}
/>
<Text>Edit</Text>
</TouchableOpacity>
<TouchableOpacity style={[styles.button, styles.button_border]}>
<Image
source={require('../../../assets/images/home-screen/Bookmark.png')}
/>
<Text>Mark As Favourite</Text>
</TouchableOpacity>
<TouchableOpacity style={[styles.button, styles.button_border]}>
<Image
source={require('../../../assets/images/home-screen/Price Tag.png')}
/>
<Text>Edit Tag</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
if (selectedPostId) {
handleDelete(selectedPostId);
}
}}
>
<Image
source={require('../../../assets/images/home-screen/Delete.png')}
/>
<Text style={{color: '#F34848'}}>Delete</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.button, styles.button_border]}
onPress={() => {
router.push('/profile/settings' as any);
}}
>
<Text>Settings (WIP)</Text>
</TouchableOpacity>
</View>
</Popup>
<Button title="Create" onPress={() => router.push('/text-entry')} />
<Button
title="Settings"
onPress={() => router.push('/profile/settings' as any)}
/>
</ImageBackground>
=======
{
layout === 'horizontal' ? (
<ImageBackground
Expand All @@ -194,23 +127,29 @@ export default function HomeScreen() {
source={require('../../../assets/images/home-screen/gradient-home-screen.png')}
>
{/* Start of lists */}
<FlatList
data={journalEntries}
renderItem={({ item }) => (
<Post
id={item.id}
date={item.date}
title={item.title}
content={item.content}
tags={item.tags}
onOpen={() => openPopupMenu(item.id)}
/>
)}
style={styles.list}
keyExtractor={(item) => item.id}
refreshing={isLoading}
onRefresh={handleRefresh}
/>

<SectionList
sections={sections}
renderItem={({ item }) => (
<Post
id={item.id}
date={item.date}
title={item.title}
content={item.content}
tags={item.tags}
onOpen={() => openPopupMenu(item.id)}
/>
)}
renderSectionHeader={({ section: { title } }) => (
<View style={styles.sectionHeader}>
<Text style={styles.sectionHeaderText}>{title}</Text>
</View>
)}
style={styles.list}
keyExtractor={(item) => item.id}
refreshing={isLoading}
onRefresh={handleRefresh}
/>

{/* Popup menu to edit, delete selected post */}
<Popup ref={popupRef}>
Expand Down Expand Up @@ -277,8 +216,9 @@ export default function HomeScreen() {
source={require('../../../assets/images/home-screen/white-bg.jpg')}
>
{/* Start of lists */}
<FlatList
data={journalEntries}

<SectionList
sections={sections}
renderItem={({ item }) => (
<Post
id={item.id}
Expand All @@ -289,6 +229,11 @@ export default function HomeScreen() {
onOpen={() => openPopupMenu(item.id)}
/>
)}
renderSectionHeader={({ section: { title } }) => (
<View style={styles.sectionHeader}>
<Text style={styles.sectionHeaderText}>{title}</Text>
</View>
)}
style={styles.list}
keyExtractor={(item) => item.id}
refreshing={isLoading}
Expand Down Expand Up @@ -356,8 +301,6 @@ export default function HomeScreen() {




>>>>>>> Stashed changes
</SafeAreaView>
);
}
Expand Down Expand Up @@ -394,4 +337,14 @@ const styles = StyleSheet.create({
borderBottomWidth: 1.5,
borderBlockColor: '#ECEAEA',
},
sectionHeader: {
padding: 6,
marginTop: 22,
marginLeft: 5
},
sectionHeaderText: {
fontSize: 20,
fontWeight: '700',
color: '#62239B',
},
});