layout enhancement. Reading position reset
This commit is contained in:
@@ -23,6 +23,7 @@ export default function EditStoryPage() {
|
||||
const [story, setStory] = useState<Story | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [resetingPosition, setResetingPosition] = useState(false);
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
@@ -201,6 +202,32 @@ export default function EditStoryPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleResetReadingPosition = async () => {
|
||||
if (!story || !confirm('Are you sure you want to reset the reading position to the beginning? This will remove your current place in the story.')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setResetingPosition(true);
|
||||
await storyApi.updateReadingProgress(storyId, 0);
|
||||
setStory(prev => prev ? { ...prev, readingPosition: 0 } : null);
|
||||
// Show success feedback
|
||||
setErrors({ resetSuccess: 'Reading position reset! The story will start from the beginning next time you read it.' });
|
||||
// Clear success message after 4 seconds
|
||||
setTimeout(() => {
|
||||
setErrors(prev => {
|
||||
const { resetSuccess, ...rest } = prev;
|
||||
return rest;
|
||||
});
|
||||
}, 4000);
|
||||
} catch (error) {
|
||||
console.error('Failed to reset reading position:', error);
|
||||
setErrors({ submit: 'Failed to reset reading position' });
|
||||
} finally {
|
||||
setResetingPosition(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (!story || !confirm('Are you sure you want to delete this story? This action cannot be undone.')) {
|
||||
return;
|
||||
@@ -374,6 +401,38 @@ export default function EditStoryPage() {
|
||||
placeholder="https://example.com/original-story-url"
|
||||
/>
|
||||
|
||||
{/* Reading Position Reset Section */}
|
||||
<div className="theme-card p-4 rounded-lg border theme-border">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h3 className="text-sm font-medium theme-header">Reading Position</h3>
|
||||
<p className="text-sm theme-text mt-1">
|
||||
{story?.readingPosition && story.readingPosition > 0
|
||||
? `Currently saved at position ${story.readingPosition.toLocaleString()}`
|
||||
: 'No reading position saved (story will start from the beginning)'
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={handleResetReadingPosition}
|
||||
loading={resetingPosition}
|
||||
disabled={saving || !story?.readingPosition || story.readingPosition === 0}
|
||||
className="text-orange-600 hover:text-orange-700 dark:text-orange-400 dark:hover:text-orange-300"
|
||||
>
|
||||
Reset to Beginning
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Success Message */}
|
||||
{errors.resetSuccess && (
|
||||
<div className="p-4 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg">
|
||||
<p className="text-green-800 dark:text-green-200">{errors.resetSuccess}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Submit Error */}
|
||||
{errors.submit && (
|
||||
<div className="p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg">
|
||||
|
||||
Reference in New Issue
Block a user