-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrepo.rs
More file actions
221 lines (198 loc) · 5.63 KB
/
Copy pathrepo.rs
File metadata and controls
221 lines (198 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
use crate::{
cache::*,
components::*,
data::{CrateResponse, CrateSource, RepositoryInfo, VersionDiff, VersionInfo},
version::VersionId,
};
use camino::Utf8PathBuf;
use std::{rc::Rc, sync::Arc};
use yew::{prelude::*, suspense::*};
#[derive(Properties, PartialEq)]
pub struct RepoFileViewProps {
pub krate: String,
pub version: VersionId,
pub path: Utf8PathBuf,
}
#[function_component]
pub fn RepoFileView(props: &RepoFileViewProps) -> Html {
let fallback = html! {
<>
<SimpleNavbar />
<Content>
<Center>
<Loading title={"Loading crate"} status={"Loading crate metadata"} />
</Center>
</Content>
</>
};
html! {
<Suspense {fallback}>
<CrateFetcher
krate={props.krate.clone()}
version={props.version.clone()}
path={props.path.clone()}
/>
</Suspense>
}
}
#[function_component]
fn CrateFetcher(props: &RepoFileViewProps) -> HtmlResult {
let info = use_future_with(props.krate.clone(), |krate| async move {
CRATE_RESPONSE_CACHE.fetch_cached(&krate).await
})?;
let info = match &*info {
Ok(info) => info.clone(),
Err(error) => {
return Ok(html! {
<>
<SimpleNavbar />
<Content>
<Center>
<Error title={"Loading crate"} status={format!("Error: {error}")} />
</Center>
</Content>
</>
});
}
};
Ok(html! {
<VersionResolver
info={info.clone()}
version={props.version.clone()}
path={props.path.clone()}
/>
})
}
#[derive(Properties, PartialEq)]
pub struct VersionResolverProps {
info: Arc<CrateResponse>,
version: VersionId,
path: Utf8PathBuf,
}
#[function_component]
fn VersionResolver(props: &VersionResolverProps) -> Html {
let Some(version) = &props.info.version(props.version.clone()) else {
return html! {
{"version not found"}
};
};
html! {
<CrateSourceFetcher
info={props.info.clone()}
version={(*version).clone()}
path={props.path.clone()}
/>
}
}
#[derive(Properties, PartialEq)]
pub struct CrateSourceFetcherProps {
info: Arc<CrateResponse>,
version: VersionInfo,
path: Utf8PathBuf,
}
#[function_component]
fn CrateSourceFetcher(props: &CrateSourceFetcherProps) -> Html {
html! {
<Suspense fallback={html!{{"Loading"}}}>
<CrateSourceFetcherInner info={props.info.clone()} version={props.version.clone()} path={props.path.clone()} />
</Suspense>
}
}
#[function_component]
fn CrateSourceFetcherInner(props: &CrateSourceFetcherProps) -> HtmlResult {
let source = use_future_with(props.version.clone(), |version| async move {
CRATE_SOURCE_CACHE.fetch_cached(&version).await
})?;
let source = match &*source {
Ok(source) => source.clone(),
Err(_error) => {
return Ok(html! {
{"Error fetching source"}
});
}
};
Ok(html! {
<RepoSourceFetcher
info={props.info.clone()}
{source}
path={props.path.clone()}
/>
})
}
#[derive(Properties, PartialEq)]
pub struct RepoSourceFetcherProps {
info: Arc<CrateResponse>,
source: Arc<CrateSource>,
path: Utf8PathBuf,
}
#[function_component]
fn RepoSourceFetcher(props: &RepoSourceFetcherProps) -> Html {
let Some(repository) = props.info.krate.repository.clone() else {
return html! {
{"No repository set in crate metadata"}
};
};
let vcs_info = match props.source.cargo_vcs_info() {
Ok(info) => info,
Err(error) => {
return html! {
<>
{"error: "}{error.to_string()}
</>
};
}
};
let info = RepositoryInfo {
repository,
vcs_info,
};
let fallback = html! {
{"Loading repository archive"}
};
html! {
<Suspense {fallback}>
<RepoSourceFetcherInner
info={props.info.clone()}
repository={info}
source={props.source.clone()}
path={props.path.clone()}
/>
</Suspense>
}
}
#[derive(Properties, PartialEq)]
pub struct RepoSourceFetcherInnerProps {
info: Arc<CrateResponse>,
source: Arc<CrateSource>,
repository: RepositoryInfo,
path: Utf8PathBuf,
}
#[function_component]
fn RepoSourceFetcherInner(props: &RepoSourceFetcherInnerProps) -> HtmlResult {
let source = use_future_with(props.repository.clone(), |repository| async move {
repository.fetch().await.map(Arc::new)
})?;
let source = match &*source {
Ok(source) => source.clone(),
Err(error) => {
return Ok(html! {
{format!("Error repo: {error}")}
})
}
};
let diff = VersionDiff::new(source.clone(), props.source.clone());
let diff = Rc::new(diff);
Ok(html! {
<Content>
<main class="flex flex-col md:flex-row gap-2 lg:gap-4 p-2">
<FileTreeNavigation
diff={diff.clone()}
path={props.path.clone()}
/>
<div id="diff-view" class="flex-1">
<DiffView {diff} path={props.path.clone()} />
</div>
</main>
</Content>
})
}