Simplify focus logic, fix index existence checks, and remove textarea autoFocus to improve UX and stability
This commit is contained in:
@@ -30,7 +30,7 @@ interface Scratch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const MEILISEARCH_ENDPOINT = 'https://meili.site.quack-lab.dev/';
|
const MEILISEARCH_ENDPOINT = 'https://meili.site.quack-lab.dev/';
|
||||||
const MEILISEARCH_API_KEY = 'F46V628fnzK85P376Q95n7987Z95M2MG673ea325982tD9v7236ix8XH54Xx26q6';
|
const MEILISEARCH_API_KEY = '31qXgGbQ3lT4DYHQ0TOKpMzh7wcigs7agHyxP5Fz6T6D61xsvNr24uO8ifndKOfM';
|
||||||
const NOTE_INDEX = 'notes';
|
const NOTE_INDEX = 'notes';
|
||||||
const SCRATCH_INDEX = 'scratch';
|
const SCRATCH_INDEX = 'scratch';
|
||||||
const SETTINGS_INDEX = 'settings';
|
const SETTINGS_INDEX = 'settings';
|
||||||
@@ -633,9 +633,7 @@ const Index = () => {
|
|||||||
if (e.ctrlKey && e.key === 'f') {
|
if (e.ctrlKey && e.key === 'f') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setIsSearchOpen(true);
|
setIsSearchOpen(true);
|
||||||
setTimeout(() => {
|
|
||||||
searchInputRef.current?.focus();
|
searchInputRef.current?.focus();
|
||||||
}, 100);
|
|
||||||
} else if (e.key === 'Escape') {
|
} else if (e.key === 'Escape') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// Save current note if it has content
|
// Save current note if it has content
|
||||||
@@ -674,15 +672,6 @@ const Index = () => {
|
|||||||
};
|
};
|
||||||
}, [currentNote, previousNote, scratchPad, isPreviousNoteModified]);
|
}, [currentNote, previousNote, scratchPad, isPreviousNoteModified]);
|
||||||
|
|
||||||
// Focus search input when dialog opens
|
|
||||||
useEffect(() => {
|
|
||||||
if (isSearchOpen) {
|
|
||||||
setTimeout(() => {
|
|
||||||
searchInputRef.current?.focus();
|
|
||||||
}, 100);
|
|
||||||
}
|
|
||||||
}, [isSearchOpen]);
|
|
||||||
|
|
||||||
// Auto-save functions
|
// Auto-save functions
|
||||||
const handleCurrentNoteBlur = () => {
|
const handleCurrentNoteBlur = () => {
|
||||||
if (currentNote.trim()) {
|
if (currentNote.trim()) {
|
||||||
@@ -810,7 +799,7 @@ const Index = () => {
|
|||||||
const initializeIndexes = async () => {
|
const initializeIndexes = async () => {
|
||||||
try {
|
try {
|
||||||
// Initialize notes index
|
// Initialize notes index
|
||||||
if (!await indexExists(NOTE_INDEX)) {
|
if (!(await indexExists(NOTE_INDEX))) {
|
||||||
await fetch(`${MEILISEARCH_ENDPOINT}/indexes`, {
|
await fetch(`${MEILISEARCH_ENDPOINT}/indexes`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -854,7 +843,7 @@ const Index = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Initialize scratch index
|
// Initialize scratch index
|
||||||
if (!await indexExists(SCRATCH_INDEX)) {
|
if (!(await indexExists(SCRATCH_INDEX))) {
|
||||||
await fetch(`${MEILISEARCH_ENDPOINT}/indexes`, {
|
await fetch(`${MEILISEARCH_ENDPOINT}/indexes`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -888,7 +877,7 @@ const Index = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Initialize settings index
|
// Initialize settings index
|
||||||
if (!await indexExists(SETTINGS_INDEX)) {
|
if (!(await indexExists(SETTINGS_INDEX))) {
|
||||||
await fetch(`${MEILISEARCH_ENDPOINT}/indexes`, {
|
await fetch(`${MEILISEARCH_ENDPOINT}/indexes`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -1095,7 +1084,6 @@ const Index = () => {
|
|||||||
setCurrentNote(e.target.value);
|
setCurrentNote(e.target.value);
|
||||||
}}
|
}}
|
||||||
onBlur={handleCurrentNoteBlur}
|
onBlur={handleCurrentNoteBlur}
|
||||||
autoFocus
|
|
||||||
className={`h-[calc(100%-2rem)] border-0 resize-none focus:ring-0 text-slate-200 bg-transparent ${getTextClass('2xl')}`}
|
className={`h-[calc(100%-2rem)] border-0 resize-none focus:ring-0 text-slate-200 bg-transparent ${getTextClass('2xl')}`}
|
||||||
placeholder="Start writing your thoughts..."
|
placeholder="Start writing your thoughts..."
|
||||||
/>
|
/>
|
||||||
|
Reference in New Issue
Block a user