Skip to content

Commit

Permalink
Add: Show owner
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Aug 31, 2024
1 parent d05a01b commit 1a4a200
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 36 deletions.
27 changes: 15 additions & 12 deletions backend/app/controllers/api/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def expire_data

def show_user
params.require(:handle)
@user =
user =
if params[:handle].start_with?("x")
User
.where(handle: params[:handle].delete_prefix("x"))
Expand All @@ -45,17 +45,20 @@ def show_user
else
User.find_by(handle: params[:handle])
end
if @user
user_data = @user.to_frontend
user_data[:altUsers] = @user.alt_users.map(&:to_frontend)
user_data[:discord] = {
displayName: @user.discord_display_name,
username: @user.discord_username,
avatar: @user.discord_avatar
}
user_data[:warnCount] = @user.warn_count

render json: { code: "ok", user: user_data }
if user
render json: {
code: "ok",
user: {
altUsers: user.alt_users.map(&:to_frontend),
discord: {
displayName: user.discord_display_name,
username: user.discord_username,
avatar: user.discord_avatar
},
warnCount: user.warn_count,
owner: (user.to_frontend if params[:handle].start_with?("x"))
}
}
else
render json: { code: "not_found" }, status: :not_found
end
Expand Down
6 changes: 3 additions & 3 deletions backend/app/controllers/api/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Api
class UsersController < FrontendController
def show
params.require(:handle)
@user =
user =
if params[:handle].start_with?("x")
User
.where(handle: params[:handle].delete_prefix("x"))
Expand All @@ -12,8 +12,8 @@ def show
else
User.find_by(handle: params[:handle])
end
if @user
render json: { code: "ok", user: @user.to_frontend }
if user
render json: { code: "ok", user: user.to_frontend }
else
render json: { code: "not_found" }, status: :not_found
end
Expand Down
8 changes: 1 addition & 7 deletions frontend/app/routes/charts.$name._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ import {
import { Link, useLoaderData, useNavigate, useParams } from "@remix-run/react";
import clsx from "clsx";
import { pathcat } from "pathcat";
import {
Fragment,
createElement,
useCallback,
useEffect,
useState,
} from "react";
import { Fragment, useCallback, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import ChartSection from "~/components/ChartSection";
import Checkbox from "~/components/Checkbox";
Expand Down
38 changes: 27 additions & 11 deletions frontend/app/routes/users.$handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import {
defer,
} from "@remix-run/node";
import { Link, useLoaderData } from "@remix-run/react";
import clsx from "clsx";
import { pathcat } from "pathcat";
import { createElement, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { useEffect, useState } from "react";
import { Trans, useTranslation } from "react-i18next";
import ChartSection from "~/components/ChartSection";
import { backendUrl, host } from "~/lib/config.server.ts";
import { useSession } from "~/lib/contexts.ts";
Expand Down Expand Up @@ -93,13 +92,12 @@ const UserPage = () => {
const { t } = useTranslation("user");
const { userData, userCharts } = useLoaderData<typeof loader>();

const random = useRandomValue();

const session = useSession();

const [secretUserInfo, setSecretUserInfo] = useState<{
discord: DiscordInfo;
warnCount: number;
owner: User | null;
} | null>(null);

useEffect(() => {
Expand Down Expand Up @@ -138,10 +136,22 @@ const UserPage = () => {

{secretUserInfo && (
<p className="text-md mt-4 card">
{t("secretUserInfo", {
discord: secretUserInfo.discord.username,
warn: secretUserInfo.warnCount,
})}
<Trans t={t} i18nKey="secretUserInfo">
{secretUserInfo.owner ? (
<Link
to={`/users/${secretUserInfo.owner.handle}`}
/>
) : (
<span />
)}
{{
discord: secretUserInfo.discord.username,
warn: secretUserInfo.warnCount,
owner: secretUserInfo.owner
? `${secretUserInfo.owner.name}#${secretUserInfo.owner.handle}`
: "-",
}}
</Trans>
</p>
)}
<p className="flex-grow mt-4 mr-4 whitespace-pre-wrap break-words w-full">
Expand All @@ -155,9 +165,15 @@ const UserPage = () => {
style={{ backgroundColor: userData.bgColor }}
>
{userData.handle.startsWith("x") ? (
<PersonRegular className="w-4/5 h-4/5" style={{ color: userData.fgColor }} />
<PersonRegular
className="w-4/5 h-4/5"
style={{ color: userData.fgColor }}
/>
) : (
<PersonFilled className="w-4/5 h-4/5" style={{ color: userData.fgColor }} />
<PersonFilled
className="w-4/5 h-4/5"
style={{ color: userData.fgColor }}
/>
)}
</div>
<div className="flex flex-col w-32 md:w-40 mt-4 text-center gap-2">
Expand Down
10 changes: 9 additions & 1 deletion frontend/app/routes/users.alts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,15 @@ const MyAlts = () => {
return;
}
newNameInput.current.value = "";
}, [isSubmitting, myFetch, setIsSubmitting]);
setSession((before: Session | undefined) => {
if (!before?.loggedIn) return before;
return {
...before,

altUsers: [...before.altUsers, resultData.data],
};
});
}, [isSubmitting, myFetch, setIsSubmitting, setSession]);

const editNameInput = useRef<HTMLInputElement>(null);
const [editingUsersHandle, setEditingUsersHandle] = useState<
Expand Down
2 changes: 1 addition & 1 deletion frontend/i18n/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ searchCharts:
user:
totalCharts: "Total charts: {{count}}"
totalLikes: "Total likes: {{count}}"
secretUserInfo: "Discord: {{discord}}, Warnings: {{warn}}"
secretUserInfo: "Discord: {{discord}}, Warnings: {{warn}}, Owner: <0></0>"
userCharts: "Charts by this user"

chartSection:
Expand Down
2 changes: 1 addition & 1 deletion frontend/i18n/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ searchCharts:
user:
totalCharts: "総譜面数:{{count}}"
totalLikes: "総高評価数:{{count}}"
secretUserInfo: "Discord:{{discord}}、警告数:{{warn}}"
secretUserInfo: "Discord:{{discord}}、警告数:{{warn}}、本名義:<0>{{owner}}</0>"
userCharts: "この作者の譜面"

chartSection:
Expand Down

0 comments on commit 1a4a200

Please sign in to comment.