Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic support for browsing a specific version of a crate #24

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ pub enum Route {
About,
#[at("/search/:krate")]
Search { krate: String },
#[at("/browse/:name/:version")]
Browse {
name: String,
version: VersionId,
},
#[at("/browse/:name/:version/*path")]
BrowseFile {
name: String,
version: VersionId,
path: String,
},
#[at("/:name/")]
Crate { name: String },
#[at("/:src_name/:dst_name")]
Expand Down Expand Up @@ -56,6 +67,23 @@ fn switch(route: Route) -> Html {
match route {
Route::Home => html! { <Home /> },
Route::About => html! { <About /> },
Route::Browse { name, version } => html! {
<Diff
src_name={name.clone()}
dst_name={name}
old={version.clone()}
new={version}
/>
},
Route::BrowseFile { name, version, path } => html! {
<Diff
src_name={name.clone()}
dst_name={name}
old={version.clone()}
new={version}
{path}
/>
},
Route::Crate { name } => html! {
<Diff
src_name={name.clone()}
Expand Down
5 changes: 4 additions & 1 deletion src/components/diff_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub struct DiffViewProps {
pub fn DiffView(props: &DiffViewProps) -> Html {
let empty = FileDiff::default();
let file_diff = props.diff.files.get(&props.path).unwrap_or(&empty);
let is_identical_version = props.diff.left.version == props.diff.right.version;

// if this file does not exist, this will be none. so we use this trick to convert the none
// case into an empty iterator, meaning that it will simply be rendered as an empty file.
Expand Down Expand Up @@ -142,7 +143,9 @@ pub fn DiffView(props: &DiffViewProps) -> Html {
stack.push(DiffGroupInfo {
group: changes.by_ref().cloned().collect(),
range: cursor..file_diff.changes.len(),
in_context: false,
// When comparing a version of the crate to itself, this group will
// always contain the full text of the file. Don't collapse it.
in_context: is_identical_version,
});
}

Expand Down