Skip to content

Commit

Permalink
Add: Add discord info
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Jul 20, 2023
1 parent 565225d commit ab0d96b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 68 deletions.
13 changes: 8 additions & 5 deletions backend/app/controllers/api/discord_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ def scope
def my_discord
require_login!

unless session.user.discord_id
session_user = User.find_by(id: session[:user_id])
unless session_user.discord_token
render json: { discord: nil }
return
end

render json: {
displayName: session.user.discord_display_name,
username: session.user.discord_username,
avatar: session.user.discord_avatar
discord: {
displayName: session_user.discord_display_name,
username: session_user.discord_username,
avatar: session_user.discord_avatar
}
}
end
def link
Expand Down Expand Up @@ -100,7 +103,7 @@ def callback
**if discord_user["discriminator"] == "0"
{
discord_id: discord_user["id"],
discord_username: discord_user["username"],
discord_username: "@" + discord_user["username"],
discord_display_name:
discord_user["global_name"] || discord_user["username"],
discord_avatar:
Expand Down
3 changes: 1 addition & 2 deletions frontend/i18n/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ upload:
label: "連携状態:"
connected: "連携済み({{username}})"
notConnected: "未連携"
connect: "連携"
reconnect: "再連携"
connectGuide: "連携方法"

param:
title: "タイトル"
Expand Down
4 changes: 3 additions & 1 deletion frontend/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ function App({ Component, pageProps }: AppProps) {
fetch(`/api/my/alt_users`).then(
async (res) => (await res.json()).users
),
fetch(`/api/my/discord`).then(async (res) => (await res.json()).user),
fetch(`/api/my/discord`).then(
async (res) => (await res.json()).discord
),
])

setSession({
Expand Down
116 changes: 56 additions & 60 deletions frontend/pages/charts/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ const UploadChart: NextPage<
onDragOver={(e) => e.preventDefault()}
onDrop={onDrop}
>
<fieldset disabled={isSubmitting}>
<fieldset disabled={isSubmitting || !session.discord}>
<Head>
<title>{t("title") + " | " + rootT("name")}</title>
</Head>
Expand Down Expand Up @@ -860,65 +860,61 @@ const UploadChart: NextPage<
</div>
</ModalPortal>

<div>
<h1 className="text-2xl font-bold mb-2">
{isEdit ? (
<>
{t("titleEdit", { title: chartData.title })}
{chartData.visibility === "public" || (
<span className="ml-2 text-slate-900 dark:text-white">
<LockClosedRegular />
</span>
)}
</>
) : (
t("title")
)}
</h1>
<p className="mb-4">
<Trans
i18nKey="upload:description"
components={[
<Link
href={`https://cc-wiki.sevenc7c.com/${
router.locale || "en"
}/guideline`}
target="_blank"
key="0"
/>,
]}
/>
<br />
<br />
{t("discordInfo.description")}
<p>
{t("discordInfo.status.label")}

{session.discord ? (
<>
{t("discordInfo.status.connected", {
username: session.discord.username,
})}
<a
href="/api/discord/authorize"
className="text-blue-500 hover:underline ml-2"
>
{t("discordInfo.reconnect")}
</a>
</>
) : (
<>
{t("discordInfo.status.notConnected")}
<a
href="/api/discord/authorize"
className="text-blue-500 hover:underline ml-2"
>
{t("discordInfo.connect")}
</a>
</>
<h1 className="text-2xl font-bold mb-2">
{isEdit ? (
<>
{t("titleEdit", { title: chartData.title })}
{chartData.visibility === "public" || (
<span className="ml-2 text-slate-900 dark:text-white">
<LockClosedRegular />
</span>
)}
</p>
</p>
</>
) : (
t("title")
)}
</h1>
<p className="mb-4">
<Trans
i18nKey="upload:description"
components={[
<Link
href={`https://cc-wiki.sevenc7c.com/${
router.locale || "en"
}/guideline`}
target="_blank"
key="0"
/>,
]}
/>
<br />
<br />
{t("discordInfo.description")}
<br />
{t("discordInfo.status.label")}
{session.discord ? (
<>
{t("discordInfo.status.connected", {
username: session.discord.username,
})}
</>
) : (
<>{t("discordInfo.status.notConnected")}</>
)}
<Link
href={`https://cc-wiki.sevenc7c.com/${
router.locale || "en"
}/discord`}
target="_blank"
className="ml-2"
>
{t("discordInfo.connectGuide")}
</Link>
</p>
<div className="relative">
{!session.discord && (
<div className="absolute z-50 top-0 left-0 w-full h-full bg-white bg-opacity-50 cursor-not-allowed" />
)}
<div className="grid xl:grid-cols-3 gap-4">
<FileUploadButton
accept="image/*"
Expand All @@ -942,7 +938,7 @@ const UploadChart: NextPage<
error={errors["chart"]}
/>
</div>
<div className="flex items-middle pt-2">
<div className="items-middle pt-2 hidden lg:flex">
<InfoRegular className="h-6" />
<span className="text-sm"> {t("dndHint")}</span>
</div>
Expand Down

0 comments on commit ab0d96b

Please sign in to comment.