Fix datetime bug
This commit is contained in:
parent
af3eae56c8
commit
71164657a1
@ -1,16 +1,16 @@
|
||||
import { format } from 'date-fns';
|
||||
import { Appbar, Button, Dialog, Menu, Portal, Text, useTheme } from 'react-native-paper';
|
||||
import { marked } from 'marked';
|
||||
import turndown from 'turndown-rn';
|
||||
import Wrapper from '@/components/ui/Wrapper';
|
||||
import { useFileSystem } from '@/hooks/useFilesystem';
|
||||
import { CoreBridge, PlaceholderBridge, RichText, TenTapStartKit, Toolbar, useEditorBridge, useEditorContent } from '@10play/tentap-editor';
|
||||
import { useRoute } from '@react-navigation/native';
|
||||
import { format } from 'date-fns';
|
||||
import { StorageAccessFramework } from 'expo-file-system';
|
||||
import { useRouter } from 'expo-router';
|
||||
import { marked } from 'marked';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Keyboard, View } from 'react-native';
|
||||
import { Appbar, Button, Dialog, Menu, Portal, Text, useTheme } from 'react-native-paper';
|
||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
import { useRoute } from '@react-navigation/native';
|
||||
import { StorageAccessFramework } from 'expo-file-system';
|
||||
import { useFileSystem } from '@/hooks/useFilesystem';
|
||||
import turndown from 'turndown-rn';
|
||||
|
||||
export default function EditorScreen() {
|
||||
const [entryText, setEntryText] = useState<string>('');
|
||||
@ -86,7 +86,7 @@ export default function EditorScreen() {
|
||||
replacement: (content: string) => `<u>${content}</u>`
|
||||
});
|
||||
const markdownContent = turndownService.turndown(content.html);
|
||||
console.log(markdownContent);
|
||||
if (markdownContent == turndownService.turndown(loadedContents)) { console.log("Skipping..."); return; }
|
||||
|
||||
// Save the markdown content
|
||||
await writeFile(fileUri ?? format(fileDatetime, 't'), markdownContent);
|
||||
@ -138,9 +138,6 @@ export default function EditorScreen() {
|
||||
* {
|
||||
font-size: 14px;
|
||||
}
|
||||
p {
|
||||
margin: 0; padding: 0;
|
||||
}
|
||||
`),
|
||||
PlaceholderBridge.configureExtension({
|
||||
placeholder: '',
|
||||
|
||||
@ -1,21 +1,16 @@
|
||||
import { Image } from 'expo-image';
|
||||
import { Platform, Pressable, RefreshControl, ScrollView, StyleSheet, TouchableOpacity, useColorScheme, View, ViewToken } from 'react-native';
|
||||
import { RefreshControl, StyleSheet, View, ViewToken } from 'react-native';
|
||||
|
||||
import { HelloWave } from '@/components/HelloWave';
|
||||
import ParallaxScrollView from '@/components/ParallaxScrollView';
|
||||
import { ThemedText } from '@/components/ThemedText';
|
||||
import { ThemedView } from '@/components/ThemedView';
|
||||
import { ActivityIndicator, Card, FAB, IconButton, List, Surface, Text, TouchableRipple, useTheme } from 'react-native-paper';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { DATA_DIRECTORY_URI_KEY } from '@/constants/Settings';
|
||||
import { useNavigation } from 'expo-router';
|
||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||
import { useFileSystem, prettyName } from '@/hooks/useFilesystem';
|
||||
import { prettyName, useFileSystem } from '@/hooks/useFilesystem';
|
||||
import { format } from 'date-fns';
|
||||
import { StorageAccessFramework } from 'expo-file-system';
|
||||
import { useNavigation } from 'expo-router';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { FlatList } from 'react-native-gesture-handler';
|
||||
import Markdown from 'react-native-markdown-display';
|
||||
import { ActivityIndicator, FAB, Text, TouchableRipple, useTheme } from 'react-native-paper';
|
||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||
|
||||
|
||||
export default function HomeScreen() {
|
||||
@ -88,6 +83,20 @@ export default function HomeScreen() {
|
||||
});
|
||||
}, []);
|
||||
|
||||
const entryPreview = (fileUri: string) => {
|
||||
if (!loadedContents.has(fileUri)) return null;
|
||||
const preview = loadedContents.get(fileUri)?.slice(0, 200);
|
||||
if (!preview) return null; // No content to show
|
||||
const extra = loadedContents.get(fileUri)?.slice(200);
|
||||
if (!extra) return preview; // No extra content to show
|
||||
|
||||
const extraLength = extra.trim().split(/\s+/).filter(Boolean).length;
|
||||
return preview! + (extra ?
|
||||
` *[... ${extraLength} words]*`
|
||||
:
|
||||
'');
|
||||
};
|
||||
|
||||
const renderFileItem = ({ item: f }: { item: typeof files[0] }) => (
|
||||
<TouchableRipple key={f.uri} style={styles.entryCard}
|
||||
onPress={() => {
|
||||
@ -117,7 +126,7 @@ export default function HomeScreen() {
|
||||
},
|
||||
paragraph: {
|
||||
marginTop: 0,
|
||||
marginBottom: 0,
|
||||
marginBottom: 10,
|
||||
},
|
||||
heading1: {
|
||||
color: theme.colors.primary,
|
||||
@ -143,7 +152,8 @@ export default function HomeScreen() {
|
||||
},
|
||||
}}
|
||||
>
|
||||
{loadedContents.get(f.uri) ||
|
||||
{entryPreview(f.uri)
|
||||
||
|
||||
<ActivityIndicator />
|
||||
}
|
||||
</Markdown>
|
||||
@ -181,7 +191,7 @@ export default function HomeScreen() {
|
||||
<Text style={{ fontWeight: "bold" }}>
|
||||
{prettyName(dataDirectoryUri, { pathContext: 'full' })}:
|
||||
</Text>
|
||||
{' '}{files.length} {files.length == 1 ? "entry" : "entries"}, {directorySize} bytes
|
||||
{' '}{files.length} {files.length == 1 ? "entry" : "entries"}, {directorySize} MB
|
||||
</Text>
|
||||
</View>
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import * as FileSystem from 'expo-file-system';
|
||||
import { DATA_DIRECTORY_URI_KEY } from '@/constants/Settings';
|
||||
import { StorageAccessFramework } from 'expo-file-system';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { format } from 'date-fns';
|
||||
import * as FileSystem from 'expo-file-system';
|
||||
import { StorageAccessFramework } from 'expo-file-system';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
interface FileEntry {
|
||||
name: string;
|
||||
@ -22,7 +22,7 @@ interface FileInfoWithSize {
|
||||
size: number;
|
||||
}
|
||||
|
||||
function datetimeFromFilename(filename: string): string {
|
||||
function datetimeFromFilename(filename: string): Date {
|
||||
const match = filename.match(/(\d+)-(\d+)-(\d+)-(\d+)-(\d+)-(\d+)\.md$/);
|
||||
if (match) {
|
||||
const [_, year, month, day, hour, minute, second] = match;
|
||||
@ -33,9 +33,9 @@ function datetimeFromFilename(filename: string): string {
|
||||
parseInt(hour),
|
||||
parseInt(minute),
|
||||
parseInt(second)
|
||||
).toISOString();
|
||||
);
|
||||
}
|
||||
return new Date().toISOString();
|
||||
return new Date();
|
||||
}
|
||||
|
||||
export function prettyName(uri: string | null, options: PrettyNameOptions = {}) {
|
||||
@ -118,7 +118,7 @@ export function useFileSystem() {
|
||||
}
|
||||
markdownFiles.sort((a, b) => b.datetime.getTime() - a.datetime.getTime()); // Sort by datetime descending
|
||||
setFiles(markdownFiles);
|
||||
setDirectorySize(totalSize);
|
||||
setDirectorySize(Math.round((totalSize / 1024 / 1024) * 1000) / 1000); // Convert to MB
|
||||
} catch (error) {
|
||||
console.error('Error loading files:', error);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user