mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-04-21 13:14:04 +02:00
feat: enhance ActionsMenu functionality with improved keyboard context management and dynamic history updates
This commit is contained in:
parent
be1718d9a5
commit
a79268d0f7
2 changed files with 31 additions and 16 deletions
|
@ -54,7 +54,7 @@
|
||||||
showModifier: true,
|
showModifier: true,
|
||||||
onClick: toggleActionsMenu,
|
onClick: toggleActionsMenu,
|
||||||
}" />
|
}" />
|
||||||
<ActionsMenu :selected-item="selectedItem" :is-visible="isActionsMenuVisible" @close="closeActionsMenu" />
|
<ActionsMenu :selected-item="selectedItem" :is-visible="isActionsMenuVisible" @close="closeActionsMenu" @toggle="toggleActionsMenu" />
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -116,17 +116,21 @@ const isActionsMenuVisible = ref<boolean>(false);
|
||||||
const topBar = ref<{ searchInput: HTMLInputElement | null } | null>(null);
|
const topBar = ref<{ searchInput: HTMLInputElement | null } | null>(null);
|
||||||
|
|
||||||
const toggleActionsMenu = () => {
|
const toggleActionsMenu = () => {
|
||||||
nextTick(() => {
|
isActionsMenuVisible.value = !isActionsMenuVisible.value;
|
||||||
isActionsMenuVisible.value = !isActionsMenuVisible.value;
|
|
||||||
if (isActionsMenuVisible.value) {
|
if (isActionsMenuVisible.value) {
|
||||||
$keyboard.enableContext('actionsMenu');
|
$keyboard.disableContext('main');
|
||||||
}
|
$keyboard.enableContext('actionsMenu');
|
||||||
});
|
} else {
|
||||||
|
$keyboard.disableContext('actionsMenu');
|
||||||
|
$keyboard.enableContext('main');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeActionsMenu = () => {
|
const closeActionsMenu = () => {
|
||||||
isActionsMenuVisible.value = false;
|
isActionsMenuVisible.value = false;
|
||||||
$keyboard.disableContext('actionsMenu');
|
$keyboard.disableContext('actionsMenu');
|
||||||
|
$keyboard.enableContext('main');
|
||||||
};
|
};
|
||||||
|
|
||||||
const isSameDay = (date1: Date, date2: Date): boolean => {
|
const isSameDay = (date1: Date, date2: Date): boolean => {
|
||||||
|
@ -430,13 +434,13 @@ const getYoutubeThumbnail = (url: string): string => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateHistory = async (resetScroll: boolean = false): Promise<void> => {
|
const updateHistory = async (resetScroll: boolean = false): Promise<void> => {
|
||||||
const results = await $history.loadHistoryChunk(0, CHUNK_SIZE);
|
offset = 0;
|
||||||
if (results.length > 0) {
|
history.value = [];
|
||||||
const existingIds = new Set(history.value.map((item) => item.id));
|
|
||||||
const uniqueNewItems = results.filter((item) => !existingIds.has(item.id));
|
|
||||||
|
|
||||||
const processedNewItems = await Promise.all(
|
const results = await $history.loadHistoryChunk(offset, CHUNK_SIZE);
|
||||||
uniqueNewItems.map(async (item) => {
|
if (results.length > 0) {
|
||||||
|
const processedItems = await Promise.all(
|
||||||
|
results.map(async (item) => {
|
||||||
const historyItem = new HistoryItem(
|
const historyItem = new HistoryItem(
|
||||||
item.source,
|
item.source,
|
||||||
item.content_type,
|
item.content_type,
|
||||||
|
@ -484,7 +488,8 @@ const updateHistory = async (resetScroll: boolean = false): Promise<void> => {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
history.value = [...processedNewItems, ...history.value];
|
history.value = processedItems;
|
||||||
|
offset = results.length;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
resetScroll &&
|
resetScroll &&
|
||||||
|
@ -554,9 +559,14 @@ const setupEventListeners = async (): Promise<void> => {
|
||||||
},
|
},
|
||||||
onToggleActions: toggleActionsMenu,
|
onToggleActions: toggleActionsMenu,
|
||||||
contextName: 'main',
|
contextName: 'main',
|
||||||
priority: $keyboard.PRIORITY.LOW
|
priority: $keyboard.PRIORITY.HIGH
|
||||||
});
|
});
|
||||||
$keyboard.enableContext('main');
|
|
||||||
|
if (isActionsMenuVisible.value) {
|
||||||
|
$keyboard.enableContext('actionsMenu');
|
||||||
|
} else {
|
||||||
|
$keyboard.enableContext('main');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await listen("tauri://blur", () => {
|
await listen("tauri://blur", () => {
|
||||||
|
|
|
@ -5,6 +5,7 @@ use rand::distr::Alphanumeric;
|
||||||
use sqlx::{ Row, SqlitePool };
|
use sqlx::{ Row, SqlitePool };
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use tauri_plugin_aptabase::EventTracker;
|
use tauri_plugin_aptabase::EventTracker;
|
||||||
|
use tauri::Emitter;
|
||||||
|
|
||||||
pub async fn initialize_history(pool: &SqlitePool) -> Result<(), Box<dyn std::error::Error>> {
|
pub async fn initialize_history(pool: &SqlitePool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let id: String = rng()
|
let id: String = rng()
|
||||||
|
@ -107,6 +108,8 @@ pub async fn add_history_item(
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let _ = app_handle.emit("clipboard-content-updated", ());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,6 +198,7 @@ pub async fn delete_history_item(
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
let _ = app_handle.track_event("history_item_deleted", None);
|
let _ = app_handle.track_event("history_item_deleted", None);
|
||||||
|
let _ = app_handle.emit("clipboard-content-updated", ());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -210,6 +214,7 @@ pub async fn clear_history(
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
let _ = app_handle.track_event("history_cleared", None);
|
let _ = app_handle.track_event("history_cleared", None);
|
||||||
|
let _ = app_handle.emit("clipboard-content-updated", ());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue