-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat(webapp): add an "add project" page #31
Open
W95Psp
wants to merge
7
commits into
main
Choose a base branch
from
lucas/add-project-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0d639c7
feat(webapp): gather errors in a module
W95Psp 8b7deb5
feat(webapp): request_action now accepts a `then` argument
W95Psp 2f5f5bf
feat(webapp): add a "add project" page
W95Psp 806da7a
Merge branch 'main' into lucas/add-project-page
pnmadelaine f5d067e
fix option text
W95Psp a066566
fmt
W95Psp fbb0b6d
fix add project header text
W95Psp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
use crate::prelude::*; | ||
|
||
#[component] | ||
pub(crate) fn AddProject() -> impl IntoView { | ||
let action = request_action!( | ||
CreateProject, | ||
|name: String, url: String, flake: Option<String>| requests::Request::CreateProject { | ||
name, | ||
decl: requests::ProjectDecl { | ||
url, | ||
flake: flake.is_some() | ||
}, | ||
}, | ||
|result| { | ||
// TODO: redirect when success | ||
// if let Ok(Ok(())) = result { | ||
// leptos_actix::redirect("/"); | ||
// } | ||
result | ||
} | ||
); | ||
let value: RwSignal<Option<_>> = action.value(); | ||
let response = move || { | ||
value().map(|v| match v { | ||
Ok(Err(ResponseError::BadRequest(message))) => Err(message), | ||
Ok(_) => Ok(()), | ||
Err(e) => Err(format!("Fatal error: {e:?}")), | ||
}) | ||
}; | ||
let style = style! { | ||
.header { | ||
font-size: var(--font-size-huge); | ||
padding-bottom: 2px; | ||
} | ||
.header-description { | ||
color: var(--color-fg-muted); | ||
padding-top: 4px; | ||
margin-bottom: 14px; | ||
} | ||
.sep { | ||
border-bottom: 1px solid var(--color-border-default); | ||
padding-bottom: 14px; | ||
} | ||
.page { | ||
padding-top: 22px; | ||
max-width: 600px; | ||
margin: auto; | ||
} | ||
.fields { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 14px; | ||
} | ||
.field > label { | ||
display: block; | ||
padding-left: 2px; | ||
font-size: var(--font-size-small); | ||
font-weight: 400; | ||
} | ||
.field > input { | ||
width: 100%; | ||
} | ||
.field.flake { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 16px; | ||
} | ||
.field.flake .option { | ||
display: grid; | ||
grid-template-areas: raw_str("radio icon title") raw_str("radio icon details"); | ||
grid-template-columns: auto auto 1fr; | ||
align-items: center; | ||
column-gap: 5px; | ||
} | ||
.field.flake .option input { | ||
grid-area: radio; | ||
} | ||
.field.flake :deep(svg) { | ||
grid-area: icon; | ||
font-size: 20px; | ||
} | ||
.field.flake .option .kind { | ||
font-size: var(--font-size-small); | ||
font-weight: 400; | ||
grid-area: title; | ||
padding-bottom: 2px; | ||
} | ||
.field.flake .option .details { | ||
font-size: var(--font-size-small); | ||
grid-area: details; | ||
color: var(--color-fg-muted); | ||
padding-top: 2px; | ||
} | ||
button { | ||
background: var(--color-green-button-bg); | ||
color: white; | ||
width: auto!important; | ||
transition: all 100ms; | ||
} | ||
button:hover { | ||
transition: all 100ms; | ||
background: var(--color-green); | ||
} | ||
button:active { | ||
transition: all 100ms; | ||
background: var(--color-darkgreen); | ||
} | ||
.page :deep(.message) { | ||
text-align: justify; | ||
padding-bottom: 14px; | ||
display: flex; | ||
align-items: center; | ||
gap: 6px; | ||
} | ||
.page :deep(.error-message) { | ||
color: var(--color-danger-emphasis); | ||
} | ||
.page :deep(.success-message) { | ||
color: var(--color-success); | ||
} | ||
// TODO: Move to `app.rs` | ||
.page :deep(button) { | ||
border-radius: 6px; | ||
border: 1px solid var(--color-border-default); | ||
padding: 8px 10px; | ||
cursor: pointer; | ||
outline: inherit; | ||
font-size: inherit; | ||
font-family: inherit; | ||
font-weight: 400; | ||
} | ||
}; | ||
view! { class=style, | ||
<div class="page"> | ||
<ActionForm action> | ||
<div class="header">"Add a project"</div> | ||
<div class="header-description sep"> | ||
"Add continuous integration with Typhon for an existing codebase. This project will be visible to anyone that have access to this Typhon instance." | ||
</div> | ||
<div class="fields"> | ||
<div class="field"> | ||
<label class="label" for="name"> | ||
"Name" | ||
</label> | ||
<input type="text" name="name" class="input" id="name"/> | ||
</div> | ||
<div class="field sep"> | ||
<label class="label" for="url"> | ||
"Flake URL" | ||
</label> | ||
<input type="text" name="url" class="input" id="url"/> | ||
</div> | ||
<div class="field sep flake"> | ||
|
||
<div class="option"> | ||
<input name="flake" class="input" id="flake" type="radio" checked=true/> | ||
<Icon icon=icondata::FaSnowflakeRegular/> | ||
<label class="kind" for="flake"> | ||
"Flake" | ||
</label> | ||
<label class="details"> | ||
The project has a <code>flake.nix</code> <span>.</span> | ||
The project is a | ||
<a href="https://nixos.wiki/wiki/Flakes">Nix Flake</a> | ||
<span>.</span> | ||
</label> | ||
</div> | ||
|
||
<div class="option"> | ||
<input name="flake" class="input" id="legacy" type="radio"/> | ||
<Icon icon=icondata::BiCodeCurlyRegular/> | ||
<label class="kind" for="legacy"> | ||
"Legacy" | ||
</label> | ||
<label class="details" for="legacy"> | ||
The project has a | ||
<code>default.nix</code> | ||
<span>.</span> | ||
</label> | ||
</div> | ||
|
||
</div> | ||
<div class="field"> | ||
{move || { | ||
match response() { | ||
Some(Err(error)) => { | ||
view! { | ||
<div class="message error-message"> | ||
<Icon icon=icondata::BiErrorSolid/> | ||
<div>{error}</div> | ||
</div> | ||
} | ||
.into_view() | ||
} | ||
Some(Ok(())) => { | ||
view! { | ||
<div class="message success-message"> | ||
<Icon icon=icondata::BiCheckCircleSolid/> | ||
<div>"The project have been created successfully."</div> | ||
</div> | ||
} | ||
.into_view() | ||
} | ||
None => ().into_view(), | ||
} | ||
}} | ||
<button type="submit" style="float: right;"> | ||
"Add project" | ||
</button> | ||
</div> | ||
</div> | ||
</ActionForm> | ||
</div> | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "Import a project's declaration to Typhon. This project will be visible to anyone with access to this Typhon instance."?