Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// comlog 화면으로 옮기는 동안 바로 보이는 자리 (주소가 먼저 바뀌어 회차 칸이 누르자마자 열림)
export default function ComlogLoading() {
return (
<div
aria-busy="true"
className="flex flex-1 items-center justify-center py-20"
>
<span className="size-5 animate-spin rounded-full border-2 border-line border-t-ink-faint" />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { notFound } from 'next/navigation';
import { after } from 'next/server';
import ComlogProjectEditor from '@/components/studio/comlog-project-editor';
import { requireSession } from '@/lib/auth/session';
import {
Expand Down Expand Up @@ -30,7 +31,9 @@ export default async function ComlogProjectPage({
}

// GitHub 링크 켜기 가능 여부가 저장소 공개 여부를 따르므로 열 때 맞춤 (실패해도 기존 값으로 진행)
await refreshProjectRepoPrivacy(user.id, repositoryId);
// - GitHub 호출을 기다리면 화면이 늦게 열려서 응답을 보낸 뒤에 맞춤 (이번 화면은 저장된 값, 다음 화면부터 반영)
// - 공개 화면의 GitHub 링크는 그릴 때마다 저장된 공개 여부를 다시 보므로 늦게 맞춰도 안전
after(() => refreshProjectRepoPrivacy(user.id, repositoryId));
const data = await getComlogEditorData(user.id, repositoryId);

if (!data) {
Expand Down
8 changes: 2 additions & 6 deletions components/comlog/project-intro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ProjectStatusBadge,
UnlistedBadge,
} from '@/components/comlog/project-badges';
import GithubIcon from '@/components/shared/github-icon';
import type { ComlogProjectView } from '@/lib/comlog/queries';

interface ProjectIntroProps {
Expand Down Expand Up @@ -104,12 +105,7 @@ const ProjectIntro = ({ project, isOwner }: ProjectIntroProps) => {
aria-label={t`${name} GitHub 저장소`}
className={LINK_CLASS}
>
<Image
src="/images/main/github-16.svg"
alt=""
width={16}
height={16}
/>
<GithubIcon className="size-4" />
GitHub
</a>
)}
Expand Down
36 changes: 24 additions & 12 deletions components/dashboard/repository-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const RepositoryCard = ({ repository }: RepositoryCardProps) => {
license,
draftCount,
id,
comlogPath,
} = repository;
const hasDrafts = draftCount > 0;

Expand Down Expand Up @@ -106,18 +107,29 @@ const RepositoryCard = ({ repository }: RepositoryCardProps) => {
/>
<Plural value={draftCount} other="초안 #개" />
</p>
<LocalizedLink
href={`/dashboard/repositories/${id}/drafts`}
className="flex items-center gap-2 text-[12px] leading-[normal] font-medium whitespace-nowrap text-brand"
>
<Trans>초안 보기</Trans>
<Image
src="/images/dashboard/arrow-right.svg"
alt=""
width={15}
height={15}
/>
</LocalizedLink>
<div className="flex items-center gap-4">
{/* 내 comlog 프로젝트 페이지 바로가기 (비공개여도 작성자는 볼 수 있음) */}
{comlogPath && (
<LocalizedLink
href={comlogPath}
className="text-[12px] leading-[normal] font-medium whitespace-nowrap text-ink-muted hover:text-ink"
>
<Trans>comlog 보기</Trans>
</LocalizedLink>
)}
<LocalizedLink
href={`/dashboard/repositories/${id}/drafts`}
className="flex items-center gap-2 text-[12px] leading-[normal] font-medium whitespace-nowrap text-brand"
>
<Trans>초안 보기</Trans>
<Image
src="/images/dashboard/arrow-right.svg"
alt=""
width={15}
height={15}
/>
</LocalizedLink>
</div>
</div>
</article>
);
Expand Down
20 changes: 20 additions & 0 deletions components/shared/github-icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
interface GithubIconProps {
className?: string;
}

// GitHub 아이콘 (선 색이 글자색을 따름, 흰색 고정 이미지는 밝은 배경에서 보이지 않아서)
const GithubIcon = ({ className }: GithubIconProps) => (
<svg
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
strokeWidth={1.6}
strokeLinecap="round"
aria-hidden="true"
className={className}
>
<path d="M5.99959 14.6672V12.0003C5.95292 11.587 5.98625 11.1669 6.09959 10.7669C6.21293 10.3669 6.40628 9.99349 6.66629 9.6668C4.66618 9.6668 2.66607 8.33336 2.66607 5.99984C2.61171 5.1683 2.84733 4.34363 3.33277 3.66632C3.13276 2.89959 3.13276 2.09953 3.33277 1.3328C3.33277 1.3328 3.99948 1.3328 5.33288 2.33288C7.09298 1.99952 8.90642 1.99952 10.6665 2.33288C11.9999 1.3328 12.6666 1.3328 12.6666 1.3328C12.8533 2.09953 12.8533 2.89959 12.6666 3.66632C13.1533 4.34637 13.3867 5.16644 13.3333 5.99984C13.3333 8.33336 11.3332 9.6668 9.33311 9.6668C9.85309 10.3269 10.0926 11.1651 9.99981 12.0003V14.6672M5.99959 12.0003C2.99275 13.3338 2.66621 10.6669 1.3328 10.6669" />
</svg>
);

export default GithubIcon;
32 changes: 20 additions & 12 deletions components/studio/comlog-project-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,9 @@ const ComlogProjectEditor = ({ data }: ComlogProjectEditorProps) => {
const [problem, setProblem] = useState<ComlogFormProblem | null>(null);
const [notice, setNotice] = useState<SaveNotice>(null);
const [isPending, startTransition] = useTransition();
const canOpenPublicPage =
project.enabled && !project.isHidden && project.visibility !== 'private';
// 작성자는 비공개 프로젝트 페이지도 볼 수 있으므로 공개 범위와 상관없이 바로가기를 둠
// (꺼져 있거나 관리자가 숨긴 프로젝트는 작성자에게도 404 라 숨김)
const canOpenProjectPage = project.enabled && !project.isHidden;

const update = (patch: Partial<ComlogProjectForm>) => {
setForm((previous) => ({ ...previous, ...patch }));
Expand Down Expand Up @@ -452,16 +453,23 @@ const ComlogProjectEditor = ({ data }: ComlogProjectEditorProps) => {
<h1 className="text-[20px] leading-[normal] font-bold tracking-[-0.3px] text-ink">
<Trans>프로젝트 소개</Trans>
</h1>
{canOpenPublicPage && (
<LocalizedAnchor
href={getComlogProjectPath(project)}
target="_blank"
rel="noreferrer"
className={`h-8 text-[12px] leading-[normal] font-medium ${OUTLINE_BUTTON_CLASS}`}
>
<Trans>공개 페이지 보기</Trans>
<ExternalLink aria-hidden size={14} strokeWidth={2.25} />
</LocalizedAnchor>
{canOpenProjectPage && (
<div className="flex items-center gap-2">
{project.visibility === 'private' && (
<span className="text-[12px] leading-[normal] text-ink-faint">
<Trans>비공개 · 나만 볼 수 있어요</Trans>
</span>
)}
<LocalizedAnchor
href={getComlogProjectPath(project)}
target="_blank"
rel="noreferrer"
className={`h-8 text-[12px] leading-[normal] font-medium ${OUTLINE_BUTTON_CLASS}`}
>
<Trans>내 comlog 보기</Trans>
<ExternalLink aria-hidden size={14} strokeWidth={2.25} />
</LocalizedAnchor>
</div>
)}
</header>

Expand Down
4 changes: 4 additions & 0 deletions lib/comlog/initial-project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ describe('buildInitialProject', () => {
expect(project.name).toBe('My-Repo');
expect(project.slug).toBe('my-repo');
});

it('처음 켜면 비공개로 시작함 (소개를 다듬고 직접 공개하도록)', () => {
expect(buildInitialProject(snapshot()).visibility).toBe('private');
});
});
4 changes: 3 additions & 1 deletion lib/comlog/initial-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ export const buildInitialProject = (
snapshot: RepoSnapshot,
): Pick<
ComlogProjectRow,
'name' | 'slug' | 'intro' | 'demoUrl' | 'techStack'
'name' | 'slug' | 'intro' | 'demoUrl' | 'techStack' | 'visibility'
> => ({
// 저장소 정보로 채운 소개를 다듬기 전에는 남에게 보이지 않게 비공개로 시작 (공개는 사용자가 직접)
visibility: 'private',
name: snapshot.name,
slug: createPostSlug(snapshot.name),
intro: snapshot.description ?? '',
Expand Down
24 changes: 24 additions & 0 deletions lib/comlog/paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
import {
getComlogEntryPath,
getComlogProjectPath,
getOwnerComlogPath,
getEncodedComlogEntryPath,
getEncodedComlogProjectPath,
parseComlogEntryParam,
Expand Down Expand Up @@ -109,3 +110,26 @@ describe('parseComlogProjectParam / parseComlogEntryParam', () => {
expect(parseComlogEntryParam(`%E0%A4%A-${POST_ID}`)).toBeNull();
});
});

describe('getOwnerComlogPath', () => {
const project = {
id: '11111111-2222-3333-4444-555555555555',
slug: 'my-app',
};

it('켜져 있고 숨겨지지 않았으면 공개 범위와 상관없이 프로젝트 주소', () => {
expect(
getOwnerComlogPath({ ...project, enabled: true, bannedAt: null }),
).toBe(getComlogProjectPath(project));
});

it('comlog 를 켠 적이 없거나 꺼져 있거나 숨겨졌으면 null (작성자에게도 404 라서)', () => {
expect(getOwnerComlogPath(null)).toBeNull();
expect(
getOwnerComlogPath({ ...project, enabled: false, bannedAt: null }),
).toBeNull();
expect(
getOwnerComlogPath({ ...project, enabled: true, bannedAt: new Date() }),
).toBeNull();
});
});
12 changes: 12 additions & 0 deletions lib/comlog/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ const joinSegment = ({ id, slug }: PathTarget) =>
const entrySegment = (entry: PathTarget) =>
getPostPath(entry).slice('/posts/'.length);

/**
* 작성자 본인이 쓰는 프로젝트 바로가기 주소 (대시보드 카드)
* - 작성자는 비공개 프로젝트도 볼 수 있으므로 공개 범위는 보지 않음
* - comlog 를 켠 적이 없거나, 꺼져 있거나, 관리자가 숨긴 프로젝트는 작성자에게도 404 라 null
*/
export const getOwnerComlogPath = (
project: (PathTarget & { enabled: boolean; bannedAt: Date | null }) | null,
): string | null =>
project && project.enabled && project.bannedAt === null
? getComlogProjectPath(project)
: null;

/** 프로젝트 페이지의 로케일 없는 주소. slug 가 비면 ID 만 쓴다. */
export const getComlogProjectPath = (project: PathTarget): string =>
`${COMLOG_PATH}/${joinSegment(project)}`;
Expand Down
27 changes: 27 additions & 0 deletions lib/dashboard/queries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'server-only';
import { and, desc, eq, sql } from 'drizzle-orm';
import { db } from '@/lib/db';
import { getOwnerComlogPath } from '@/lib/comlog/paths';
import {
comlogProject,
draft,
githubInstallation,
githubRepository,
Expand All @@ -24,6 +26,8 @@ export interface DashboardRepository {
license: string | null;
// 이 저장소에 만든 초안 수
draftCount: number;
// 내 comlog 프로젝트 페이지 주소 (comlog 를 켜지 않았거나 꺼져 있거나 숨겨졌으면 null)
comlogPath: string | null;
}

export interface DashboardRepositoryPage {
Expand Down Expand Up @@ -98,6 +102,10 @@ export const getDashboardRepositoryPage = async (
accountType: githubInstallation.accountType,
branch: userRepository.branch,
updatedAt: userRepository.updatedAt,
comlogId: comlogProject.id,
comlogSlug: comlogProject.slug,
comlogEnabled: comlogProject.enabled,
comlogBannedAt: comlogProject.bannedAt,
draftCount: db.$count(
draft,
and(
Expand All @@ -115,6 +123,13 @@ export const getDashboardRepositoryPage = async (
githubInstallation,
eq(githubRepository.installationId, githubInstallation.id),
)
.leftJoin(
comlogProject,
and(
eq(comlogProject.userId, userRepository.userId),
eq(comlogProject.repositoryId, userRepository.repositoryId),
),
)
.where(
and(
eq(userRepository.userId, userId),
Expand All @@ -141,6 +156,18 @@ export const getDashboardRepositoryPage = async (
branch: row.branch,
license: row.license,
draftCount: row.draftCount,
comlogPath: getOwnerComlogPath(
row.comlogId === null ||
row.comlogSlug === null ||
row.comlogEnabled === null
? null
: {
id: row.comlogId,
slug: row.comlogSlug,
enabled: row.comlogEnabled,
bannedAt: row.comlogBannedAt,
},
),
})),
nextCursor:
rows.length > DASHBOARD_PAGE_SIZE && last
Expand Down
Loading