Skip to content
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

세부 목표 정하기 & 만다라트 완성 기능 #33

Closed
wants to merge 20 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
feat: 완성된 만다라트 보여주기
sumi-0011 committed Apr 28, 2023
commit 815da78670ef1e9271dc7450dc65cc6c4ca18580
37 changes: 37 additions & 0 deletions src/app/create/complete/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use client';

import { MandalartCarousel } from '@/components/mandalart';
import useDidMount from '@/hooks/use-did-mount';
import { MandalartPartType } from '@/types/mandalart';
import { BranchesType, CreateStorageType, getCreateStorage } from '@/utils/storage';
import { useState } from 'react';

function CreateCompletePage() {
const [contents, setContents] = useState<MandalartPartType[]>([]);

const initSetting = () => {
const data = getCreateStorage() as CreateStorageType;

if (data) {
const mainContent = {
mainContent: data['full-goal'],
subContents: data.branches.map(({ title }: BranchesType) => title),
};
const subContents = data.branches.map(({ title, details }: BranchesType) => ({
mainContent: title,
subContents: details,
}));
setContents([mainContent, ...subContents]);
}
};

useDidMount(initSetting);

return (
<div>
<MandalartCarousel contents={contents} theme='primary' isFullMandalart />
</div>
);
}

export default CreateCompletePage;
2 changes: 1 addition & 1 deletion src/app/create/detailed-goals/page.tsx
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ export default function DetailedGoalsPage() {
};

const init_setting = () => {
const keyGoals = getCreateStorage('key-goal');
const keyGoals = getCreateStorage('key-goal') as string[];

const newContents = keyGoals.map((content: string) => ({
mainContent: content,
2 changes: 1 addition & 1 deletion src/app/create/key-goals/page.tsx
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ export default function KeyGoalsPage() {
};

useEffect(() => {
const mainContent = getCreateStorage(FULL_GOAL);
const mainContent = getCreateStorage(FULL_GOAL) as string;
if (mainContent) {
setMainContent(mainContent);
}
16 changes: 13 additions & 3 deletions src/components/mandalart/mandalart-carousel.tsx
Original file line number Diff line number Diff line change
@@ -10,10 +10,12 @@ import { useEffect } from 'react';
interface MandalartCarouselProps {
contents: MandalartPartType[];
theme: MandalartThemeType;
handleCurrentPart: (partIndex: number) => void;

isFullMandalart?: boolean;

onClick?: (id: number) => void;
handleTileClick?: (partIndex: number, tileIndex: number) => void;
handleCurrentPart?: (partIndex: number) => void;
}

export function MandalartCarousel({
@@ -22,6 +24,7 @@ export function MandalartCarousel({
onClick,
handleTileClick,
handleCurrentPart,
isFullMandalart,
}: MandalartCarouselProps) {
const [emblaRef, emblaApi] = useEmblaCarousel();
const isMounted = useMount();
@@ -30,20 +33,27 @@ export function MandalartCarousel({
if (emblaApi) {
emblaApi.on('select', () => {
const index = emblaApi.selectedScrollSnap();
handleCurrentPart(index);
handleCurrentPart && handleCurrentPart(index);
});
}
}, [emblaApi, handleCurrentPart]);

useEffect(() => {
if (emblaApi) {
emblaApi.reInit();
}
}, [emblaApi, contents]);

return (
<Carousel isMounted={isMounted.current}>
<CarouselViewport ref={emblaRef}>
<CarouselContainer gap={10}>
{contents.map((subContent, idx) => {
const isMainPart = idx === 0 && isFullMandalart;
return (
<div key={'sub' + idx} onClick={() => onClick && onClick(idx)}>
<MandalartPart
theme={MANDALART_FULL_THEME[theme].sub}
theme={isMainPart ? MANDALART_FULL_THEME[theme].main : MANDALART_FULL_THEME[theme].sub}
contents={subContent}
onTileClick={(tileIndex) => handleTileClick && handleTileClick(idx, tileIndex)}
/>
15 changes: 11 additions & 4 deletions src/utils/storage.ts
Original file line number Diff line number Diff line change
@@ -8,12 +8,17 @@ export const DETAILED_GOAL = 'detailed-goals';

type CreateKeyType = typeof KEY_GOAL | typeof FULL_GOAL | typeof DETAILED_GOAL;

interface BranchesType {
export interface BranchesType {
title: string;
details: string[];
}

const INIT_CREATE_STORAGE = {
export interface CreateStorageType {
'full-goal': string;
'branches': BranchesType[];
}

const INIT_CREATE_STORAGE: CreateStorageType = {
'full-goal': '',
'branches': [],
};
@@ -48,19 +53,21 @@ export const setCreateStorage = (key: CreateKeyType, value: string | any) => {
}
};

export const getCreateStorage = (key?: string) => {
export const getCreateStorage = (key?: string): CreateStorageType | string | string[] | null => {
if (typeof window !== undefined) {
const item = window.sessionStorage.getItem(CREATE_STORAGE_KEY);
const obj = item ? JSON.parse(item) : INIT_CREATE_STORAGE;
if (!key) return obj;

if (key === FULL_GOAL) {
console.log(' ', obj['full-goal']);
return obj['full-goal'];
}
if (key === KEY_GOAL) {
return obj['branches'].map((item: BranchesType) => item.title);
}

return obj[key];
}

return null;
};