-
Notifications
You must be signed in to change notification settings - Fork 8
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
Print files owned by current user to console #347
base: main
Are you sure you want to change the base?
Changes from 3 commits
632e71b
2f77029
9f8053e
4053e6d
fde9c00
a57ebff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.files { | ||
display: grid; | ||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); | ||
gap: 1rem; | ||
padding: 1rem; | ||
background: whitesmoke; | ||
border-radius: 6px; | ||
border: 1px solid lightgray; | ||
} | ||
|
||
.filebutton { | ||
display: block; | ||
padding: 1rem; | ||
text-align: center; | ||
background: white; | ||
border-radius: 4px; | ||
border: 1px solid #e1e4e8; | ||
transition: all 0.2s ease; | ||
text-decoration: none; | ||
color: #0366d6; | ||
box-shadow: none; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { type SubmitHandler, createForm, reset } from "@modular-forms/solid"; | ||
import { createEffect, createResource } from "solid-js"; | ||
import { Fragment, Show, createEffect, createResource, createSignal } from "solid-js"; | ||
import invariant from "tiny-invariant"; | ||
|
||
import type { UserProfile } from "catcolab-api"; | ||
|
@@ -8,37 +8,98 @@ import { FormGroup, TextInputItem } from "../components"; | |
import { BrandedToolbar } from "../page"; | ||
import { LoginGate } from "./login"; | ||
|
||
import "./profile.css"; | ||
|
||
/** Page to configure user profile. */ | ||
export default function UserProfilePage() { | ||
const [myRefs, setMyRefs] = createSignal<[string, string][] | null>(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having to pass these refs around is a code smell. Also, I don't understand the types. This isn't how you usually create a ref. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The refs are going to be a list of |
||
|
||
return ( | ||
<div class="growable-container"> | ||
<BrandedToolbar /> | ||
<div class="page-container"> | ||
<LoginGate> | ||
<h2>Public profile</h2> | ||
<UserProfileForm /> | ||
<UserProfileForm onRefsLoaded={setMyRefs} /> | ||
<div style="margin-top: 1rem;"> | ||
<h3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No inline styles. Use the external stylesheet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should/can we lint directly for the keyword |
||
style=" | ||
margin: 0 0 0.5rem 0; | ||
color: #24292e; | ||
font-size: 1.25rem; | ||
font-weight: 500; | ||
" | ||
> | ||
Your Documents | ||
</h3> | ||
<Show when={myRefs()} fallback={<div> Loading user files... </div>} keyed> | ||
{(items) => { | ||
return ( | ||
<div class="files"> | ||
{items.map(([id, title]: [string, string]) => ( | ||
<Fragment key={id}> | ||
<a | ||
href={`${import.meta.env.VITE_SERVER_URL}/model/${id}`} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't need this env variable. Use Solid Router's |
||
class="filebutton" | ||
onMouseOver={(e) => { | ||
e.currentTarget.style.boxShadow = | ||
"0 2px 8px rgba(0,0,0,0.1)"; | ||
}} | ||
onMouseOut={(e) => { | ||
e.currentTarget.style.boxShadow = "none"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto about inline styles, and also you shouldn't use mouse over events to change styles. Use the appropriate CSS selectors. |
||
}} | ||
> | ||
{title || "(Untitled)"} | ||
</a> | ||
</Fragment> | ||
))} | ||
</div> | ||
); | ||
}} | ||
</Show> | ||
</div> | ||
</LoginGate> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
/** Form to configure user proifle. */ | ||
export function UserProfileForm() { | ||
export function UserProfileForm(props: { | ||
onRefsLoaded: (refs: [string, string][] | null) => void; | ||
}) { | ||
const api = useApi(); | ||
|
||
const [currentProfile, { refetch: refetchProfile }] = createResource(async () => { | ||
const result = await api.rpc.get_active_user_profile.query(); | ||
invariant(result.tag === "Ok"); | ||
console.log("cpTest", result.content); | ||
return result.content; | ||
}); | ||
const [userRefs, setUserRefs] = createSignal<[string, string][] | null>(null); | ||
createEffect(() => { | ||
if (userRefs()) { | ||
props.onRefsLoaded?.(userRefs()); | ||
} | ||
}); | ||
|
||
const [form, { Form, Field }] = createForm<UserProfile>(); | ||
|
||
createEffect(() => { | ||
reset(form, { initialValues: currentProfile() }); | ||
}); | ||
|
||
createEffect(async () => { | ||
const profile = currentProfile(); | ||
if (!profile) { | ||
return; | ||
} | ||
invariant(profile.username != null, "Profile username must be defined and not null"); | ||
const result = await api.rpc.get_user_refs_and_titles.query(profile.username); | ||
invariant(result.tag === "Ok"); | ||
console.log("get_refs_test", result.content); | ||
setUserRefs(result.content); | ||
}); | ||
|
||
const onSubmit: SubmitHandler<UserProfile> = async (values) => { | ||
await api.rpc.set_active_user_profile.mutate({ | ||
username: values.username ? values.username : null, | ||
|
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.
I think
RpcResult<Array<[string, string]>>>
is probably wrong here and reflects the weird front-end types you couldn't parse earlier.