-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shortcut to publish user profile (#1140)
* add profile visibility button and checkbox to /people * remove checkbox if unauthenticated * adjust checbox removal if unauthenticated * remove content jumping, add note about delay, remove button option
- Loading branch information
1 parent
bc11bbb
commit f2f0022
Showing
2 changed files
with
98 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
"use client"; | ||
|
||
import { signIn, useSession } from "next-auth/react"; | ||
|
||
import { usePatchedJSONResource } from "~/components/hooks/resource"; | ||
import { type UserProfile } from "~/src/data/user-profile"; | ||
import { setFlag } from "~/src/flags"; | ||
import { Route } from "~/src/routing"; | ||
|
||
export const ProfileVisibilityPrefs = () => { | ||
const { status: sessionStatus } = useSession(); | ||
return ( | ||
<div className="mb-10"> | ||
{sessionStatus === "loading" && <LoadingSpinner />} | ||
{sessionStatus === "authenticated" && <ProfileVisibilityButton />} | ||
{sessionStatus === "unauthenticated" && <SignedOutText />} | ||
</div> | ||
); | ||
}; | ||
|
||
const Note = ({ children }: { children: React.ReactNode }) => ( | ||
<p className="typo-caption ml-6 mt-1 text-balance">{children}</p> | ||
); | ||
|
||
const ProfileVisibilityButton = () => { | ||
const { | ||
model: model, | ||
updating, | ||
setModel, | ||
} = usePatchedJSONResource<UserProfile>({ | ||
url: "/account/me", | ||
writeKeys: ["privacyFlags"], | ||
}); | ||
|
||
return ( | ||
<div> | ||
<label className="mb-1 flex items-center"> | ||
<input | ||
checked={!!model?.privacyFlags.includes("enablePublicProfile")} | ||
type="checkbox" | ||
className="mr-3" | ||
disabled={updating} | ||
onChange={(e) => { | ||
if (model) { | ||
setModel({ | ||
...model, | ||
privacyFlags: setFlag( | ||
model.privacyFlags, | ||
"enablePublicProfile", | ||
e.target.checked, | ||
), | ||
}); | ||
} | ||
}} | ||
></input> | ||
Chci mít veřejný profil | ||
</label> | ||
<Note>Může pár minut trvat, než se tato změna projeví.</Note> | ||
</div> | ||
); | ||
}; | ||
|
||
const LoadingSpinner = () => ( | ||
<> | ||
<div className="w-[50ex] animate-pulse rounded-lg bg-gray indent-[-9999px]"> | ||
Načítám… | ||
</div> | ||
<Note>Načítám…</Note> | ||
</> | ||
); | ||
|
||
const SignedOutText = () => ( | ||
<> | ||
<div> | ||
Tip:{" "} | ||
<a | ||
className="typo-link" | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
return signIn(); | ||
}} | ||
> | ||
Když se přihlásíš | ||
</a> | ||
, můžeš tady zveřejnit svůj profil. | ||
</div> | ||
<Note> | ||
<a className="typo-link" href={Route.register()}> | ||
Nebo si založ nový účet | ||
</a> | ||
, pokud žádný nemáš. | ||
</Note> | ||
</> | ||
); |
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