fix: scroll to top when change input, update dependencies

This commit is contained in:
Artemy Egorov 2024-08-07 12:57:33 +03:00
parent a189ab1de6
commit b821b2bb8b
9 changed files with 50 additions and 38 deletions

View file

@ -14,7 +14,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@tauri-apps/api": "^1", "@tauri-apps/api": "^1",
"@txtdot/dalet": "1.0.0-pre1" "@txtdot/dalet": "1.0.0-pre3"
}, },
"devDependencies": { "devDependencies": {
"@iconify/svelte": "^4.0.2", "@iconify/svelte": "^4.0.2",

23
src-tauri/Cargo.lock generated
View file

@ -609,9 +609,9 @@ dependencies = [
[[package]] [[package]]
name = "dalet" name = "dalet"
version = "1.0.0-pre.10" version = "1.0.0-pre.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cccea0b163fbc0bc06f125bf69dfff4518336b63b86462f8c711366eef9e3e3" checksum = "fcb1baee9a3c3f0f6aed8cb4cf29331717227cb92dd6204e2df963dd315d69c1"
dependencies = [ dependencies = [
"clap", "clap",
"enum-procs", "enum-procs",
@ -656,6 +656,20 @@ dependencies = [
"syn 2.0.72", "syn 2.0.72",
] ]
[[package]]
name = "dashmap"
version = "6.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "804c8821570c3f8b70230c2ba75ffa5c0f9a4189b9a432b6656c536712acae28"
dependencies = [
"cfg-if",
"crossbeam-utils",
"hashbrown 0.14.5",
"lock_api",
"once_cell",
"parking_lot_core",
]
[[package]] [[package]]
name = "deranged" name = "deranged"
version = "0.3.11" version = "0.3.11"
@ -3724,12 +3738,13 @@ dependencies = [
[[package]] [[package]]
name = "tokio-gemini" name = "tokio-gemini"
version = "0.3.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bab37428a69ae0349cf6dd0182a6da06f065aa8c40ca18d9414a02e6fb49d875" checksum = "f7daf3995399caee7c8a2bd6de9e5f977443578b54130600f58a47409b90d360"
dependencies = [ dependencies = [
"base64ct", "base64ct",
"bytes", "bytes",
"dashmap",
"mime", "mime",
"num_enum 0.7.3", "num_enum 0.7.3",
"sha2", "sha2",

View file

@ -26,7 +26,7 @@ tauri = { version = "1", features = [
] } ] }
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
dalet = "1.0.0-pre.10" dalet = "1.0.0-pre.12"
tokio = { version = "1.39.2", features = ["full"] } tokio = { version = "1.39.2", features = ["full"] }
tokio-rustls = { version = "0.26.0", default-features = false, features = [ tokio-rustls = { version = "0.26.0", default-features = false, features = [
@ -36,7 +36,7 @@ tokio-rustls = { version = "0.26.0", default-features = false, features = [
bytes = "1.7.1" bytes = "1.7.1"
reqwest = "0.12.5" reqwest = "0.12.5"
tokio-gemini = "0.3.0" tokio-gemini = { version = "0.4.0", features = ["file-sscv"] }
url = "2.5.2" url = "2.5.2"
mime = "0.3.17" mime = "0.3.17"

View file

@ -1,5 +1,5 @@
use bytes::Bytes; use bytes::Bytes;
use dalet::{daletl::ToDaletlPage, parsers::gemtext::parse_gemtext, typed::Tag::*}; use dalet::{daletl::DlPage, parsers::gemtext::parse_gemtext, typed::Tag::*};
use mime::Mime; use mime::Mime;
use std::str; use std::str;
@ -23,19 +23,17 @@ async fn process_text(data: &str) -> VigiOutput {
let mut truncated = data.to_owned(); let mut truncated = data.to_owned();
truncated.truncate(50); truncated.truncate(50);
VigiOutput::new(truncated, vec![El(data.into())].to_dl_page()) VigiOutput::new(truncated, vec![El(data.into()).into()])
} }
async fn process_gemini(data: &str) -> Result<VigiOutput, VigiError> { async fn process_gemini(data: &str) -> Result<VigiOutput, VigiError> {
let mut truncated = data.to_owned(); let mut truncated = data.to_owned();
truncated.truncate(50); truncated.truncate(50);
let res = VigiOutput::new( let page = parse_gemtext(data).map_err(|_| VigiError::Parse)?;
truncated, let output = DlPage::from(page).data;
parse_gemtext(data)
.map_err(|_| VigiError::Parse)? let res = VigiOutput::new(truncated, output);
.to_dl_page(),
);
Ok(res) Ok(res)
} }

View file

@ -1,4 +1,4 @@
use dalet::daletl::{Tag, ToDaletlPage}; use dalet::daletl::DlTag;
use dalet::typed::Tag::*; use dalet::typed::Tag::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fs, path::PathBuf}; use std::{collections::HashMap, fs, path::PathBuf};
@ -41,18 +41,18 @@ pub struct VigiState {
// Temporary // Temporary
pub top_bar_input: String, pub top_bar_input: String,
pub current_data: Vec<Tag>, pub current_data: Vec<DlTag>,
pub cached_inputs: HashMap<String, VigiOutput>, pub cached_inputs: HashMap<String, VigiOutput>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct VigiOutput { pub struct VigiOutput {
pub title: String, pub title: String,
pub data: Vec<Tag>, pub data: Vec<DlTag>,
} }
impl VigiOutput { impl VigiOutput {
pub fn new(title: String, data: Vec<Tag>) -> Self { pub fn new(title: String, data: Vec<DlTag>) -> Self {
Self { title, data } Self { title, data }
} }
} }
@ -64,7 +64,7 @@ pub struct VigiJsState {
pub favorites_tabs: Vec<Tab>, pub favorites_tabs: Vec<Tab>,
pub top_bar_input: String, pub top_bar_input: String,
pub current_data: Vec<Tag>, pub current_data: Vec<DlTag>,
} }
impl VigiState { impl VigiState {
@ -132,7 +132,7 @@ impl VigiState {
} else if self.top_bar_input.is_empty() { } else if self.top_bar_input.is_empty() {
VigiOutput::new( VigiOutput::new(
"Homepage".to_owned(), "Homepage".to_owned(),
vec![El("Type something in the address bar".into())].to_dl_page(), vec![El("Type something in the address bar".into()).into()],
) )
} else { } else {
process_input(&self.top_bar_input).await? process_input(&self.top_bar_input).await?

View file

@ -4,9 +4,12 @@
export let body: Body; export let body: Body;
export let ifNull: any = undefined; export let ifNull: any = undefined;
export let preformatted = false;
</script> </script>
{#if typeof body === "string"} {#if typeof body === "string" && preformatted}
{body}
{:else if typeof body === "string"}
{#each body.split("\n") as line} {#each body.split("\n") as line}
{line} <br /> {line} <br />
{/each} {/each}

View file

@ -1,12 +1,8 @@
<script lang="ts"> <script lang="ts">
import TagRenderer from "./TagRenderer.svelte"; import TagRenderer from "./TagRenderer.svelte";
import { state } from "$lib/stores"; import { state } from "$lib/stores";
import ToTopScroller from "../ToTopScroller.svelte";
</script> </script>
{#each $state.current_data as tag, i} {#each $state.current_data as tag, i}
{#if i === 0}
<ToTopScroller />
{/if}
<TagRenderer {tag} /> <TagRenderer {tag} />
{/each} {/each}

View file

@ -1,7 +0,0 @@
<script lang="ts">
import { onMount } from "svelte";
onMount(() => {
document.getElementsByClassName("browser-window")[0]?.scrollTo(0, 0);
});
</script>

View file

@ -13,8 +13,7 @@ export async function updateAndLoadInput(input: string, newTab?: boolean) {
await invoke("update_input", { input, newTab: !!newTab }); await invoke("update_input", { input, newTab: !!newTab });
await updateVigiState(); await updateVigiState();
await invoke("load_input_force"); await loadInput(true);
await updateVigiState();
} }
export async function addTab() { export async function addTab() {
@ -29,13 +28,21 @@ export async function selectTab(index: number) {
} }
export async function removeTab(index: number) { export async function removeTab(index: number) {
let tabChanged = get(state).current_tab_index === index;
await invoke("remove_tab", { index }); await invoke("remove_tab", { index });
await updateVigiState(); await updateVigiState();
setTimeout(loadInput, 150);
if (tabChanged) setTimeout(loadInput, 150);
} }
export async function loadInput() { export async function loadInput(force = true) {
document.getElementsByClassName("browser-window")[0]?.scrollTo(0, 0);
if (force) {
await invoke("load_input_force");
} else {
await invoke("load_input"); await invoke("load_input");
}
await updateVigiState(); await updateVigiState();
} }