code
stringlengths
41
34.3k
lang
stringclasses
8 values
review
stringlengths
1
4.74k
@@ -0,0 +1,70 @@ +package christmas.domain.order.menu; + +import java.util.Arrays; +import java.util.Map; + +public enum Menu { + + // ๊ธฐํƒ€ + NONE("์—†์Œ", 0, MenuType.NONE), + + // ์—ํ”ผํƒ€์ด์ € + MUSHROOM_SOUP("์–‘์†ก์ด ์Šคํ”„", 6_000, MenuType.APPETIZER), + TAPAS("ํƒ€ํŒŒ์Šค", 5_500, MenuType.APPETIZER), + CAESAR_SALAD("์‹œ์ € ์ƒ๋Ÿฌ๋“œ", 8_000, MenuType.APPETIZER), + + // ๋ฉ”์ธ + T_BONE_STEAK("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ", 55_000, MenuType.MAIN), + BBQ_RIBS("๋ฐ”๋น„ํ๋ฆฝ", 54_000, MenuType.MAIN), + SEAFOOD_PASTA("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 35_000, MenuType.MAIN), + CHRISTMAS_PASTA("ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€", 25_000, MenuType.MAIN), + + // ๋””์ €ํŠธ + CHOCOLATE_CAKE("์ดˆ์ฝ”์ผ€์ดํฌ", 15_000, MenuType.DESSERT), + ICE_CREAM("์•„์ด์Šคํฌ๋ฆผ", 5_000, MenuType.DESSERT), + + // ์Œ๋ฃŒ + ZERO_COKE("์ œ๋กœ์ฝœ๋ผ", 3_000, MenuType.DRINK), + RED_WINE("๋ ˆ๋“œ์™€์ธ", 60_000, MenuType.DRINK), + CHAMPAGNE("์ƒดํŽ˜์ธ", 25_000, MenuType.DRINK); + + private final String name; + private final int price; + private final MenuType type; + + Menu(String name, int price, MenuType type) { + this.name = name; + this.price = price; + this.type = type; + } + + public static Menu findByName(String name) { + return Arrays.stream(values()) + .filter(menu -> menu.name.equals(name)) + .findAny() + .orElse(Menu.NONE); + } + + public static boolean isGiftMenu(Menu menu) { + return getGiftMenus() + .keySet() + .stream() + .anyMatch(giftMenu -> giftMenu.equals(menu)); + } + + public static Map<Menu, Quantity> getGiftMenus() { + return Map.of(Menu.CHAMPAGNE, Quantity.create(1)); + } + + public String getName() { + return name; + } + + public int getPrice() { + return price; + } + + public MenuType getType() { + return type; + } +}
Java
์ œ ๊ฒฝ์šฐ 1์›” ์ƒˆํ•ด ์ด๋ฒคํŠธ์— ์ด๋ฒคํŠธ๊ฐ€ ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ๋‹ค ๊ฐ€์ •ํ•ด Menu ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์„ ์–ธํ•œ ๋’ค ์—ํ”ผํƒ€์ด์ €, ๋ฉ”์ธ, ๋””์ €ํŠธ, ์Œ๋ฃŒ๋ณ„๋กœ ENUM ๊ฐ์ฒด๋ฅผ ๊ฐ๊ฐ ๋”ฐ๋กœ ์„ ์–ธํ–ˆ์Šต๋‹ˆ๋‹ค! ์ฐธ๊ณ ํ•˜์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”! ``` java public interface Menu { int discount(int day); String getName(); int getPrice(); } ``` ``` java public enum Appetizer implements Menu { MUSHROOM_SOUP("์–‘์†ก์ด์ˆ˜ํ”„", 6000), TAPAS("ํƒ€ํŒŒ์Šค", 5500), CAESAR_SALAD("์‹œ์ €์ƒ๋Ÿฌ๋“œ", 8000); private final String name; private final int price; Appetizer(String name, int price) { this.name = name; this.price = price; } @Override public int discount(int day) { return 0; } @Override public String getName() { return name; } @Override public int getPrice() { return price; } } ```
@@ -0,0 +1,40 @@ +package christmas.domain.order.menu; + +import christmas.validator.OrderValidator; + +import java.util.Objects; + +public class Quantity { + + private final Integer quantity; + + private Quantity(Integer quantity) { + validate(quantity); + this.quantity = quantity; + } + + public static Quantity create(Integer quantity) { + return new Quantity(quantity); + } + + private void validate(Integer quantity) { + OrderValidator.validateIsEachQuantityGreaterThanCondition(quantity); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Quantity quantity1 = (Quantity) o; + return Objects.equals(quantity, quantity1.quantity); + } + + @Override + public int hashCode() { + return Objects.hash(quantity); + } + + public Integer getPrimitiveQuantity() { + return quantity; + } +}
Java
int๊ฐ€ ์•„๋‹Œ Integer๋กœ ์„ ์–ธํ•ด์ฃผ์‹œ๋Š” ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!๐Ÿค”
@@ -0,0 +1,18 @@ +package christmas.domain.discount; + +import christmas.domain.order.Day; +import christmas.domain.order.Order; + +public interface Discount { + + public void calculateDiscountAmount(Order order, Day day); + + public void checkIsAvailableDiscount(Order order, Day day); + + public String getName(); + + public int getDiscountAmount(); + + public boolean getIsAvailable(); + +}
Java
๋‹คํ˜•์„ฑ์„ ์ด์šฉํ•˜๋Š” ์ •๋ง ์ข‹์€ ๋ฐฉ๋ฒ•์ด๋„ค์š” ๋ฐฐ์šฐ๊ณ ๊ฐ‘๋‹ˆ๋‹ค!
@@ -0,0 +1,119 @@ +package christmas.validator; + +import christmas.domain.order.menu.Menu; +import christmas.dto.request.OrderRequest; +import christmas.util.InputUtil; +import christmas.exception.ErrorMessage; + +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +public class InputValidator { + + private InputValidator() { + + } + + /* + ์‹๋‹น ์˜ˆ์ƒ ๋ฐฉ๋ฌธ ๋‚ ์งœ ์ž…๋ ฅ๊ฐ’ ๊ฒ€์ฆ + */ + public static void validateEstimatedVisitingDateInput(String input) { + validateIsBlank(input); + validateIsDigit(input); + } + + /* + ์ฃผ๋ฌธ ๋ฉ”๋‰ด ๋ฐ ๊ฐœ์ˆ˜ ์ž…๋ ฅ๊ฐ’ ์ „์ฒด ๊ฒ€์ฆ + */ + public static void validateOrder(String input) { + validateOrderInput(input); + validateOrderRequest(input); + } + + /* + ์ฃผ๋ฌธ ๋ฉ”๋‰ด ๋ฐ ๊ฐœ์ˆ˜ ์ž…๋ ฅ๊ฐ’ ๋ถ„๋ฆฌ ์ „ ๊ฒ€์ฆ + */ + private static void validateOrderInput(String input) { + validateIsBlank(input); + validateIsRightFormat(input); + } + + private static void validateIsRightFormat(String input) { + if (!isRightFormat(input)) { + throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage()); + } + } + + private static boolean isRightFormat(String input) { + String regex = ErrorMessage.ORDER_INPUT_REGEX.getMessage(); + return Pattern.compile(regex) + .matcher(input) + .matches(); + } + + /* + ์ฃผ๋ฌธ ๋ฉ”๋‰ด ๋ฐ ๊ฐœ์ˆ˜ ์ž…๋ ฅ๊ฐ’ ๋ถ„๋ฆฌ ํ›„ ๊ฒ€์ฆ + */ + private static void validateOrderRequest(String input) { + List<OrderRequest> orderRequests = InputUtil.parseOrder(input); + validateIsExistingMenu(orderRequests); + validateHasDuplicatedMenu(orderRequests); + } + + private static void validateIsExistingMenu(List<OrderRequest> orderRequests) { + if (!isExistingMenu(orderRequests)) { + throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage()); + } + } + + private static boolean isExistingMenu(List<OrderRequest> orderRequests) { + List<String> menuNames = getMenuNames(); + return orderRequests.stream() + .map(OrderRequest::getMenuName) + .allMatch(menuNames::contains); + } + + private static List<String> getMenuNames() { + return Arrays.stream(Menu.values()) + .map(Menu::getName) + .toList(); + } + + private static void validateHasDuplicatedMenu(List<OrderRequest> orderRequests) { + if (hasDuplicatedMenu(orderRequests)) { + throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage()); + } + } + + private static boolean hasDuplicatedMenu(List<OrderRequest> orderRequests) { + return orderRequests.stream() + .map(OrderRequest::getMenuName) + .distinct() + .count() != orderRequests.size(); + } + + /* + ๊ณตํ†ต ๊ฒ€์ฆ + */ + private static void validateIsBlank(String input) { + if (input.isBlank()) { + throw new IllegalArgumentException(ErrorMessage.INPUT_IS_BLANK.getMessage()); + } + } + + private static void validateIsDigit(String input) { + if (!isDigit(input)) { + throw new IllegalArgumentException(ErrorMessage.INVALID_DATE.getMessage()); + } + } + + private static boolean isDigit(String input) { + try { + Integer.parseInt(input); + return true; + } catch (NumberFormatException e) { + return false; + } + } +}
Java
ํ˜„์žฌ InputValidator ๊ฐ์ฒด์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๋ฉ”์†Œ๋“œ๋“ค์€ ๋Œ€๋ถ€๋ถ„ ํŠน์ • ๋„๋ฉ”์ธ์˜ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋Š”๋ฐ ์ธ์Šคํ„ด์Šค ๋ฉ”์†Œ๋“œ๋กœ ์‚ฌ์šฉํ•˜๋Š”๊ฑด ์–ด๋– ์‹ ๊ฐ€์š”??
@@ -0,0 +1,40 @@ +package christmas.domain.order.menu; + +import christmas.validator.OrderValidator; + +import java.util.Objects; + +public class Quantity { + + private final Integer quantity; + + private Quantity(Integer quantity) { + validate(quantity); + this.quantity = quantity; + } + + public static Quantity create(Integer quantity) { + return new Quantity(quantity); + } + + private void validate(Integer quantity) { + OrderValidator.validateIsEachQuantityGreaterThanCondition(quantity); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Quantity quantity1 = (Quantity) o; + return Objects.equals(quantity, quantity1.quantity); + } + + @Override + public int hashCode() { + return Objects.hash(quantity); + } + + public Integer getPrimitiveQuantity() { + return quantity; + } +}
Java
ํฐ ์˜๋ฏธ๊ฐ€ ์žˆ๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๊ณ , null ์ฒ˜๋ฆฌ์— ๋Œ€๋น„ํ•˜์—ฌ Integer๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์‚ฌ์‹ค ์ž…๋ ฅ๊ฐ’ ๊ฒ€์ฆ ๋กœ์ง์ด ์ด๋ฏธ ์žˆ์–ด์„œ null์ด ๋“ค์–ด๊ฐˆ ์ผ์€ ์—†์„ ๊ฒƒ ๊ฐ™๊ธฐ๋„ ํ•˜๋„ค์š”!
@@ -0,0 +1,119 @@ +package christmas.validator; + +import christmas.domain.order.menu.Menu; +import christmas.dto.request.OrderRequest; +import christmas.util.InputUtil; +import christmas.exception.ErrorMessage; + +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +public class InputValidator { + + private InputValidator() { + + } + + /* + ์‹๋‹น ์˜ˆ์ƒ ๋ฐฉ๋ฌธ ๋‚ ์งœ ์ž…๋ ฅ๊ฐ’ ๊ฒ€์ฆ + */ + public static void validateEstimatedVisitingDateInput(String input) { + validateIsBlank(input); + validateIsDigit(input); + } + + /* + ์ฃผ๋ฌธ ๋ฉ”๋‰ด ๋ฐ ๊ฐœ์ˆ˜ ์ž…๋ ฅ๊ฐ’ ์ „์ฒด ๊ฒ€์ฆ + */ + public static void validateOrder(String input) { + validateOrderInput(input); + validateOrderRequest(input); + } + + /* + ์ฃผ๋ฌธ ๋ฉ”๋‰ด ๋ฐ ๊ฐœ์ˆ˜ ์ž…๋ ฅ๊ฐ’ ๋ถ„๋ฆฌ ์ „ ๊ฒ€์ฆ + */ + private static void validateOrderInput(String input) { + validateIsBlank(input); + validateIsRightFormat(input); + } + + private static void validateIsRightFormat(String input) { + if (!isRightFormat(input)) { + throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage()); + } + } + + private static boolean isRightFormat(String input) { + String regex = ErrorMessage.ORDER_INPUT_REGEX.getMessage(); + return Pattern.compile(regex) + .matcher(input) + .matches(); + } + + /* + ์ฃผ๋ฌธ ๋ฉ”๋‰ด ๋ฐ ๊ฐœ์ˆ˜ ์ž…๋ ฅ๊ฐ’ ๋ถ„๋ฆฌ ํ›„ ๊ฒ€์ฆ + */ + private static void validateOrderRequest(String input) { + List<OrderRequest> orderRequests = InputUtil.parseOrder(input); + validateIsExistingMenu(orderRequests); + validateHasDuplicatedMenu(orderRequests); + } + + private static void validateIsExistingMenu(List<OrderRequest> orderRequests) { + if (!isExistingMenu(orderRequests)) { + throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage()); + } + } + + private static boolean isExistingMenu(List<OrderRequest> orderRequests) { + List<String> menuNames = getMenuNames(); + return orderRequests.stream() + .map(OrderRequest::getMenuName) + .allMatch(menuNames::contains); + } + + private static List<String> getMenuNames() { + return Arrays.stream(Menu.values()) + .map(Menu::getName) + .toList(); + } + + private static void validateHasDuplicatedMenu(List<OrderRequest> orderRequests) { + if (hasDuplicatedMenu(orderRequests)) { + throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage()); + } + } + + private static boolean hasDuplicatedMenu(List<OrderRequest> orderRequests) { + return orderRequests.stream() + .map(OrderRequest::getMenuName) + .distinct() + .count() != orderRequests.size(); + } + + /* + ๊ณตํ†ต ๊ฒ€์ฆ + */ + private static void validateIsBlank(String input) { + if (input.isBlank()) { + throw new IllegalArgumentException(ErrorMessage.INPUT_IS_BLANK.getMessage()); + } + } + + private static void validateIsDigit(String input) { + if (!isDigit(input)) { + throw new IllegalArgumentException(ErrorMessage.INVALID_DATE.getMessage()); + } + } + + private static boolean isDigit(String input) { + try { + Integer.parseInt(input); + return true; + } catch (NumberFormatException e) { + return false; + } + } +}
Java
์—ฌํƒœ ํฌ๊ฒŒ ์ƒ๊ฐ์„ ์•ˆ ํ–ˆ๋˜ ๋ถ€๋ถ„์ธ๋ฐ, ์•„๋ฌด๋ž˜๋„ static์„ ๋ถ™์—ฌ์„œ ์•„๋ฌด๋ฐ์„œ๋‚˜ ์“ธ ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค๋Š” ํ•„์š”ํ•œ ๊ณณ์—์„œ๋งŒ ๋ถˆ๋Ÿฌ์™€์„œ ์‚ฌ์šฉํ•˜๋Š” ํŽธ์ด ์žฅ์ ์ด ์žˆ๊ฒ ๋„ค์š”! ์ข‹์€ ์˜๊ฒฌ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ˜„
@@ -0,0 +1,63 @@ +package christmas.controller; + +import christmas.domain.PromotionService; +import christmas.domain.order.Day; +import christmas.domain.order.Order; +import christmas.dto.response.DiscountPreviewResponse; +import christmas.view.InputView; +import christmas.view.OutputView; + +import java.util.function.Supplier; + +public class PromotionController { + + private PromotionController() { + + } + + public static PromotionController create() { + return new PromotionController(); + } + + + public void run() { + printIntroductionMessage(); + + Day day = readWithExceptionHandling(PromotionController::readDay); + Order order = readWithExceptionHandling(PromotionController::readOrder); + PromotionService promotionService = PromotionService.create(order, day); + closeRead(); + + printDiscountPreviewMessage(promotionService); + } + + private static void printIntroductionMessage() { + OutputView.printIntroductionMessage(); + } + + private static <T> T readWithExceptionHandling(Supplier<T> reader) { + while (true) { + try { + return reader.get(); + } catch (IllegalArgumentException exception) { + System.out.println(exception.getMessage()); + } + } + } + + private static Day readDay() throws IllegalArgumentException { + return Day.create(InputView.readEstimatedVisitingDate()); + } + + private static Order readOrder() throws IllegalArgumentException { + return Order.create(InputView.readOrder()); + } + + private static void closeRead() { + InputView.closeRead(); + } + + private static void printDiscountPreviewMessage(PromotionService promotionService) { + OutputView.printDiscountPreviewMessage(DiscountPreviewResponse.from(promotionService)); + } +}
Java
์•„...! ์ œ๊ฐ€ ์ธํ…”๋ฆฌ์ œ์ด์˜ ๋ฉ”์†Œ๋“œ ๋ถ„๋ฆฌ ๋‹จ์ถ•ํ‚ค์ธ option + command + v๋ฅผ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ, ๊ทธ ๊ณผ์ •์—์„œ ์ž๋™์œผ๋กœ static ๋ฉ”์†Œ๋“œ๋กœ ์„ ์–ธ๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ „๋ถ€ ์ง€์›Œ์•ผ๊ฒ ๋„ค์š” ๐Ÿ˜‚
@@ -0,0 +1,40 @@ +package christmas.domain.order; + +import christmas.validator.OrderValidator; + +import java.util.Objects; + +public class Day { + + private final Integer day; + + private Day(Integer day) { + validate(day); + this.day = day; + } + + public static Day create(Integer day) { + return new Day(day); + } + + private void validate(Integer day) { + OrderValidator.validateIsDateInRange(day); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Day day1 = (Day) o; + return Objects.equals(day, day1.day); + } + + @Override + public int hashCode() { + return Objects.hash(day); + } + + public Integer getPrimitiveDay() { + return day; + } +}
Java
๊ฐ VO์—์„œ ์ด๋ฃจ์–ด์ง€๋Š” ๊ฒ€์ฆ์„ ํ•œ ๊ตฐ๋ฐ์—์„œ ๋ชจ์•„ ๊ด€๋ฆฌํ•˜๋ฉด ํŽธ๋ฆฌํ•  ๊ฒƒ์ด๋ผ ์ƒ๊ฐํ•˜์˜€๋Š”๋ฐ, ๋ง์”€์ฃผ์‹  ๊ฒƒ์ฒ˜๋Ÿผ ์บก์Аํ™”๊ฐ€ ๊นจ์ง€๋Š” ๋ฌธ์ œ๋„ ์žˆ์„ ๋ฟ๋”๋Ÿฌ OrderValidator ๊ฐ์ฒด๊ฐ€ ๋น„๋Œ€ํ•ด์ง„๋‹ค๋ฉด ๊ฒฐ๊ตญ์— ๋กœ์ง์„ ๋ถ„๋ฆฌํ•ด์•ผํ•  ๊ฒƒ์ด๊ณ  ์ด๋Ÿฌ๋ฉด ํ•œ ๊ณณ์—์„œ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์žฅ์  ๋˜ํ•œ ์‚ฌ๋ผ์งˆ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฒฐ๊ตญ์—๋Š” ์ œ์ผ ๊ด€๋ จ์„ฑ์ด ๊นŠ์€ VO ๋‚ด๋ถ€์—์„œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ํ•˜๋Š” ๊ฒƒ์ด ๋งž๊ฒ ๋„ค์š”! ์ข‹์€ ์กฐ์–ธ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ˜„
@@ -0,0 +1,74 @@ +package christmas.domain.order; + +import christmas.domain.order.menu.Menu; +import christmas.domain.order.menu.Quantity; +import christmas.dto.request.OrderRequest; +import christmas.dto.response.OrderResponse; +import christmas.util.InputUtil; +import christmas.validator.OrderValidator; + +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class Order { + + Map<Menu, Quantity> Order; + + private Order(List<OrderRequest> orderRequests) { + Map<Menu, Quantity> order = InputUtil.parseOrderRequests(orderRequests); + validate(order); + this.Order = new EnumMap<>(order); + } + + public static Order create(List<OrderRequest> orderRequests) { + return new Order(orderRequests); + } + + private void validate(Map<Menu, Quantity> order) { + OrderValidator.validateHasOnlyDrink(order); + OrderValidator.validateIsTotalQuantityValid(order); + } + + public List<OrderResponse> findOrderResponses() { + return Order + .entrySet() + .stream() + .map(entry -> OrderResponse.of(entry.getKey(), entry.getValue())) + .toList(); + } + + public int calculateInitialPrice() { + return Order + .entrySet() + .stream() + .mapToInt(entry -> getMenuPrice(entry) * getEachQuantity(entry)) + .sum(); + } + + private int getMenuPrice(Map.Entry<Menu, Quantity> entry) { + return entry.getKey().getPrice(); + } + + private Integer getEachQuantity(Map.Entry<Menu, Quantity> entry) { + return entry.getValue().getPrimitiveQuantity(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Order order = (Order) o; + return Objects.equals(getOrder(), order.getOrder()); + } + + @Override + public int hashCode() { + return Objects.hash(getOrder()); + } + + public Map<Menu, Quantity> getOrder() { + return new EnumMap<>(Order); + } +}
Java
์ €๋„ ์ง€๊ธˆ ๋ดค๋„ค์š”ใ…‹ใ…‹ใ… ใ…  private ์„ ์–ธํ•ด์•ผ ๋˜๋Š”๋ฐ ๊นŒ๋จน์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿคฃ
@@ -0,0 +1,70 @@ +package christmas.domain.order.menu; + +import java.util.Arrays; +import java.util.Map; + +public enum Menu { + + // ๊ธฐํƒ€ + NONE("์—†์Œ", 0, MenuType.NONE), + + // ์—ํ”ผํƒ€์ด์ € + MUSHROOM_SOUP("์–‘์†ก์ด ์Šคํ”„", 6_000, MenuType.APPETIZER), + TAPAS("ํƒ€ํŒŒ์Šค", 5_500, MenuType.APPETIZER), + CAESAR_SALAD("์‹œ์ € ์ƒ๋Ÿฌ๋“œ", 8_000, MenuType.APPETIZER), + + // ๋ฉ”์ธ + T_BONE_STEAK("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ", 55_000, MenuType.MAIN), + BBQ_RIBS("๋ฐ”๋น„ํ๋ฆฝ", 54_000, MenuType.MAIN), + SEAFOOD_PASTA("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 35_000, MenuType.MAIN), + CHRISTMAS_PASTA("ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€", 25_000, MenuType.MAIN), + + // ๋””์ €ํŠธ + CHOCOLATE_CAKE("์ดˆ์ฝ”์ผ€์ดํฌ", 15_000, MenuType.DESSERT), + ICE_CREAM("์•„์ด์Šคํฌ๋ฆผ", 5_000, MenuType.DESSERT), + + // ์Œ๋ฃŒ + ZERO_COKE("์ œ๋กœ์ฝœ๋ผ", 3_000, MenuType.DRINK), + RED_WINE("๋ ˆ๋“œ์™€์ธ", 60_000, MenuType.DRINK), + CHAMPAGNE("์ƒดํŽ˜์ธ", 25_000, MenuType.DRINK); + + private final String name; + private final int price; + private final MenuType type; + + Menu(String name, int price, MenuType type) { + this.name = name; + this.price = price; + this.type = type; + } + + public static Menu findByName(String name) { + return Arrays.stream(values()) + .filter(menu -> menu.name.equals(name)) + .findAny() + .orElse(Menu.NONE); + } + + public static boolean isGiftMenu(Menu menu) { + return getGiftMenus() + .keySet() + .stream() + .anyMatch(giftMenu -> giftMenu.equals(menu)); + } + + public static Map<Menu, Quantity> getGiftMenus() { + return Map.of(Menu.CHAMPAGNE, Quantity.create(1)); + } + + public String getName() { + return name; + } + + public int getPrice() { + return price; + } + + public MenuType getType() { + return type; + } +}
Java
๋ฉ”๋‰ด Enum์—๋„ ์ด๋Ÿฐ ์‹์œผ๋กœ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ ์ƒ๊ฐํ•˜์ง€ ๋ชปํ–ˆ๋„ค์š”! ์ฐธ๊ณ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค...!
@@ -0,0 +1,67 @@ +import { Button, Form, Input, Select, Space } from 'antd'; +import { REVIEW_CYCLE_FORM_NAMES, REVIEW_CYCLE_RULES } from './constants'; +import useMembers from '@apis/review/useMembers'; +import { ReviewCycleRequest } from '@apis/review/type'; +import { ReviewCycle } from '@apis/review/entities'; + +interface Props { + onFinish: (values: ReviewCycleRequest) => void; + onReset: () => void; + initialValues?: { + name: ReviewCycle['name']; + reviewees: number[]; + title: ReviewCycle['question']['title']; + description: ReviewCycle['question']['description']; + }; + confirmButtonProps?: { text: string }; + deleteButtonProps?: { text: string; handleClick: () => void }; +} + +export default function ReviewCycleForm({ + onFinish, + onReset, + initialValues, + confirmButtonProps = { text: 'ํ™•์ธ' }, + deleteButtonProps, +}: Props) { + const { members, isLoading } = useMembers(); + + return ( + <Form labelAlign="right" onFinish={onFinish} onReset={onReset} initialValues={initialValues}> + <Form.Item label="๋ฆฌ๋ทฐ ์ •์ฑ… ์ด๋ฆ„" name={REVIEW_CYCLE_FORM_NAMES.name} rules={REVIEW_CYCLE_RULES.reviewCycleName}> + <Input /> + </Form.Item> + + <Form.Item label="๋ฆฌ๋ทฐ ๋ฐ›๋Š” ์‚ฌ๋žŒ" name={REVIEW_CYCLE_FORM_NAMES.reviewees} rules={REVIEW_CYCLE_RULES.reviewees}> + <Select + mode="multiple" + loading={isLoading} + placeholder="๋ฆฌ๋ทฐ ๋ฐ›๋Š” ์‚ฌ๋žŒ์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”." + optionFilterProp="label" + options={members?.map(m => ({ key: m.entityId, label: m.name, value: m.entityId }))} + /> + </Form.Item> + + <Form.Item label="์งˆ๋ฌธ" name={REVIEW_CYCLE_FORM_NAMES.question.title} rules={REVIEW_CYCLE_RULES.questionTitle}> + <Input /> + </Form.Item> + + <Form.Item + label="์งˆ๋ฌธ ์„ค๋ช…" + name={REVIEW_CYCLE_FORM_NAMES.question.description} + rules={REVIEW_CYCLE_RULES.questionDescription} + > + <Input /> + </Form.Item> + <Form.Item style={{ textAlign: 'right' }}> + <Space size={10}> + <Button htmlType="reset">์ทจ์†Œ</Button> + {deleteButtonProps && <Button onClick={deleteButtonProps.handleClick}>{deleteButtonProps.text}</Button>} + <Button type="primary" htmlType="submit"> + {confirmButtonProps.text} + </Button> + </Space> + </Form.Item> + </Form> + ); +}
Unknown
์š”๊ธฐ `form`์€ ์—†์–ด๋„ ๋  ๊ฒƒ ๊ฐ™์•„์š”~
@@ -0,0 +1,67 @@ +import { Button, Form, Input, Select, Space } from 'antd'; +import { REVIEW_CYCLE_FORM_NAMES, REVIEW_CYCLE_RULES } from './constants'; +import useMembers from '@apis/review/useMembers'; +import { ReviewCycleRequest } from '@apis/review/type'; +import { ReviewCycle } from '@apis/review/entities'; + +interface Props { + onFinish: (values: ReviewCycleRequest) => void; + onReset: () => void; + initialValues?: { + name: ReviewCycle['name']; + reviewees: number[]; + title: ReviewCycle['question']['title']; + description: ReviewCycle['question']['description']; + }; + confirmButtonProps?: { text: string }; + deleteButtonProps?: { text: string; handleClick: () => void }; +} + +export default function ReviewCycleForm({ + onFinish, + onReset, + initialValues, + confirmButtonProps = { text: 'ํ™•์ธ' }, + deleteButtonProps, +}: Props) { + const { members, isLoading } = useMembers(); + + return ( + <Form labelAlign="right" onFinish={onFinish} onReset={onReset} initialValues={initialValues}> + <Form.Item label="๋ฆฌ๋ทฐ ์ •์ฑ… ์ด๋ฆ„" name={REVIEW_CYCLE_FORM_NAMES.name} rules={REVIEW_CYCLE_RULES.reviewCycleName}> + <Input /> + </Form.Item> + + <Form.Item label="๋ฆฌ๋ทฐ ๋ฐ›๋Š” ์‚ฌ๋žŒ" name={REVIEW_CYCLE_FORM_NAMES.reviewees} rules={REVIEW_CYCLE_RULES.reviewees}> + <Select + mode="multiple" + loading={isLoading} + placeholder="๋ฆฌ๋ทฐ ๋ฐ›๋Š” ์‚ฌ๋žŒ์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”." + optionFilterProp="label" + options={members?.map(m => ({ key: m.entityId, label: m.name, value: m.entityId }))} + /> + </Form.Item> + + <Form.Item label="์งˆ๋ฌธ" name={REVIEW_CYCLE_FORM_NAMES.question.title} rules={REVIEW_CYCLE_RULES.questionTitle}> + <Input /> + </Form.Item> + + <Form.Item + label="์งˆ๋ฌธ ์„ค๋ช…" + name={REVIEW_CYCLE_FORM_NAMES.question.description} + rules={REVIEW_CYCLE_RULES.questionDescription} + > + <Input /> + </Form.Item> + <Form.Item style={{ textAlign: 'right' }}> + <Space size={10}> + <Button htmlType="reset">์ทจ์†Œ</Button> + {deleteButtonProps && <Button onClick={deleteButtonProps.handleClick}>{deleteButtonProps.text}</Button>} + <Button type="primary" htmlType="submit"> + {confirmButtonProps.text} + </Button> + </Space> + </Form.Item> + </Form> + ); +}
Unknown
์˜ค ์ด๋Ÿฐ ๋ฐฉ์‹์œผ๋กœ ํƒ€์ดํ•‘ ํ•˜๋ฉด `initialValues`์— ๋Œ€ํ•œ ํƒ€์ž…์„ ๋”ฐ๋กœ ๋งŒ๋“ค์–ด์ฃผ์ง€ ์•Š์•„๋„ ๋˜๊ณ  ์ข‹๋„ค์š” ๐Ÿ‘
@@ -0,0 +1,17 @@ +import { Rule } from 'antd/lib/form'; + +export const REVIEW_CYCLE_FORM_NAMES = { + name: 'name', + reviewees: 'reviewees', + question: { + title: 'title', + description: 'description', + }, +} as const; + +export const REVIEW_CYCLE_RULES: Record<string, Rule[]> = { + reviewCycleName: [{ required: true, message: '๋ฆฌ๋ทฐ ์ •์ฑ… ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.' }], + reviewees: [{ required: true, message: '๋ฆฌ๋ทฐ ๋ฐ›๋Š” ์‚ฌ๋žŒ์„ ์„ ํƒํ•˜์„ธ์š”.' }], + questionTitle: [{ required: true, message: '์งˆ๋ฌธ ์ œ๋ชฉ์„ ์ž…๋ ฅํ•˜์„ธ์š”.' }], + questionDescription: [{ required: true, message: '์งˆ๋ฌธ ์„ค๋ช…์„ ์ž…๋ ฅํ•˜์„ธ์š”.' }], +};
TypeScript
์š”๊ธฐ ์ƒ์ˆ˜๋Š” ๋”ฐ๋กœ ๋นผ์‹  ์ด์œ ๊ฐ€ ๋ญ˜๊นŒ์š”? `Form.Item`์˜ `name` ์™ธ์—๋Š” ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ๊ฒƒ ๊ฐ™์€๋ฐ `label`์ฒ˜๋Ÿผ ๋ฐ”๋กœ ๋„ฃ์–ด๋„ ์ข‹์•„๋ณด์—ฌ์š”! ์•„๋‹ˆ๋ฉด label, name, rule์„ ํ•˜๋‚˜๋กœ ๋ฌถ์–ด๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™๊ตฌ์š”! ๊ฐ€๋ณ๊ฒŒ ๋“œ๋Š” ์ƒ๊ฐ ๋‚จ๊ฒจ๋ด…๋‹ˆ๋‹ค~
@@ -0,0 +1,90 @@ +import { API_PATH } from '@apis/constants'; +import { useQuery } from '@apis/common/useQuery'; +import { ReviewCycle } from './entities'; +import { ReviewCycleRequest, ReviewCycleResponse } from './type'; +import { useDelete, usePost, usePut } from '@apis/common/useMutation'; +import { get } from 'lodash'; + +export function useGetReviewCycles() { + const { + data, + isLoading, + mutate: refetchReviewCycle, + } = useQuery<{ reviewCycles: ReviewCycle[] }>(API_PATH.REVIEW_CYCLES); + + return { + reviewCycles: data?.reviewCycles, + isLoading, + refetchReviewCycle, + }; +} + +export function useCreateReviewCycle({ + onSuccess, + onError, +}: { + onSuccess: () => void; + onError: (message: string) => void; +}) { + const { trigger, isMutating } = usePost<ReviewCycleRequest, ReviewCycleResponse>({ + endpoint: API_PATH.REVIEW_CYCLES, + onSuccess: onSuccess, + onError: err => { + const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์‚ฌ์ดํด ์ƒ์„ฑ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.'); + onError(errorMessage); + }, + }); + + return { + createReviewCycle: (reviewCycle: ReviewCycleRequest) => trigger(reviewCycle), + isMutating, + }; +} + +export function useUpdateReviewCycle({ + entityId, + onSuccess, + onError, +}: { + entityId?: number; + onSuccess: () => void; + onError: (message: string) => void; +}) { + const { trigger, isMutating } = usePut<ReviewCycleRequest, ReviewCycleResponse>({ + endpoint: entityId ? `${API_PATH.REVIEW_CYCLES}/${entityId}` : null, + onSuccess: onSuccess, + onError: err => { + const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์‚ฌ์ดํด ์ˆ˜์ •์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.'); + onError(errorMessage); + }, + }); + + return { + updateReviewCycle: (reviewCycle: ReviewCycleRequest) => trigger(reviewCycle), + isMutating, + }; +} + +export function useDeleteReviewCycle({ + entityId, + onSuccess, + onError, +}: { + entityId: number; + onSuccess: () => void; + onError: (message: string) => void; +}) { + const { trigger, isMutating } = useDelete({ + endpoint: `${API_PATH.REVIEW_CYCLES}/${entityId}`, + onSuccess, + onError: err => { + const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์‚ฌ์ดํด ์‚ญ์ œ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.'); + onError(errorMessage); + }, + }); + + return { + deleteReviewCycle: trigger, + isMutating, + }; +}
TypeScript
[์งˆ๋ฌธ] `trigger`๋ฅผ ๋ฐ”๋กœ ๋„˜๊ธฐ์ง€ ์•Š๊ณ  ํ•จ์ˆ˜๋กœ ๋„˜๊ฒจ์ฃผ๋Š” ์ด์œ ๋Š” ํƒ€์ž…์„ ๊ณ ์ •์‹œํ‚ค๊ธฐ ์œ„ํ•จ์ผ๊นŒ์š”?
@@ -0,0 +1,37 @@ +import useModal from 'hooks/useModal'; +import { Headline4 } from 'styles/typography'; +import ReviewCycleForm from '../ReviewCycleForm'; +import { message } from 'antd'; +import { useCreateReviewCycle, useGetReviewCycles } from '@apis/review/useReviewCycles'; + +function useReviewCycleCreateModal() { + const modal = useModal(); + + const { refetchReviewCycle } = useGetReviewCycles(); + const { createReviewCycle } = useCreateReviewCycle({ + onSuccess: () => { + message.success('์ƒˆ๋กœ์šด ๋ฆฌ๋ทฐ ์ •์ฑ…์„ ์ƒ์„ฑํ–ˆ์–ด์š”.'); + modal.close(); + refetchReviewCycle(); + }, + onError: message.error, + }); + + function render() { + return modal.render({ + title: <Headline4>์ƒˆ๋กœ์šด ๋ฆฌ๋ทฐ ์ •์ฑ… ๋งŒ๋“ค๊ธฐ</Headline4>, + visible: modal.visible, + children: ( + <ReviewCycleForm onFinish={createReviewCycle} onReset={modal.close} confirmButtonProps={{ text: '์ƒ์„ฑํ•˜๊ธฐ' }} /> + ), + }); + } + + return { + render, + open: modal.open, + close: modal.close, + }; +} + +export default useReviewCycleCreateModal;
Unknown
์š”๋Ÿฐ ์‹์œผ๋กœ ๊ธฐ์กด `modal`์„ ํ™•์žฅํ•˜๋Š” ํ›…์œผ๋กœ ๋งŒ๋“ค์–ด๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”~ ```suggestion return { ...modal, render, }; ```
@@ -0,0 +1,25 @@ +import { DeleteOutlined } from '@ant-design/icons'; +import { useDeleteReviewCycle, useGetReviewCycles } from '@apis/review/useReviewCycles'; +import { message } from 'antd'; + +function DeleteButton({ entityId }: { entityId: number }) { + const { refetchReviewCycle } = useGetReviewCycles(); + const { deleteReviewCycle } = useDeleteReviewCycle({ + entityId, + onSuccess: refetchReviewCycle, + onError: message.error, + }); + + return ( + <button + onClick={e => { + e.stopPropagation(); + deleteReviewCycle(); + }} + > + <DeleteOutlined /> + </button> + ); +} + +export default DeleteButton;
Unknown
[์งˆ๋ฌธ] `e.stopPropagation()`์˜ ์˜๋„๊ฐ€ ๋ฌด์—‡์ธ๊ฐ€์š”?
@@ -0,0 +1,10 @@ +import { Member, ReviewCycle } from './entities'; + +export type ReviewCycleRequest = { + name: ReviewCycle['name']; + reviewees: Member['entityId'][]; + title: string; + description: string; +}; + +export type ReviewCycleResponse = Pick<ReviewCycle, 'entityId'>;
TypeScript
[์ œ์•ˆ] ์ด๊ฒƒ๊ณผ entities์˜ ํƒ€์ž…์„ ์ผ๋ถ€ ๊ณตํ†ต์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณผ ์ˆ˜๋Š” ์—†์œผ๋ ค๋‚˜์š”? ๊ฐ™์€ ๋งฅ๋ฝ์„ ๋‹ด๊ณ  ์žˆ๋Š” ํƒ€์ž…์ธ๋ฐ ๋งฅ๋ฝ์ด ์•„์˜ˆ ๋ถ„๋ฆฌ๋˜์–ด์„œ ๋‚˜์ค‘์— ์œ ์ง€๋ณด์ˆ˜ํ•  ๋•Œ ์ฃผ์˜ํ•ด์•ผ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“œ๋„ค์š”
@@ -0,0 +1,67 @@ +import { Button, Form, Input, Select, Space } from 'antd'; +import { REVIEW_CYCLE_FORM_NAMES, REVIEW_CYCLE_RULES } from './constants'; +import useMembers from '@apis/review/useMembers'; +import { ReviewCycleRequest } from '@apis/review/type'; +import { ReviewCycle } from '@apis/review/entities'; + +interface Props { + onFinish: (values: ReviewCycleRequest) => void; + onReset: () => void; + initialValues?: { + name: ReviewCycle['name']; + reviewees: number[]; + title: ReviewCycle['question']['title']; + description: ReviewCycle['question']['description']; + }; + confirmButtonProps?: { text: string }; + deleteButtonProps?: { text: string; handleClick: () => void }; +} + +export default function ReviewCycleForm({ + onFinish, + onReset, + initialValues, + confirmButtonProps = { text: 'ํ™•์ธ' }, + deleteButtonProps, +}: Props) { + const { members, isLoading } = useMembers(); + + return ( + <Form labelAlign="right" onFinish={onFinish} onReset={onReset} initialValues={initialValues}> + <Form.Item label="๋ฆฌ๋ทฐ ์ •์ฑ… ์ด๋ฆ„" name={REVIEW_CYCLE_FORM_NAMES.name} rules={REVIEW_CYCLE_RULES.reviewCycleName}> + <Input /> + </Form.Item> + + <Form.Item label="๋ฆฌ๋ทฐ ๋ฐ›๋Š” ์‚ฌ๋žŒ" name={REVIEW_CYCLE_FORM_NAMES.reviewees} rules={REVIEW_CYCLE_RULES.reviewees}> + <Select + mode="multiple" + loading={isLoading} + placeholder="๋ฆฌ๋ทฐ ๋ฐ›๋Š” ์‚ฌ๋žŒ์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”." + optionFilterProp="label" + options={members?.map(m => ({ key: m.entityId, label: m.name, value: m.entityId }))} + /> + </Form.Item> + + <Form.Item label="์งˆ๋ฌธ" name={REVIEW_CYCLE_FORM_NAMES.question.title} rules={REVIEW_CYCLE_RULES.questionTitle}> + <Input /> + </Form.Item> + + <Form.Item + label="์งˆ๋ฌธ ์„ค๋ช…" + name={REVIEW_CYCLE_FORM_NAMES.question.description} + rules={REVIEW_CYCLE_RULES.questionDescription} + > + <Input /> + </Form.Item> + <Form.Item style={{ textAlign: 'right' }}> + <Space size={10}> + <Button htmlType="reset">์ทจ์†Œ</Button> + {deleteButtonProps && <Button onClick={deleteButtonProps.handleClick}>{deleteButtonProps.text}</Button>} + <Button type="primary" htmlType="submit"> + {confirmButtonProps.text} + </Button> + </Space> + </Form.Item> + </Form> + ); +}
Unknown
[์ ๊ทน] ui๋ฅผ ๋ Œ๋”๋งํ•˜๊ธฐ ์œ„ํ•œ buttonProps๊ฐ€ ๊ฐ์ฒดํ˜•ํƒœ๋กœ ๋‚ด๋ ค๊ฐ€๋ฉด ๋‚˜์ค‘์— ์œ ์ง€๋ณด์ˆ˜์ฐจ์›์—์„œ ์–ด๋ ค์›€์ด ์žˆ์„ ๊ฒƒ ๊ฐ™์€๋ฐ ๋ฐฉ๋ฒ•์ด ์—†์œผ๋ ค๋‚˜์š”?? confirmButtonProps๋‚˜ deleteButtonProps๋Š” Form์ด๋ผ๋Š” ๋งฅ๋ฝ์—์„œ๋Š” ์•ˆ์— ๋“ค์–ด๊ฐ€๋„ ๋  ๊ฒƒ ๊ฐ™๋‹ค๊ณ  ํŒ๋‹จํ•  ์ˆ˜๋„ ์žˆ์œผ๋‚˜ ์‹ค์ œ ๋ Œ๋”ํ•˜๋Š” ์ชฝ์—์„œ๋Š” prop์„ ๊บผ๋‚ด์“ฐ๋Š” ์ฐจ์›์— ๋ถˆ๊ณผํ•ด์„œ ์–ด๋–ป๊ฒŒ๋“  ๋ถ„๋ฆฌ๊ฐ€ ๋˜๋ฉด ์ข‹๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์–ด์š”.
@@ -0,0 +1,28 @@ +import { faker } from '@faker-js/faker'; +import { personList } from '@mocks/auth/data'; +import { v4 as uuidv4 } from 'uuid'; + +const personCount = personList.length; + +export const reviewCycleList = Array.from({ length: 10 }, (_, i) => ({ + entityId: uuidv4(), + name: faker.lorem.words(), + creator: personList[Math.floor(Math.random() * personCount)], + reviewees: shuffleArray(personList).slice(0, Math.floor(Math.random() * personCount) + 1), + question: { + title: faker.lorem.words(), + description: faker.lorem.sentence(), + }, + updatedAt: faker.date.past().toISOString(), +})); + +function shuffleArray<T>(array: T[]) { + const result = [...array]; + + for (let i = result.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [result[i], result[j]] = [result[j], result[i]]; + } + + return result; +}
TypeScript
`faker` ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ ์ ˆํžˆ ์ž˜ ์“ฐ์‹œ๋„ค์š” ๐Ÿ‘
@@ -0,0 +1,25 @@ +import { DeleteOutlined } from '@ant-design/icons'; +import { useDeleteReviewCycle, useGetReviewCycles } from '@apis/review/useReviewCycles'; +import { message } from 'antd'; + +function DeleteButton({ entityId }: { entityId: number }) { + const { refetchReviewCycle } = useGetReviewCycles(); + const { deleteReviewCycle } = useDeleteReviewCycle({ + entityId, + onSuccess: refetchReviewCycle, + onError: message.error, + }); + + return ( + <button + onClick={e => { + e.stopPropagation(); + deleteReviewCycle(); + }} + > + <DeleteOutlined /> + </button> + ); +} + +export default DeleteButton;
Unknown
[์ ๊ทน] ๋ฒ„ํŠผ์ธ๋ฐ ๋ฒ„ํŠผ์ด ์•„๋‹Œ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋œ ๊ฒƒ ๊ฐ™์•„์š”. ์•„์ด์ฝ˜์— ํด๋ฆญ์ด๋ฒคํŠธ๋ฅผ ๋‹ค๋Š” ๊ฒƒ์— ๋Œ€ํ•ด์„œ๋Š” ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์šฉ? role=button์ด ๋˜๋„๋ก ํ•ด์•ผํ•˜๋‚˜ ํ•˜๋Š” ํŒ๋‹จ์ด ๋“œ๋„ค์š”
@@ -0,0 +1,163 @@ +import { Person, personIDMap, personMap } from './../auth/data'; +import { API_PATH } from '@apis/constants'; +import { personList } from '@mocks/auth/data'; +import { HttpResponse, http } from 'msw'; +import { reviewCycleList } from './data'; +import { ReviewCycleRequest } from '@apis/review/type'; +import { JWTPayload, JWTVerifyResult, jwtVerify } from 'jose'; +import { v4 as uuidv4 } from 'uuid'; +import { validateAccessToken } from '@mocks/utils'; +import { secretKey } from '@mocks/constants'; + +export const reviewHandlers = [ + http.get(API_PATH.MEMBERS, async ({ request }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + return HttpResponse.json({ + members: personList.map(m => ({ + entityId: m.entityId, + name: m.name, + })), + }); + }), + + http.get(API_PATH.REVIEW_CYCLES, async ({ request }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + const formatted = reviewCycleList.map(r => ({ + entityId: r.entityId, + name: r.name, + creator: r.creator.name, + reviewees: r.reviewees.map(m => ({ entityId: m.entityId, name: m.name })), + question: { + title: r.question.title, + description: r.question.description, + }, + updatedAt: r.updatedAt, + })); + + return HttpResponse.json({ + reviewCycles: formatted, + }); + }), + + http.post<never, ReviewCycleRequest>(API_PATH.REVIEW_CYCLES, async ({ request }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + const accessToken = request.headers.get('Authorization')?.split(' ')[1]; + const verified = accessToken && (await jwtVerify(accessToken, secretKey)); + const email = (verified as JWTVerifyResult<JWTPayload>).payload.email; + + const req = await request.json(); + const reviewees = req.reviewees.map(id => personIDMap.get(id) ?? ({} as Person)); + + reviewCycleList.push({ + entityId: uuidv4(), + name: req.name, + creator: personMap.get(email as string) ?? ({} as Person), + reviewees: reviewees, + question: { + title: req.title, + description: req.description, + }, + updatedAt: new Date().toISOString(), + }); + + return HttpResponse.json( + { + reviewCycle: reviewCycleList[reviewCycleList.length - 1], + }, + { + status: 201, + }, + ); + }), + + http.delete<{ entityId: string }>(`${API_PATH.REVIEW_CYCLES}/:entityId`, async ({ request, params }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + const index = reviewCycleList.splice( + reviewCycleList.findIndex(r => r.entityId === params.entityId), + 1, + ); + + if (index.length === 0) { + return HttpResponse.json( + { + error: { message: '๋ฆฌ๋ทฐ ์‚ฌ์ดํด์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค' }, + }, + { + status: 404, + }, + ); + } + + return HttpResponse.json({ + status: 200, + }); + }), + + http.put<{ entityId: string }, ReviewCycleRequest>( + `${API_PATH.REVIEW_CYCLES}/:entityId`, + async ({ request, params }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + const index = reviewCycleList.findIndex(r => r.entityId === params.entityId); + + if (index === -1) { + return HttpResponse.json( + { + error: { message: '๋ฆฌ๋ทฐ ์‚ฌ์ดํด์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค' }, + }, + { + status: 404, + }, + ); + } + + const req = await request.json(); + const prev = reviewCycleList[index]; + + reviewCycleList[index] = { + entityId: params.entityId, + name: req.name, + creator: prev.creator, + reviewees: req.reviewees.map(id => personIDMap.get(id) ?? ({} as Person)), + question: { + title: req.title, + description: req.description, + }, + updatedAt: new Date().toISOString(), + }; + + return HttpResponse.json( + { + entityId: params.entityId, + }, + { + status: 200, + }, + ); + }, + ), +];
TypeScript
์—ฌ๊ธฐ๋Š” ์Šค์ฝ”ํ”„๊ฐ€ ๋„“์œผ๋‹ˆ `r`๋ณด๋‹ค๋Š” `reviewCycle`์œผ๋กœ ๋„ค์ด๋ฐ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”~
@@ -0,0 +1,43 @@ +import { Button } from 'antd'; +import { RoundContent } from 'components/common/RoundContent'; +import useReviewCycleCreateModal from './ReviewCycleModals/useReviewCycleCreateModal'; +import ReviewCycleTable from './ReviewCycleTable'; +import useReviewCycleUpdateModal from './ReviewCycleModals/useReviewCycleUpdateModal'; +import useSelectedReviewCycle from './useSelectedReviewCycle'; + +function ReviewCycles() { + const { selectedReviewCycle } = useSelectedReviewCycle(); + + const reviewCycleCreateModal = useReviewCycleCreateModal(); + const reviewCycleUpdateModal = useReviewCycleUpdateModal({ + entityId: selectedReviewCycle?.entityId, + }); + + function openReviewCycleCreateModal() { + reviewCycleCreateModal.open(); + } + + function openReviewCycleUpdateModal() { + reviewCycleUpdateModal.open(); + } + + return ( + <RoundContent> + <RoundContent.Header + title="๋ฆฌ๋ทฐ ์ •์ฑ… ๋ชฉ๋ก" + rightArea={ + <Button type="primary" size="large" onClick={openReviewCycleCreateModal}> + ๋ฆฌ๋ทฐ ์ •์ฑ… ์ƒ์„ฑ + </Button> + } + /> + <RoundContent.Body> + <ReviewCycleTable onRowClick={openReviewCycleUpdateModal} /> + </RoundContent.Body> + {reviewCycleCreateModal.render()} + {reviewCycleUpdateModal.render()} + </RoundContent> + ); +} + +export default ReviewCycles;
Unknown
[์ ๊ทน] ์ธ์Šคํ„ด์Šค๋Š” camelcase๊ฐ€ ๋˜๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,163 @@ +import { Person, personIDMap, personMap } from './../auth/data'; +import { API_PATH } from '@apis/constants'; +import { personList } from '@mocks/auth/data'; +import { HttpResponse, http } from 'msw'; +import { reviewCycleList } from './data'; +import { ReviewCycleRequest } from '@apis/review/type'; +import { JWTPayload, JWTVerifyResult, jwtVerify } from 'jose'; +import { v4 as uuidv4 } from 'uuid'; +import { validateAccessToken } from '@mocks/utils'; +import { secretKey } from '@mocks/constants'; + +export const reviewHandlers = [ + http.get(API_PATH.MEMBERS, async ({ request }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + return HttpResponse.json({ + members: personList.map(m => ({ + entityId: m.entityId, + name: m.name, + })), + }); + }), + + http.get(API_PATH.REVIEW_CYCLES, async ({ request }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + const formatted = reviewCycleList.map(r => ({ + entityId: r.entityId, + name: r.name, + creator: r.creator.name, + reviewees: r.reviewees.map(m => ({ entityId: m.entityId, name: m.name })), + question: { + title: r.question.title, + description: r.question.description, + }, + updatedAt: r.updatedAt, + })); + + return HttpResponse.json({ + reviewCycles: formatted, + }); + }), + + http.post<never, ReviewCycleRequest>(API_PATH.REVIEW_CYCLES, async ({ request }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + const accessToken = request.headers.get('Authorization')?.split(' ')[1]; + const verified = accessToken && (await jwtVerify(accessToken, secretKey)); + const email = (verified as JWTVerifyResult<JWTPayload>).payload.email; + + const req = await request.json(); + const reviewees = req.reviewees.map(id => personIDMap.get(id) ?? ({} as Person)); + + reviewCycleList.push({ + entityId: uuidv4(), + name: req.name, + creator: personMap.get(email as string) ?? ({} as Person), + reviewees: reviewees, + question: { + title: req.title, + description: req.description, + }, + updatedAt: new Date().toISOString(), + }); + + return HttpResponse.json( + { + reviewCycle: reviewCycleList[reviewCycleList.length - 1], + }, + { + status: 201, + }, + ); + }), + + http.delete<{ entityId: string }>(`${API_PATH.REVIEW_CYCLES}/:entityId`, async ({ request, params }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + const index = reviewCycleList.splice( + reviewCycleList.findIndex(r => r.entityId === params.entityId), + 1, + ); + + if (index.length === 0) { + return HttpResponse.json( + { + error: { message: '๋ฆฌ๋ทฐ ์‚ฌ์ดํด์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค' }, + }, + { + status: 404, + }, + ); + } + + return HttpResponse.json({ + status: 200, + }); + }), + + http.put<{ entityId: string }, ReviewCycleRequest>( + `${API_PATH.REVIEW_CYCLES}/:entityId`, + async ({ request, params }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + const index = reviewCycleList.findIndex(r => r.entityId === params.entityId); + + if (index === -1) { + return HttpResponse.json( + { + error: { message: '๋ฆฌ๋ทฐ ์‚ฌ์ดํด์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค' }, + }, + { + status: 404, + }, + ); + } + + const req = await request.json(); + const prev = reviewCycleList[index]; + + reviewCycleList[index] = { + entityId: params.entityId, + name: req.name, + creator: prev.creator, + reviewees: req.reviewees.map(id => personIDMap.get(id) ?? ({} as Person)), + question: { + title: req.title, + description: req.description, + }, + updatedAt: new Date().toISOString(), + }; + + return HttpResponse.json( + { + entityId: params.entityId, + }, + { + status: 200, + }, + ); + }, + ), +];
TypeScript
`r`์ด ์ค‘๋ณต ๋ณ€์ˆ˜๋ผ ์—ฌ๊ธฐ๋Š” `m`์ด ๋˜์—ˆ๊ตฐ์š”.. `r`์„ `reviewCycle`๋กœ ๋ฐ”๊พธ๋ฉด ์—ฌ๊ธฐ๋Š” `r`์ด์–ด๋„ ๊ดœ์ฐฎ์•„๋ณด์ž…๋‹ˆ๋‹ค. ํ˜น์€ ์ข€ ๋” ๋ช…ํ™•ํžˆ `reviewee`์–ด๋„ ์ข‹๊ฒ ๊ตฌ์š”! ์ทจํ–ฅ ์ฐจ์ด์ผ ์ˆ˜ ์žˆ๊ฒ ์ง€๋งŒ ๊ฐœ์ธ์ ์œผ๋กœ๋Š” ํ•œ ์ค„ ์ •๋„์˜ ์Šค์ฝ”ํ”„์ผ ๋•Œ๋Š” ์ถ•์•ฝ ๋ณ€์ˆ˜ ์‚ฌ์šฉํ•ด๋„ ํฌ๊ฒŒ ๊ฐ€๋…์„ฑ์„ ํ•ด์น˜์ง€ ์•Š์•„ ๊ดœ์ฐฎ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์š”~
@@ -0,0 +1,163 @@ +import { Person, personIDMap, personMap } from './../auth/data'; +import { API_PATH } from '@apis/constants'; +import { personList } from '@mocks/auth/data'; +import { HttpResponse, http } from 'msw'; +import { reviewCycleList } from './data'; +import { ReviewCycleRequest } from '@apis/review/type'; +import { JWTPayload, JWTVerifyResult, jwtVerify } from 'jose'; +import { v4 as uuidv4 } from 'uuid'; +import { validateAccessToken } from '@mocks/utils'; +import { secretKey } from '@mocks/constants'; + +export const reviewHandlers = [ + http.get(API_PATH.MEMBERS, async ({ request }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + return HttpResponse.json({ + members: personList.map(m => ({ + entityId: m.entityId, + name: m.name, + })), + }); + }), + + http.get(API_PATH.REVIEW_CYCLES, async ({ request }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + const formatted = reviewCycleList.map(r => ({ + entityId: r.entityId, + name: r.name, + creator: r.creator.name, + reviewees: r.reviewees.map(m => ({ entityId: m.entityId, name: m.name })), + question: { + title: r.question.title, + description: r.question.description, + }, + updatedAt: r.updatedAt, + })); + + return HttpResponse.json({ + reviewCycles: formatted, + }); + }), + + http.post<never, ReviewCycleRequest>(API_PATH.REVIEW_CYCLES, async ({ request }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + const accessToken = request.headers.get('Authorization')?.split(' ')[1]; + const verified = accessToken && (await jwtVerify(accessToken, secretKey)); + const email = (verified as JWTVerifyResult<JWTPayload>).payload.email; + + const req = await request.json(); + const reviewees = req.reviewees.map(id => personIDMap.get(id) ?? ({} as Person)); + + reviewCycleList.push({ + entityId: uuidv4(), + name: req.name, + creator: personMap.get(email as string) ?? ({} as Person), + reviewees: reviewees, + question: { + title: req.title, + description: req.description, + }, + updatedAt: new Date().toISOString(), + }); + + return HttpResponse.json( + { + reviewCycle: reviewCycleList[reviewCycleList.length - 1], + }, + { + status: 201, + }, + ); + }), + + http.delete<{ entityId: string }>(`${API_PATH.REVIEW_CYCLES}/:entityId`, async ({ request, params }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + const index = reviewCycleList.splice( + reviewCycleList.findIndex(r => r.entityId === params.entityId), + 1, + ); + + if (index.length === 0) { + return HttpResponse.json( + { + error: { message: '๋ฆฌ๋ทฐ ์‚ฌ์ดํด์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค' }, + }, + { + status: 404, + }, + ); + } + + return HttpResponse.json({ + status: 200, + }); + }), + + http.put<{ entityId: string }, ReviewCycleRequest>( + `${API_PATH.REVIEW_CYCLES}/:entityId`, + async ({ request, params }) => { + const res = await validateAccessToken(request); + + if (res) { + return res; + } + + const index = reviewCycleList.findIndex(r => r.entityId === params.entityId); + + if (index === -1) { + return HttpResponse.json( + { + error: { message: '๋ฆฌ๋ทฐ ์‚ฌ์ดํด์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค' }, + }, + { + status: 404, + }, + ); + } + + const req = await request.json(); + const prev = reviewCycleList[index]; + + reviewCycleList[index] = { + entityId: params.entityId, + name: req.name, + creator: prev.creator, + reviewees: req.reviewees.map(id => personIDMap.get(id) ?? ({} as Person)), + question: { + title: req.title, + description: req.description, + }, + updatedAt: new Date().toISOString(), + }; + + return HttpResponse.json( + { + entityId: params.entityId, + }, + { + status: 200, + }, + ); + }, + ), +];
TypeScript
[์ œ์•ˆ] ์š”๋Œ€๋กœ `push`๋ฅผ ํ•˜๋ฉด ๋งจ ๋’ค์— ๋“ค์–ด๊ฐ€๊ฒŒ ๋ผ์„œ ์ตœ์‹ ์ˆœ์œผ๋กœ ๋ณด์ด์ง€ ์•Š๊ฒŒ ๋˜๋”๋ผ๊ตฌ์š”~ ์ •๋ ฌ์„ ํ•œ ๋ฒˆ ํ•ด ์ฃผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,10 @@ +import { Member, ReviewCycle } from './entities'; + +export type ReviewCycleRequest = { + name: ReviewCycle['name']; + reviewees: Member['entityId'][]; + title: string; + description: string; +}; + +export type ReviewCycleResponse = Pick<ReviewCycle, 'entityId'>;
TypeScript
์Œ ์•„๋ž˜์ฒ˜๋Ÿผ ํƒ€์ดํ•‘ํ•˜๋ฉด ๊ฐ™์€ ๋งฅ๋ฝ์ž„์ด ์ž˜ ๋“œ๋Ÿฌ๋‚˜๋ ค๋‚˜์š”? ```ts export type ReviewCycleRequest = { name: ReviewCycle['name']; reviewees: Member['entityId'][]; title: string; description: string; }; export type ReviewCycleResponse = Pick<ReviewCycle, 'entityId'>; ```
@@ -0,0 +1,90 @@ +import { API_PATH } from '@apis/constants'; +import { useQuery } from '@apis/common/useQuery'; +import { ReviewCycle } from './entities'; +import { ReviewCycleRequest, ReviewCycleResponse } from './type'; +import { useDelete, usePost, usePut } from '@apis/common/useMutation'; +import { get } from 'lodash'; + +export function useGetReviewCycles() { + const { + data, + isLoading, + mutate: refetchReviewCycle, + } = useQuery<{ reviewCycles: ReviewCycle[] }>(API_PATH.REVIEW_CYCLES); + + return { + reviewCycles: data?.reviewCycles, + isLoading, + refetchReviewCycle, + }; +} + +export function useCreateReviewCycle({ + onSuccess, + onError, +}: { + onSuccess: () => void; + onError: (message: string) => void; +}) { + const { trigger, isMutating } = usePost<ReviewCycleRequest, ReviewCycleResponse>({ + endpoint: API_PATH.REVIEW_CYCLES, + onSuccess: onSuccess, + onError: err => { + const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์‚ฌ์ดํด ์ƒ์„ฑ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.'); + onError(errorMessage); + }, + }); + + return { + createReviewCycle: (reviewCycle: ReviewCycleRequest) => trigger(reviewCycle), + isMutating, + }; +} + +export function useUpdateReviewCycle({ + entityId, + onSuccess, + onError, +}: { + entityId?: number; + onSuccess: () => void; + onError: (message: string) => void; +}) { + const { trigger, isMutating } = usePut<ReviewCycleRequest, ReviewCycleResponse>({ + endpoint: entityId ? `${API_PATH.REVIEW_CYCLES}/${entityId}` : null, + onSuccess: onSuccess, + onError: err => { + const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์‚ฌ์ดํด ์ˆ˜์ •์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.'); + onError(errorMessage); + }, + }); + + return { + updateReviewCycle: (reviewCycle: ReviewCycleRequest) => trigger(reviewCycle), + isMutating, + }; +} + +export function useDeleteReviewCycle({ + entityId, + onSuccess, + onError, +}: { + entityId: number; + onSuccess: () => void; + onError: (message: string) => void; +}) { + const { trigger, isMutating } = useDelete({ + endpoint: `${API_PATH.REVIEW_CYCLES}/${entityId}`, + onSuccess, + onError: err => { + const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์‚ฌ์ดํด ์‚ญ์ œ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.'); + onError(errorMessage); + }, + }); + + return { + deleteReviewCycle: trigger, + isMutating, + }; +}
TypeScript
์ด ๋ถ€๋ถ„์€ SWR ๊ธฐ๋ฐ˜์˜ ์ธํ„ฐํŽ˜์ด์Šค(trigger)๋ฅผ ๊ฐ์ถ”๊ณ  ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ต์ผํ•˜๊ธฐ ์œ„ํ•œ ๋ชฉ์ ์ด์—ˆ์–ด์š”. ์ถ”ํ›„์— SWR์„ tanstack-query ๋“ฑ ๋‹ค๋ฅธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋ณ€๊ฒฝํ•˜๋”๋ผ๋„ ๋™์ผํ•˜๊ฒŒ createReviewCycle ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ํ•ด์„œ ์‚ฌ์šฉ์ฒ˜์—์„œ๋Š” ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•  ํ•„์š”๊ฐ€ ์—†๋„๋ก ํ•˜๊ณ ์ž ํ–ˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,17 @@ +import { Rule } from 'antd/lib/form'; + +export const REVIEW_CYCLE_FORM_NAMES = { + name: 'name', + reviewees: 'reviewees', + question: { + title: 'title', + description: 'description', + }, +} as const; + +export const REVIEW_CYCLE_RULES: Record<string, Rule[]> = { + reviewCycleName: [{ required: true, message: '๋ฆฌ๋ทฐ ์ •์ฑ… ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.' }], + reviewees: [{ required: true, message: '๋ฆฌ๋ทฐ ๋ฐ›๋Š” ์‚ฌ๋žŒ์„ ์„ ํƒํ•˜์„ธ์š”.' }], + questionTitle: [{ required: true, message: '์งˆ๋ฌธ ์ œ๋ชฉ์„ ์ž…๋ ฅํ•˜์„ธ์š”.' }], + questionDescription: [{ required: true, message: '์งˆ๋ฌธ ์„ค๋ช…์„ ์ž…๋ ฅํ•˜์„ธ์š”.' }], +};
TypeScript
ํ•ด๋‹น form์˜ ์š”์†Œ๊ฐ€ ์–ด๋–ป๊ฒŒ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋Š”์ง€ ํ•œ๋ˆˆ์— ํŒŒ์•…ํ•˜๊ธฐ ์‰ฝ์ง€ ์•Š์„๊นŒ ํ–ˆ์—ˆ๋Š”๋ฐ, ํ•˜๋‚˜์˜ ๊ฐ์ฒด๋กœ ๋ฌถ๋Š”๊ฒŒ ๋‚˜์•˜์œผ๋ ค๋‚˜ ์‹ถ๊ตฐ์š”!
@@ -0,0 +1,25 @@ +import { DeleteOutlined } from '@ant-design/icons'; +import { useDeleteReviewCycle, useGetReviewCycles } from '@apis/review/useReviewCycles'; +import { message } from 'antd'; + +function DeleteButton({ entityId }: { entityId: number }) { + const { refetchReviewCycle } = useGetReviewCycles(); + const { deleteReviewCycle } = useDeleteReviewCycle({ + entityId, + onSuccess: refetchReviewCycle, + onError: message.error, + }); + + return ( + <button + onClick={e => { + e.stopPropagation(); + deleteReviewCycle(); + }} + > + <DeleteOutlined /> + </button> + ); +} + +export default DeleteButton;
Unknown
ํ˜„์žฌ ํ…Œ์ด๋ธ” onRowClick ์‹œ ๋ฆฌ๋ทฐ ์‚ฌ์ดํด ์ˆ˜์ • ๋ชจ๋‹ฌ์ด ์—ด๋ฆฌ๋„๋ก ์ด๋ฒคํŠธ๋ฅผ ๋“ฑ๋กํ•ด๋‘์—ˆ๋Š”๋ฐ์š”, ์‚ญ์ œ ๋ฒ„ํŠผ ์‹œ์—๋Š” ์ด๋ฒคํŠธ ์ „ํŒŒ๋ฅผ ๋ง‰๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,25 @@ +import { DeleteOutlined } from '@ant-design/icons'; +import { useDeleteReviewCycle, useGetReviewCycles } from '@apis/review/useReviewCycles'; +import { message } from 'antd'; + +function DeleteButton({ entityId }: { entityId: number }) { + const { refetchReviewCycle } = useGetReviewCycles(); + const { deleteReviewCycle } = useDeleteReviewCycle({ + entityId, + onSuccess: refetchReviewCycle, + onError: message.error, + }); + + return ( + <button + onClick={e => { + e.stopPropagation(); + deleteReviewCycle(); + }} + > + <DeleteOutlined /> + </button> + ); +} + +export default DeleteButton;
Unknown
๋„ต button์œผ๋กœ ๊ฐ์‹ธ๋Š”๊ฒŒ ์ข‹๊ฒ ๊ตฐ์š”. > ๋ฐ˜์˜ํ–ˆ์Šต๋‹ˆ๋‹ค! [refactor: ์‚ญ์ œ ๋ฒ„ํŠผ ๊ตฌ์กฐ ๋ณ€๊ฒฝ](https://github.com/lemonbase-labs/journee-on-boarding-project/pull/7/commits/2201091e80c11c71bb97c3cf131410067cb04478)
@@ -0,0 +1,67 @@ +import { Button, Form, Input, Select, Space } from 'antd'; +import { REVIEW_CYCLE_FORM_NAMES, REVIEW_CYCLE_RULES } from './constants'; +import useMembers from '@apis/review/useMembers'; +import { ReviewCycleRequest } from '@apis/review/type'; +import { ReviewCycle } from '@apis/review/entities'; + +interface Props { + onFinish: (values: ReviewCycleRequest) => void; + onReset: () => void; + initialValues?: { + name: ReviewCycle['name']; + reviewees: number[]; + title: ReviewCycle['question']['title']; + description: ReviewCycle['question']['description']; + }; + confirmButtonProps?: { text: string }; + deleteButtonProps?: { text: string; handleClick: () => void }; +} + +export default function ReviewCycleForm({ + onFinish, + onReset, + initialValues, + confirmButtonProps = { text: 'ํ™•์ธ' }, + deleteButtonProps, +}: Props) { + const { members, isLoading } = useMembers(); + + return ( + <Form labelAlign="right" onFinish={onFinish} onReset={onReset} initialValues={initialValues}> + <Form.Item label="๋ฆฌ๋ทฐ ์ •์ฑ… ์ด๋ฆ„" name={REVIEW_CYCLE_FORM_NAMES.name} rules={REVIEW_CYCLE_RULES.reviewCycleName}> + <Input /> + </Form.Item> + + <Form.Item label="๋ฆฌ๋ทฐ ๋ฐ›๋Š” ์‚ฌ๋žŒ" name={REVIEW_CYCLE_FORM_NAMES.reviewees} rules={REVIEW_CYCLE_RULES.reviewees}> + <Select + mode="multiple" + loading={isLoading} + placeholder="๋ฆฌ๋ทฐ ๋ฐ›๋Š” ์‚ฌ๋žŒ์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”." + optionFilterProp="label" + options={members?.map(m => ({ key: m.entityId, label: m.name, value: m.entityId }))} + /> + </Form.Item> + + <Form.Item label="์งˆ๋ฌธ" name={REVIEW_CYCLE_FORM_NAMES.question.title} rules={REVIEW_CYCLE_RULES.questionTitle}> + <Input /> + </Form.Item> + + <Form.Item + label="์งˆ๋ฌธ ์„ค๋ช…" + name={REVIEW_CYCLE_FORM_NAMES.question.description} + rules={REVIEW_CYCLE_RULES.questionDescription} + > + <Input /> + </Form.Item> + <Form.Item style={{ textAlign: 'right' }}> + <Space size={10}> + <Button htmlType="reset">์ทจ์†Œ</Button> + {deleteButtonProps && <Button onClick={deleteButtonProps.handleClick}>{deleteButtonProps.text}</Button>} + <Button type="primary" htmlType="submit"> + {confirmButtonProps.text} + </Button> + </Space> + </Form.Item> + </Form> + ); +}
Unknown
์•„ํ•˜.. ์ €๋Š” ์ง๊ด€์ ์ด๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋Š”๋ฐ, ์œ ์ง€๋ณด์ˆ˜ ์ฐจ์›์—์„œ ์–ด๋–ค ์–ด๋ ค์›€์ธ์ง€ ํ˜น์€ ์–ด๋–ป๊ฒŒ ๋ถ„๋ฆฌ๋˜์–ด์•ผ ํ•˜๋Š”์ง€ ์ข€ ๋” ์„ค๋ช…ํ•ด์ฃผ์‹ค ์ˆ˜ ์žˆ์„๊นŒ์š”? ์‹ค์ œ๋กœ ํ˜„์žฌ ๋ ˆ๋ชฌ๋ฒ ์ด์Šค ๋ชจ๋‹ฌ ํ›…์ธ useBasicModal๋„ ๋น„์Šทํ•œ ํŒจํ„ด์œผ๋กœ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š”๋ฐ, ์ €๋Š” ์œ ์ง€๋ณด์ˆ˜ ์ฐจ์›์—์„œ ์–ด๋ ค์›€์ด ์žˆ์–ด์„œ ๊ฐœ์„ ํ•ด์•ผ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•˜์ง„ ์•Š์•˜์–ด์„œ์š”!
@@ -0,0 +1,43 @@ +import { Button } from 'antd'; +import { RoundContent } from 'components/common/RoundContent'; +import useReviewCycleCreateModal from './ReviewCycleModals/useReviewCycleCreateModal'; +import ReviewCycleTable from './ReviewCycleTable'; +import useReviewCycleUpdateModal from './ReviewCycleModals/useReviewCycleUpdateModal'; +import useSelectedReviewCycle from './useSelectedReviewCycle'; + +function ReviewCycles() { + const { selectedReviewCycle } = useSelectedReviewCycle(); + + const reviewCycleCreateModal = useReviewCycleCreateModal(); + const reviewCycleUpdateModal = useReviewCycleUpdateModal({ + entityId: selectedReviewCycle?.entityId, + }); + + function openReviewCycleCreateModal() { + reviewCycleCreateModal.open(); + } + + function openReviewCycleUpdateModal() { + reviewCycleUpdateModal.open(); + } + + return ( + <RoundContent> + <RoundContent.Header + title="๋ฆฌ๋ทฐ ์ •์ฑ… ๋ชฉ๋ก" + rightArea={ + <Button type="primary" size="large" onClick={openReviewCycleCreateModal}> + ๋ฆฌ๋ทฐ ์ •์ฑ… ์ƒ์„ฑ + </Button> + } + /> + <RoundContent.Body> + <ReviewCycleTable onRowClick={openReviewCycleUpdateModal} /> + </RoundContent.Body> + {reviewCycleCreateModal.render()} + {reviewCycleUpdateModal.render()} + </RoundContent> + ); +} + +export default ReviewCycles;
Unknown
๋„ค!! ๋ฐ˜์˜ํ–ˆ์Šต๋‹ˆ๋‹ค! [refactor: ์ธ์Šคํ„ด์Šค camelcase๋กœ ์ˆ˜์ •](https://github.com/lemonbase-labs/journee-on-boarding-project/pull/7/commits/3a4fecb79aa6c1a53951900d79c308af0a87d940)
@@ -0,0 +1,90 @@ +import { API_PATH } from '@apis/constants'; +import { useQuery } from '@apis/common/useQuery'; +import { ReviewCycle } from './entities'; +import { ReviewCycleRequest, ReviewCycleResponse } from './type'; +import { useDelete, usePost, usePut } from '@apis/common/useMutation'; +import { get } from 'lodash'; + +export function useGetReviewCycles() { + const { + data, + isLoading, + mutate: refetchReviewCycle, + } = useQuery<{ reviewCycles: ReviewCycle[] }>(API_PATH.REVIEW_CYCLES); + + return { + reviewCycles: data?.reviewCycles, + isLoading, + refetchReviewCycle, + }; +} + +export function useCreateReviewCycle({ + onSuccess, + onError, +}: { + onSuccess: () => void; + onError: (message: string) => void; +}) { + const { trigger, isMutating } = usePost<ReviewCycleRequest, ReviewCycleResponse>({ + endpoint: API_PATH.REVIEW_CYCLES, + onSuccess: onSuccess, + onError: err => { + const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์‚ฌ์ดํด ์ƒ์„ฑ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.'); + onError(errorMessage); + }, + }); + + return { + createReviewCycle: (reviewCycle: ReviewCycleRequest) => trigger(reviewCycle), + isMutating, + }; +} + +export function useUpdateReviewCycle({ + entityId, + onSuccess, + onError, +}: { + entityId?: number; + onSuccess: () => void; + onError: (message: string) => void; +}) { + const { trigger, isMutating } = usePut<ReviewCycleRequest, ReviewCycleResponse>({ + endpoint: entityId ? `${API_PATH.REVIEW_CYCLES}/${entityId}` : null, + onSuccess: onSuccess, + onError: err => { + const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์‚ฌ์ดํด ์ˆ˜์ •์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.'); + onError(errorMessage); + }, + }); + + return { + updateReviewCycle: (reviewCycle: ReviewCycleRequest) => trigger(reviewCycle), + isMutating, + }; +} + +export function useDeleteReviewCycle({ + entityId, + onSuccess, + onError, +}: { + entityId: number; + onSuccess: () => void; + onError: (message: string) => void; +}) { + const { trigger, isMutating } = useDelete({ + endpoint: `${API_PATH.REVIEW_CYCLES}/${entityId}`, + onSuccess, + onError: err => { + const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์‚ฌ์ดํด ์‚ญ์ œ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.'); + onError(errorMessage); + }, + }); + + return { + deleteReviewCycle: trigger, + isMutating, + }; +}
TypeScript
์˜คํ˜ธ ์ธํ„ฐํŽ˜์ด์Šค ํ†ต์ผ ๋ชฉ์ ! ์ดํ•ดํ–ˆ์Šต๋‹ˆ๋‹ค~ ๊ณ ๋ ‡๋‹ค๋ฉด ๊ฐ™์€ ํŒŒ์ผ [L87](https://github.com/lemonbase-labs/journee-on-boarding-project/pull/7/files#diff-3ab91e36eb619267b0f18915f2e642a8452aece2c4e8220b0bce854dc2e8d68eR87)์— `deleteReviewCycle: trigger`๋Š” ์š” ์ฒ˜๋ฆฌ๊ฐ€ ๋ˆ„๋ฝ๋œ ๊ฒƒ ๊ฐ™์•„ ๊ฐ™์ด ๋ฐ˜์˜ํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”~
@@ -1 +1,30 @@ -# java-lotto ๊ฒŒ์ž„ +# java-Lotto ๊ฒŒ์ž„ + +# ๊ตฌํ˜„ ๊ธฐ๋Šฅ ๋ชฉ๋ก + +- [x] ๊ตฌ์ž…๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๊ธฐ + - [x] 1000์› ๋ฏธ๋งŒ ์ž…๋ ฅ ์‹œ ์ฒ˜๋ฆฌ + - [x] 1000์˜ ๋ฐฐ์ˆ˜ ์•„๋‹Œ ๊ฐ’ ์ž…๋ ฅ ์‹œ ์ฒ˜๋ฆฌ + - [x] ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๊ฐ’ (๋ฌธ์ž์—ด) + - [x] ์ •์ƒ๊ฐ’ ์ฒ˜๋ฆฌ + - [x] ๊ณต๋ฐฑ ์ฒ˜๋ฆฌ +- [x] ๊ตฌ๋งค ๊ฐœ์ˆ˜ ๊ตฌํ•˜๊ธฐ +- [x] ๋žœ๋ค ๋กœ๋˜๋ฒˆํ˜ธ ๊ตฌ๋งค ๊ฐœ์ˆ˜๋งŒํผ ๋งŒ๋“ค๊ธฐ + - [x] defaultNumberSet 1๋ฒˆ๋งŒ ์ƒ์„ฑ๋˜๋„๋ก ๋ณ€๊ฒฝ + - [x] RandomLottoTest ์ƒ์ˆ˜ ๋ฆฌํŒฉํ† ๋ง + - [x] PurchaseCount์˜ 1000 ์ ‘๊ทผ +- [x] ์ง€๋‚œ ์ฃผ ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ž…๋ ฅ๋ฐ›๊ธฐ + - [x] WinningNumbers ๋ฉค๋ฒ„๋ณ€์ˆ˜ ArrayList ํด๋ž˜์Šค ํ™•์ธ + - [x] ์ˆซ์ž ๊ฐœ์ˆ˜ 6๊ฐœ ํ™•์ธ + - [x] ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๊ฐ’ ํฌํ•จ + - [x] ๋ฒ”์œ„ (1~45) ํ™•์ธ + - [x] ๊ณต๋ฐฑ ์ฒ˜๋ฆฌ +- [x] ๋ณด๋„ˆ์Šค ๋ณผ ์ž…๋ ฅ๋ฐ›๊ธฐ +- [x] ๋‹น์ฒจ ํ†ต๊ณ„ + - [x] ๋‹น์ฒจ ์กฐ๊ฑด์„ enum ์ฒ˜๋ฆฌ + - [x] ์ผ์น˜ ๊ฐœ์ˆ˜ ์ฐพ๊ธฐ + - [x] 5๊ฐœ ์ผ์น˜ ์‹œ ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ ์—ฌ๋ถ€ ํ™•์ธ + - [x] ๋กœ๋˜ ๋‹น์ฒจ ๊ฐœ์ˆ˜ ๊ตฌํ•˜๊ธฐ + - [x] ๋‹น์ฒจ๊ฐ’์˜ ํ•ฉ ๊ตฌํ•˜๊ธฐ + - [x] ์ˆ˜์ต๋ฅ  ๊ตฌํ•˜๊ธฐ + - [x] ๊ฒฐ๊ณผ ์ถœ๋ ฅ \ No newline at end of file
Unknown
๊ตฌํ˜„ ๊ธฐ๋Šฅ ๋ชฉ๋ก ์ž‘์„ฑ ๐Ÿ‘
@@ -10,6 +10,13 @@ repositories { dependencies { testImplementation('org.junit.jupiter:junit-jupiter:5.6.0') testImplementation('org.assertj:assertj-core:3.15.0') + + compileOnly 'org.projectlombok:lombok:1.18.20' + annotationProcessor 'org.projectlombok:lombok:1.18.20' + + testCompileOnly 'org.projectlombok:lombok:1.18.20' + testAnnotationProcessor 'org.projectlombok:lombok:1.18.20' + } test {
Unknown
๋กฌ๋ณต ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ํ™œ์šฉํ•˜์…จ๋„ค์š”!
@@ -0,0 +1,24 @@ +package lotto.controller; + +import lotto.domain.dto.LottoResult; +import lotto.domain.dto.PurchaseInput; +import lotto.domain.dto.PurchaseResult; +import lotto.domain.dto.WinningLottoInput; +import lotto.service.LottoService; + +public class LottoController { + + private final LottoService lottoService; + + public LottoController() { + this.lottoService = new LottoService(); + } + + public PurchaseResult purchase(PurchaseInput purchaseInput) throws IllegalArgumentException { + return lottoService.purchase(purchaseInput); + } + + public LottoResult calculateResult(PurchaseResult purchaseResult, WinningLottoInput winningLottoInput) throws IllegalArgumentException { + return lottoService.calculateResult(purchaseResult, winningLottoInput); + } +}
Java
MVC ํŒจํ„ด์„ ์ด์šฉํ•ด ๋ฌธ์ œ๋ฅผ ํ’€๋ ค๊ณ  ์‹œ๋„ํ•˜์…จ๋„ค์š”! ๋‹ค๋งŒ Model - View - Controller ์—ญํ•  ๋ถ„๋ฆฌ๊ฐ€ ๋ช…ํ™•ํ•˜๊ฒŒ ๋˜์–ด์žˆ์ง€ ์•Š์•„ ํ˜„์žฌ Controller๊ฐ€ View๋ฅผ ์ง์ ‘ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ฝ”๋“œ ๊ตฌํ˜„์ด ๋˜์–ด์žˆ๋Š”๋ฐ์š”. ๊ฐ์ž์˜ ์—ญํ• ๊ณผ ์ฑ…์ž„์€ ๋ฌด์—‡์ด๊ณ , ์ด๋ฅผ ์–ด๋–ป๊ฒŒ ๋…๋ฆฝ์ ์œผ๋กœ ๋ถ„๋ฆฌํ•ด๋‚ผ ์ˆ˜ ์žˆ์„ ์ง€, ๋˜ ์™œ ๊ทธ๋Ÿฌํ•˜์—ฌ์•ผ ํ•˜๋Š”์ง€ ๊ณ ๋ฏผํ•ด๋ณด์‹œ๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค. ํ˜„์žฌ๋Š” `LottoController.start()` ๋Š” `LottoApplication`์˜ main๊ณผ ๊ฐ™์€ ์—ญํ• ๋กœ ๋ณด์ด๋„ค์š”.
@@ -0,0 +1,31 @@ +package lotto.view; + +import java.util.Arrays; +import java.util.List; +import java.util.Scanner; +import java.util.stream.Collectors; + +public class ConsoleInputView implements InputView { + + private static final String LOTTO_NUMBERS_INPUT_DELIMITER = ","; + + private final Scanner scanner = new Scanner(System.in); + + public Integer getPurchaseCost() throws NumberFormatException { + String input = scanner.nextLine().trim(); + return Integer.parseInt(input); + } + + public List<Integer> getWinningLottoNumbers() throws NumberFormatException { + String input = scanner.nextLine(); + return Arrays.stream(input.split(LOTTO_NUMBERS_INPUT_DELIMITER)) + .map(String::trim) + .map(Integer::new) + .collect(Collectors.toList()); + } + + public Integer getWinningLottoBonus() throws NumberFormatException { + String input = scanner.nextLine().trim(); + return Integer.parseInt(input); + } +}
Java
๊ณผํ•œ(๋ถˆํ•„์š”ํ•œ) ๋ฉ”์„œ๋“œ ํฌ์žฅ์ž…๋‹ˆ๋‹ค.
@@ -0,0 +1,86 @@ +package lotto.view; + +import lotto.domain.*; +import lotto.domain.dto.LottoResult; + +public class ConsoleOutputView implements OutputView { + + private static final String ERROR_HEADER = "[ERROR] "; + + private void print(String contents) { + System.out.println(contents); + } + + public void printLottoCount(PurchaseCount purchaseCount) { + int count = purchaseCount.getPurchaseCount(); + print(count + "๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค."); + } + + public void printLottoSet(LottoSet lottoSet) { + for (Lotto lotto : lottoSet.getLottoSet()) { + printLotto(lotto); + } + } + + private void printLotto(Lotto lotto) { + String result = "["; + for (LottoNumber lottoNumber : lotto.getLottoNumbers()) { + result += lottoNumber.getLottoNumber() + ", "; + } + result = removeCommaAtTheEnd(result) + "]"; + + print(result); + } + + private String removeCommaAtTheEnd(String str) { + return str.substring(0, str.length() - 2); + } + + public void askPurchaseCost() { + print("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + + public void askWinningLottoNumbers() { + print("์ง€๋‚œ ์ฃผ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + + public void askWinningLottoBonus() { + print("๋ณด๋„ˆ์Šค ๋ณผ์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + + public void printLottoStatistic(LottoResult lottoStatistics) { + String result = "๋‹น์ฒจ ํ†ต๊ณ„\n---------\n" + + generatePrizeResultMessage(Prize.FIFTH, lottoStatistics.getPrizeCount().getFifth()) + + generatePrizeResultMessage(Prize.FOURTH, lottoStatistics.getPrizeCount().getFourth()) + + generatePrizeResultMessage(Prize.THIRD, lottoStatistics.getPrizeCount().getThird()) + + generatePrizeResultMessage(Prize.SECOND, lottoStatistics.getPrizeCount().getSecond()) + + generatePrizeResultMessage(Prize.FIRST, lottoStatistics.getPrizeCount().getFirst()) + + generateProfitRateMessage(lottoStatistics.getProfitRate()); + print(result); + } + + private String generatePrizeResultMessage(Prize prize, int prizeCount) { + return generatePrizeResultMessage(prize) + prizeCount + "๊ฐœ\n"; + } + + private String generatePrizeResultMessage(Prize prize) { + StringBuilder sb = new StringBuilder(); + sb.append(prize.getMatchNumbersCount()) + .append("๊ฐœ ์ผ์น˜"); + if (prize.isBonus()) { + sb.append(", ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ "); + } + sb.append("(") + .append(prize.getPrizeMoney()) + .append("์›)- "); + return sb.toString(); + } + + private String generateProfitRateMessage(double profitRate) { + return "์ด ์ˆ˜์ต๋ฅ ์€ " + profitRate + "์ž…๋‹ˆ๋‹ค."; + } + + public void printException(String message) { + print(ERROR_HEADER + message); + } +}
Java
line 9 to 13 ๋„ˆ๋ฌด ๋ช…ํ™•ํ•œ ๊ฐ’๋“ค์ด ๊ณผํ•˜๊ฒŒ ์ƒ์ˆ˜๋กœ ๋งŒ๋“ค์–ด์กŒ์Šต๋‹ˆ๋‹ค. ๋ชจ๋“  literal value๊ฐ€ ๋‚˜์œ ๊ฒƒ์€ ์•„๋‹™๋‹ˆ๋‹ค. ^^;
@@ -0,0 +1,33 @@ +package lotto.service; + +import lotto.domain.*; +import lotto.domain.dto.LottoResult; +import lotto.domain.dto.PurchaseInput; +import lotto.domain.dto.PurchaseResult; +import lotto.domain.dto.WinningLottoInput; + +public class LottoService { + + public PurchaseResult purchase(PurchaseInput purchaseInput) throws IllegalArgumentException { + PurchaseCount purchaseCount = new PurchaseCount(purchaseInput.getPrice()); + LottoSet lottoSet = new LottoSet(purchaseCount); + + return PurchaseResult.builder() + .purchaseCount(purchaseCount) + .lottoSet(lottoSet) + .build(); + } + + public LottoResult calculateResult(PurchaseResult purchaseResult, WinningLottoInput winningLottoInput) throws IllegalArgumentException { + LottoMatcher lottoMatcher = new LottoMatcher( + new WinningLotto(winningLottoInput), purchaseResult.getLottoSet() + ); + PrizeCount prizeCount = lottoMatcher.countPrizes(); + LottoStatistics lottoStatistics = new LottoStatistics(prizeCount, purchaseResult.getPurchaseCount()); + + return LottoResult.builder() + .prizeCount(prizeCount) + .profitRate(lottoStatistics.calculateProfitRate()) + .build(); + } +}
Java
PurchaseCount ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์ด ์‹œ์ ์— ์œ ํšจ์„ฑ ๊ฒ€์ฆ์ด ํ•ด๋‹น ๊ฐ์ฒด ์ƒ์„ฑ์ž์—์„œ ์ง„ํ–‰๋˜๋Š”๋ฐ์š”, ์ปจํŠธ๋กค๋Ÿฌ ๋ ˆ์ด์–ด์—์„œ ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ ๊ฐ’์˜ ์œ ํšจ์„ฑ์„ ๋จผ์ € ๊ฒ€์ฆํ•  ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒ์š”? ๊ณ ๋ฏผํ•ด๋ณผ ๊ฑฐ๋ฆฌ: ์œ ํšจ์„ฑ ๊ฒ€์ฆ์€ ์–ด๋–ค ๋ ˆ์ด์–ด์—์„œ ์ง„ํ–‰๋˜์–ด์•ผํ• ๊นŒ?
@@ -0,0 +1,19 @@ +package lotto.exception; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lotto.domain.Lotto; + +@RequiredArgsConstructor +public enum ExceptionMessage { + + NON_NUMBER_INPUT("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."), + LESS_THAN_LOTTO_PRICE_INPUT_FOR_PURCHASE_MONEY("๊ตฌ์ž…๊ธˆ์•ก์€ " + Lotto.PRICE + " ์ด์ƒ์˜ ๊ฐ’์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."), + NON_MULTIPLE_OF_LOTTO_PRICE_INPUT_FOR_PURCHASE_MONEY("๊ตฌ์ž…๊ธˆ์•ก์€ " + Lotto.PRICE + "์˜ ๋ฐฐ์ˆ˜๋กœ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."), + INVALID_LENGTH_INPUT_FOR_LOTTO("๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”"), + DUPLICATE_LOTTO_NUMBER_INPUT_FOR_LOTTO("๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” 6๊ฐœ์˜ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”"), + OUT_OF_BOUND_INPUT_FOR_LOTTO_NUMBER("๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 1 ์ด์ƒ 45 ์ดํ•˜์˜ ๊ฐ’์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + + @Getter + private final String message; +}
Java
์˜ˆ์™ธ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณ„๋„๋กœ ๋ถ„๋ฆฌํ•ด์„œ ํ•œ ๊ณณ์—์„œ ๊ด€๋ฆฌํ•˜๊ณ  ์žˆ๋„ค์š”! ํ˜„์žฌ๋Š” IllegalArgumentException๋งŒ์„ ์‚ฌ์šฉํ•˜๊ณ  ๋ฉ”์‹œ์ง€๋กœ ํŠน์ • ์˜ˆ์™ธ์— ๋Œ€ํ•ด์„œ ์ฒ˜๋ฆฌํ•˜๊ณ  ์žˆ๋Š”๋ฐ์š”, ๊ตฌ์ฒด์ ์ธ CustomException์„ ๋งŒ๋“ค๊ณ  ์ƒํ™ฉ์— ๋”ฐ๋ผ ์ด๋ฅผ ๋˜์ ธ ํ•ด๋‹น Exception์„ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์ƒ๊ฐํ•ด๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,53 @@ +package lotto.domain; + +import lombok.Getter; + +import java.util.Objects; + +import static lotto.exception.ExceptionMessage.OUT_OF_BOUND_INPUT_FOR_LOTTO_NUMBER; + +public class LottoNumber { + + public static final int LOWER_BOUND = 1; + public static final int UPPER_BOUND = 45; + + @Getter + private final int lottoNumber; + + public LottoNumber(int lottoNumber) throws IllegalArgumentException { + validate(lottoNumber); + + this.lottoNumber = lottoNumber; + } + + private void validate(int lottoNumber) throws IllegalArgumentException { + if (isOutOfBound(lottoNumber)) { + throw new IllegalArgumentException(OUT_OF_BOUND_INPUT_FOR_LOTTO_NUMBER.getMessage()); + } + } + + private boolean isOutOfBound(int lottoNumber) { + return lottoNumber < LOWER_BOUND || lottoNumber > UPPER_BOUND; + } + + public boolean isGreaterThan(LottoNumber winningNumber) { + return this.getLottoNumber() > winningNumber.getLottoNumber(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + LottoNumber that = (LottoNumber) o; + return lottoNumber == that.lottoNumber; + } + + @Override + public int hashCode() { + return Objects.hash(lottoNumber); + } +}
Java
`isInteger` ๋Š” ์ง๋…ํ•˜๋ฉด ์ •์ˆ˜์ธ๊ฐ€? ๋Š” ํŒ๋‹จ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค๋งŒ ๋‚ด์šฉ์„ ๋ณด๋‹ˆ 0~9๊นŒ์ง€ ์ˆซ์ž ์ฆ‰ ์Œ์ด ์•„๋‹Œ ์ •์ˆ˜์ธ์ง€๋ฅผ ์ •๊ทœํ‘œํ˜„์‹์„ ์ด์šฉํ•ด ํŒ๋‹จํ•˜๊ณ  ์žˆ๋„ค์š”. isNonNegativeInteger ์ •๋„๋กœ ๋” ์ •ํ™•ํ•˜๊ฒŒ ํ‘œํ˜„ํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”? ```suggestion if (!isNonNegativeInteger(input)) { ```
@@ -0,0 +1,35 @@ +package lotto.domain; + +import lombok.Builder; +import lombok.Getter; + +import static lotto.exception.ExceptionMessage.LESS_THAN_LOTTO_PRICE_INPUT_FOR_PURCHASE_MONEY; +import static lotto.exception.ExceptionMessage.NON_MULTIPLE_OF_LOTTO_PRICE_INPUT_FOR_PURCHASE_MONEY; + +public class PurchaseCount { + + private static final int MINIMUM_INPUT = 1000; + + @Getter + private final Integer purchaseCount; + + @Builder + public PurchaseCount(int purchasePrice) { + validate(purchasePrice); + + this.purchaseCount = purchasePrice / Lotto.PRICE; + } + + private void validate(int purchasePrice) { + if (purchasePrice < MINIMUM_INPUT) { + throw new IllegalArgumentException(LESS_THAN_LOTTO_PRICE_INPUT_FOR_PURCHASE_MONEY.getMessage()); + } + if (notMultipleOfLottoPrice(purchasePrice)) { + throw new IllegalArgumentException(NON_MULTIPLE_OF_LOTTO_PRICE_INPUT_FOR_PURCHASE_MONEY.getMessage()); + } + } + + private boolean notMultipleOfLottoPrice(int input) { + return input % Lotto.PRICE != 0; + } +}
Java
`isInteger` ๋Š” ์ง๋…ํ•˜๋ฉด ์ •์ˆ˜์ธ๊ฐ€? ๋Š” ํŒ๋‹จ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค๋งŒ ๋‚ด์šฉ์„ ๋ณด๋‹ˆ 0~9๊นŒ์ง€ ์ˆซ์ž ์ฆ‰ ์Œ์ด ์•„๋‹Œ ์ •์ˆ˜์ธ์ง€๋ฅผ ์ •๊ทœํ‘œํ˜„์‹์„ ์ด์šฉํ•ด ํŒ๋‹จํ•˜๊ณ  ์žˆ๋„ค์š”. isNonNegativeInteger ์ •๋„๋กœ ๋” ์ •ํ™•ํ•˜๊ฒŒ ํ‘œํ˜„ํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”? ```suggestion if (!isNonNegativeInteger(input)) { ```
@@ -0,0 +1,35 @@ +package lotto.domain; + +import lombok.Builder; +import lombok.Getter; + +import static lotto.exception.ExceptionMessage.LESS_THAN_LOTTO_PRICE_INPUT_FOR_PURCHASE_MONEY; +import static lotto.exception.ExceptionMessage.NON_MULTIPLE_OF_LOTTO_PRICE_INPUT_FOR_PURCHASE_MONEY; + +public class PurchaseCount { + + private static final int MINIMUM_INPUT = 1000; + + @Getter + private final Integer purchaseCount; + + @Builder + public PurchaseCount(int purchasePrice) { + validate(purchasePrice); + + this.purchaseCount = purchasePrice / Lotto.PRICE; + } + + private void validate(int purchasePrice) { + if (purchasePrice < MINIMUM_INPUT) { + throw new IllegalArgumentException(LESS_THAN_LOTTO_PRICE_INPUT_FOR_PURCHASE_MONEY.getMessage()); + } + if (notMultipleOfLottoPrice(purchasePrice)) { + throw new IllegalArgumentException(NON_MULTIPLE_OF_LOTTO_PRICE_INPUT_FOR_PURCHASE_MONEY.getMessage()); + } + } + + private boolean notMultipleOfLottoPrice(int input) { + return input % Lotto.PRICE != 0; + } +}
Java
`notMatchesCondition` ํ‘œํ˜„์ด ๋ชจํ˜ธํ•˜๊ณ  ๋‘ ๊ฐ€์ง€ ์„œ๋กœ ๋‹ค๋ฅธ ์ผ์„ ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. 1. ์ž…๋ ฅ์ด ๋กœ๋˜๋ฅผ ๊ตฌ๋งคํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ์†Œ ๊ฐ’(1000)๋ฏธ๋งŒ์ธ์ง€ ๊ฒ€์ฆ 2. ์ •ํ™•ํžˆ ํ‹ฐ์ผ“ ๊ฐ€๊ฒฉ์˜ ๋ฐฐ์ˆ˜์ธ์ง€ ๊ฒ€์ฆ 1์˜ ์ƒํ™ฉ์„ 2์˜ ๋ถ€๋ถ„์ง‘ํ•ฉ์œผ๋กœ ์ƒ๊ฐํ•˜์—ฌ ๊ตฌํ˜„ํ•˜์‹  ๊ฒƒ์œผ๋กœ ์ถ”์ธก๋˜๋Š”๋ฐ, ์‚ฌ์šฉ์ž์—๊ฒŒ ์‹คํŒจ์— ๋Œ€ํ•œ ๋” ์ •ํ™•ํ•œ ์—๋Ÿฌ๋ฅผ ๊ตฌ๋ถ„ํ•˜์—ฌ ๋…ธ์ถœํ•˜๋Š” ๊ฒƒ์ด ์ข‹์ง€ ์•Š์„๊นŒ์š”?
@@ -0,0 +1,17 @@ +package lotto.domain; + +import lombok.Builder; +import lombok.Getter; +import lotto.domain.dto.WinningLottoInput; + +public class WinningLotto extends Lotto { + + @Getter + private final LottoNumber bonusNumber; + + @Builder + public WinningLotto(WinningLottoInput winningLottoInput) throws IllegalArgumentException { + super(winningLottoInput.getNumbers()); + this.bonusNumber = new LottoNumber(winningLottoInput.getBonus()); + } +}
Java
์‚ฌ์šฉ์ž ์ž…๋ ฅ(InputView)์— ๋Œ€ํ•œ ํŒŒ์‹ฑ๊ณผ ๊ฒ€์ฆ์ด ์„œ๋น„์Šค ๋ ˆ์ด์–ด๋ฅผ ํ†ต๊ณผํ•ด ๋„๋ฉ”์ธ ๋ชจ๋ธ๊นŒ์ง€ ์นจํˆฌํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ์˜์—ญ์ธ ์ปจํŠธ๋กค๋Ÿฌ ๋ ˆ์ด์–ด์—์„œ ์„ ์ž‘์—…์„ ๋ชจ๋‘ ๋งˆ๋ฌด๋ฆฌ์ง€์–ด์•ผํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€๊ธ‰์  ๋„๋ฉ”์ธ ๋ชจ๋ธ์€ ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๋ฐฉ์‹๊ณผ ๋…๋ฆฝ์ ์ด์–ด์•ผํ•ฉ๋‹ˆ๋‹ค. ์–ด๋–ค ๋ทฐ๋ฅผ ํ†ตํ•ด ์ ‘๊ทผํ•˜๋“  ๋„๋ฉ”์ธ์€ ๊ทธ ์ž์ฒด๋กœ ๋ฌธ์ œ ์˜์—ญ๋งŒ์„ ํ‘œํ˜„ํ•˜๊ณ  ํ•ด๊ฒฐํ•˜๋Š” ๋ ˆ์ด์–ด์ด์–ด์•ผํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,53 @@ +package lotto.domain; + +import lombok.Getter; + +import java.util.Objects; + +import static lotto.exception.ExceptionMessage.OUT_OF_BOUND_INPUT_FOR_LOTTO_NUMBER; + +public class LottoNumber { + + public static final int LOWER_BOUND = 1; + public static final int UPPER_BOUND = 45; + + @Getter + private final int lottoNumber; + + public LottoNumber(int lottoNumber) throws IllegalArgumentException { + validate(lottoNumber); + + this.lottoNumber = lottoNumber; + } + + private void validate(int lottoNumber) throws IllegalArgumentException { + if (isOutOfBound(lottoNumber)) { + throw new IllegalArgumentException(OUT_OF_BOUND_INPUT_FOR_LOTTO_NUMBER.getMessage()); + } + } + + private boolean isOutOfBound(int lottoNumber) { + return lottoNumber < LOWER_BOUND || lottoNumber > UPPER_BOUND; + } + + public boolean isGreaterThan(LottoNumber winningNumber) { + return this.getLottoNumber() > winningNumber.getLottoNumber(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + LottoNumber that = (LottoNumber) o; + return lottoNumber == that.lottoNumber; + } + + @Override + public int hashCode() { + return Objects.hash(lottoNumber); + } +}
Java
LottoNumber๋ฅผ ์ƒ์„ฑํ•  ๋•Œ String์œผ๋กœ ์ƒ์„ฑํ•  ํ•„์š”๊ฐ€ ์žˆ์„๊นŒ์š”? String type์œผ๋กœ ๋ฐ›๋‹ค๋ณด๋‹ˆ ํ˜•๋ณ€ํ™˜๊นŒ์ง€ ์ฑ…์ž„์ ธ์•ผํ•˜๋Š” ์ƒํ™ฉ์ด ๋˜์—ˆ๋„ค์š”.
@@ -0,0 +1,17 @@ +package lotto.domain; + +import lombok.Builder; +import lombok.Getter; +import lotto.domain.dto.WinningLottoInput; + +public class WinningLotto extends Lotto { + + @Getter + private final LottoNumber bonusNumber; + + @Builder + public WinningLotto(WinningLottoInput winningLottoInput) throws IllegalArgumentException { + super(winningLottoInput.getNumbers()); + this.bonusNumber = new LottoNumber(winningLottoInput.getBonus()); + } +}
Java
๋ฐ˜๋ณต๋ฌธ๊ณผ ์กฐ๊ฑด๋ฌธ์„ ์ค‘์ฒฉํ•ด์„œ ๋กœ์ง์ด ๋ณต์žกํ•˜๋„ค์š”. ๋” ๋‚˜์€ ๋ฐฉ์‹์œผ๋กœ ๋ฆฌํŒฉํ† ๋ง์„ ํ•ด์•ผ๊ฒ ์ฃ ?
@@ -0,0 +1,55 @@ +package lotto.domain; + +import lombok.Getter; + +@Getter +public enum Prize { + + FIRST(6, false, 2000000000), + SECOND(5, true, 30000000), + THIRD(5, false, 1500000), + FOURTH(4, false, 50000), + FIFTH(3, false, 5000), + LOSE(2, false, 0); + + private final int matchNumbersCount; + private final boolean isBonus; + private final long prizeMoney; + + Prize(int matchNumbersCount, boolean isBonus, long prizeMoney) { + this.matchNumbersCount = matchNumbersCount; + this.isBonus = isBonus; + this.prizeMoney = prizeMoney; + } + + public static Prize getMatchPrize(int matchNumbersCount, boolean isBonus) { + if (matchNumbersCount <= LOSE.matchNumbersCount) { + return LOSE; + } + if (matchNumbersCount == FIFTH.matchNumbersCount) { + return FIFTH; + } + if (matchNumbersCount == FOURTH.matchNumbersCount) { + return FOURTH; + } + if (matchNumbersCount == FIRST.matchNumbersCount) { + return FIRST; + } + return dissolveSecondOrThird(isBonus); + } + + private static Prize dissolveSecondOrThird(boolean isBonus) { + if (isBonus) { + return Prize.SECOND; + } + return Prize.THIRD; + } + + public static long sumOfPrizeMoney(PrizeCount prizeCount) { + return prizeCount.getFirst() * FIRST.prizeMoney + + prizeCount.getSecond() * SECOND.prizeMoney + + prizeCount.getThird() * THIRD.prizeMoney + + prizeCount.getFourth() * FOURTH.prizeMoney + + prizeCount.getFifth() * FIFTH.prizeMoney; + } +}
Java
Enum ํ™œ์šฉ ๐Ÿ‘
@@ -0,0 +1,35 @@ +package lotto.domain; + +import lombok.Getter; + +@Getter +public class PrizeCount { + + private int first; + private int second; + private int third; + private int fourth; + private int fifth; + + public void addPrize(Prize prize) { + if (prize == Prize.FIRST) { + first++; + return; + } + if (prize == Prize.SECOND) { + second++; + return; + } + if (prize == Prize.THIRD) { + third++; + return; + } + if (prize == Prize.FOURTH) { + fourth++; + return; + } + if (prize == Prize.FIFTH) { + fifth++; + } + } +}
Java
์ด ํด๋ž˜์Šค์˜ ์ด๋ฆ„์ด Prize**Count**์ด๋‹ˆ line 9 to 13 count ๋Š” ์ค‘๋ณต์ฒ˜๋Ÿผ ๋А๊ปด์ง€๋„ค์š”. ๋” ๋‹จ์ˆœํ•˜๊ฒŒ ๋„ค์ด๋ฐํ•ด๋„ ์˜๋ฏธ ์ „๋‹ฌ์— ๋ฌด๋ฆฌ ์—†์–ด๋ณด์ž…๋‹ˆ๋‹ค.
@@ -0,0 +1,17 @@ +package lotto.domain; + +import lombok.Builder; +import lombok.Getter; +import lotto.domain.dto.WinningLottoInput; + +public class WinningLotto extends Lotto { + + @Getter + private final LottoNumber bonusNumber; + + @Builder + public WinningLotto(WinningLottoInput winningLottoInput) throws IllegalArgumentException { + super(winningLottoInput.getNumbers()); + this.bonusNumber = new LottoNumber(winningLottoInput.getBonus()); + } +}
Java
1. ๋„ค์ด๋ฐ์—์„œ Condition๊ณผ ๊ฐ™์€ ๋ชจํ˜ธํ•œ ๋‹จ์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ข‹์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋” ๊ตฌ์ฒด์ ์ธ ํ‘œํ˜„์„ ์‚ฌ์šฉํ•˜๋„๋ก ํ•ฉ์‹œ๋‹ค. 2. find๋ผ๋Š” ํ‘œํ˜„๊ณผ get์ด๋ผ๋Š” ํ‘œํ˜„ ์‚ฌ์ด์— ๋ฏธ๋ฌ˜ํ•œ ์ฐจ์ด๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์–ด๋–ค ์ฐจ์ด์ธ์ง€๋Š” ์ฐพ์•„์„œ ๊ณต๋ถ€ํ•˜๊ณ  ์ €์—๊ฒŒ๋„ ๊ณต์œ ํ•ด์ฃผ์„ธ์š”.
@@ -0,0 +1,22 @@ +package lotto.domain; + +import lombok.Builder; +import lombok.Getter; + +public class LottoStatistics { + + @Getter + private final PrizeCount prizeCount; + private final PurchaseCount purchaseCount; + + @Builder + public LottoStatistics(PrizeCount prizeCount, PurchaseCount purchaseCount) { + this.prizeCount = prizeCount; + this.purchaseCount = purchaseCount; + } + + public double calculateProfitRate() { + return (double) Prize.sumOfPrizeMoney(prizeCount) + / (purchaseCount.getPurchaseCount() * Lotto.PRICE); + } +} \ No newline at end of file
Java
ํ†ต๊ณ„๋ฅผ ๋‹ด๋Š” ๊ฐ์ฒด๋ฅผ ๋งŒ๋“  ๊ฒƒ ์•„์ฃผ ์ข‹์Šต๋‹ˆ๋‹ค ๐Ÿ‘
@@ -0,0 +1,21 @@ +import React from 'react'; + +class InputBox extends React.Component { + // eslint-disable-next-line no-useless-constructor + constructor(props) { + super(props); + } + render() { + const { name, type, placeholder, recivedValue } = this.props; + return ( + <input + name={name} + type={type} + placeholder={placeholder} + onChange={recivedValue} + /> + ); + } +} + +export default InputBox;
JavaScript
์ด๋ถ€๋ถ„ ์™œ ์ฃผ์„์ฒ˜๋ฆฌํ•˜์…จ๋‚˜์š”? ์ด๋ ‡๊ฒŒ ์•ˆ์“ฐ๋Š” ์ฝ”๋“œ๋ฅผ ์ฃผ์„์ฒ˜๋ฆฌํ•ด์„œ ๋‚จ๊ฒจ๋‘๋ฉด ๋‹ค๋ฅธ์‚ฌ๋žŒ๋„ ์ด ์ฝ”๋“œ๊ฐ€ ์–ด๋””์— ์“ฐ์ด๋Š”๊ฑด๊ฐ€ ํ•ด์„œ ๋ชจ๋‘ ๋ชป์ง€์šฐ๊ณ  ๊ฒฐ๊ตญ ์•„๋ฌด ์“ธ๋ชจ ์—†์ง€๋งŒ ๊ณ„์† ์ „ํ•ด ๋‚ด๋ ค๊ฐ€๋Š” ์ฃผ์„์ฝ”๋“œ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค ํ•„์š”์—†๋Š” ์ฝ”๋“œ๋Š” ์‚ญ์ œํ•ด์ฃผ์„ธ์š”! ์ปค๋ฐ‹๋งŒ ์ž˜ ๋‚จ๊ฒจ๋‘๋ฉด ๋‹ค์‹œ ๋Œ์•„์˜ฌ ์ˆ˜ ์žˆ์œผ๋‹ˆ๊นŒ ๊ณผ๊ฐํ•˜๊ฒŒ ์ง€์›Œ๋„ ๋ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,21 @@ +import React from 'react'; + +class InputBox extends React.Component { + // eslint-disable-next-line no-useless-constructor + constructor(props) { + super(props); + } + render() { + const { name, type, placeholder, recivedValue } = this.props; + return ( + <input + name={name} + type={type} + placeholder={placeholder} + onChange={recivedValue} + /> + ); + } +} + +export default InputBox;
JavaScript
```suggestion const {name, type, placeholder, recivedValue} = this.props; return ( <input name={name} type={type} placeholder={placeholder} onChange={recivedValue} /> ); ``` ๊ตฌ์กฐ๋ถ„ํ•ดํ• ๋‹นํ•ด์„œ ์“ฐ๋ฉด ์ข€ ๋” ๊น”๋”ํ•˜๊ฒ ๋„ค์š”
@@ -0,0 +1,85 @@ +import React from 'react'; +import { withRouter } from 'react-router-dom'; +import InputBox from './InputBox/InputBox'; +import './JaehyunLogin.scss'; + +class JaehyunLogin extends React.Component { + constructor(props) { + super(props); + + this.state = { + userName: '', + password: '', + }; + } + + inputChangeHandler = e => { + const { name, value } = e.target; + let userIdCheck = true; + if (name === 'userName') { + this.setState({ + userName: value, + }); + userIdCheck = value.indexOf('@') === -1; + } + if (name === 'password') { + let passwordCheck = true; + this.setState({ + password: value, + }); + passwordCheck = value.length < 5; + } + }; + + goToMain = e => { + e.preventDefault(); + fetch('http://10.58.0.158:8000/users/signup', { + method: 'POST', + body: JSON.stringify({ + email: this.state.userName, + password: this.state.password, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + + this.props.history.push('./JaehyunMain'); + }; + + render() { + return ( + <main className="container"> + <div className="titleText">Westagram</div> + <form action="summit"> + <InputBox + name="userName" + type="email" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + recivedValue={this.inputChangeHandler} + /> + <InputBox + name="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + recivedValue={this.inputChangeHandler} + /> + <button + id="loginButton" + onClick={this.goToMain} + disabled={this.userIdCheck || this.passwordCheck} + style={ + this.userIdCheck || this.passwordCheck + ? { opacity: '10%' } + : { opacity: '100%' } + } + > + ๋กœ๊ทธ์ธ + </button> + </form> + <h3 className="passwordText">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</h3> + </main> + ); + } +} + +export default withRouter(JaehyunLogin);
JavaScript
import ์ˆœ์„œ ๋งž์ถฐ์ฃผ์„ธ์š”
@@ -0,0 +1,85 @@ +import React from 'react'; +import { withRouter } from 'react-router-dom'; +import InputBox from './InputBox/InputBox'; +import './JaehyunLogin.scss'; + +class JaehyunLogin extends React.Component { + constructor(props) { + super(props); + + this.state = { + userName: '', + password: '', + }; + } + + inputChangeHandler = e => { + const { name, value } = e.target; + let userIdCheck = true; + if (name === 'userName') { + this.setState({ + userName: value, + }); + userIdCheck = value.indexOf('@') === -1; + } + if (name === 'password') { + let passwordCheck = true; + this.setState({ + password: value, + }); + passwordCheck = value.length < 5; + } + }; + + goToMain = e => { + e.preventDefault(); + fetch('http://10.58.0.158:8000/users/signup', { + method: 'POST', + body: JSON.stringify({ + email: this.state.userName, + password: this.state.password, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + + this.props.history.push('./JaehyunMain'); + }; + + render() { + return ( + <main className="container"> + <div className="titleText">Westagram</div> + <form action="summit"> + <InputBox + name="userName" + type="email" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + recivedValue={this.inputChangeHandler} + /> + <InputBox + name="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + recivedValue={this.inputChangeHandler} + /> + <button + id="loginButton" + onClick={this.goToMain} + disabled={this.userIdCheck || this.passwordCheck} + style={ + this.userIdCheck || this.passwordCheck + ? { opacity: '10%' } + : { opacity: '100%' } + } + > + ๋กœ๊ทธ์ธ + </button> + </form> + <h3 className="passwordText">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</h3> + </main> + ); + } +} + +export default withRouter(JaehyunLogin);
JavaScript
peer review์— ํ•™์Šต์ž๋ฃŒ๋กœ ์ œ๊ณต๋œ ๋ฆฌํŒฉํ† ๋ง ์ฒดํฌ๋ฆฌ์ŠคํŠธ ํ™•์ธํ•ด๋ณด์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,85 @@ +import React from 'react'; +import { withRouter } from 'react-router-dom'; +import InputBox from './InputBox/InputBox'; +import './JaehyunLogin.scss'; + +class JaehyunLogin extends React.Component { + constructor(props) { + super(props); + + this.state = { + userName: '', + password: '', + }; + } + + inputChangeHandler = e => { + const { name, value } = e.target; + let userIdCheck = true; + if (name === 'userName') { + this.setState({ + userName: value, + }); + userIdCheck = value.indexOf('@') === -1; + } + if (name === 'password') { + let passwordCheck = true; + this.setState({ + password: value, + }); + passwordCheck = value.length < 5; + } + }; + + goToMain = e => { + e.preventDefault(); + fetch('http://10.58.0.158:8000/users/signup', { + method: 'POST', + body: JSON.stringify({ + email: this.state.userName, + password: this.state.password, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + + this.props.history.push('./JaehyunMain'); + }; + + render() { + return ( + <main className="container"> + <div className="titleText">Westagram</div> + <form action="summit"> + <InputBox + name="userName" + type="email" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + recivedValue={this.inputChangeHandler} + /> + <InputBox + name="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + recivedValue={this.inputChangeHandler} + /> + <button + id="loginButton" + onClick={this.goToMain} + disabled={this.userIdCheck || this.passwordCheck} + style={ + this.userIdCheck || this.passwordCheck + ? { opacity: '10%' } + : { opacity: '100%' } + } + > + ๋กœ๊ทธ์ธ + </button> + </form> + <h3 className="passwordText">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</h3> + </main> + ); + } +} + +export default withRouter(JaehyunLogin);
JavaScript
[๊ณต์‹๋ฌธ์„œ React๋กœ ์‚ฌ๊ณ ํ•˜๊ธฐ](https://ko.reactjs.org/docs/thinking-in-react.html#step-3-identify-the-minimal-but-complete-representation-of-ui-state) ๋ฅผ ๋ณด์‹œ๋ฉด ์–ด๋–ค ๊ฐ’๋“ค์ด state๊ฐ€ ๋˜์–ด์•ผํ•˜๋Š”์ง€์— ๋Œ€ํ•ด ์ ํ˜€์žˆ์Šต๋‹ˆ๋‹ค. > ๊ฐ๊ฐ ์‚ดํŽด๋ณด๊ณ  ์–ด๋–ค ๊ฒŒ state๊ฐ€ ๋˜์–ด์•ผ ํ•˜๋Š” ์ง€ ์‚ดํŽด๋ด…์‹œ๋‹ค. ์ด๋Š” ๊ฐ ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•ด ์•„๋ž˜์˜ ์„ธ ๊ฐ€์ง€ ์งˆ๋ฌธ์„ ํ†ตํ•ด ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค > 1. ๋ถ€๋ชจ๋กœ๋ถ€ํ„ฐ props๋ฅผ ํ†ตํ•ด ์ „๋‹ฌ๋ฉ๋‹ˆ๊นŒ? ๊ทธ๋Ÿฌ๋ฉด ํ™•์‹คํžˆ state๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. > 2. ์‹œ๊ฐ„์ด ์ง€๋‚˜๋„ ๋ณ€ํ•˜์ง€ ์•Š๋‚˜์š”? ๊ทธ๋Ÿฌ๋ฉด ํ™•์‹คํžˆ state๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. > 3. ์ปดํฌ๋„ŒํŠธ ์•ˆ์˜ ๋‹ค๋ฅธ state๋‚˜ props๋ฅผ ๊ฐ€์ง€๊ณ  ๊ณ„์‚ฐ ๊ฐ€๋Šฅํ•œ๊ฐ€์š”? ๊ทธ๋ ‡๋‹ค๋ฉด state๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. - userIdCheck, passwordCheck๋Š” ๋ชจ๋‘ userName, password ๊ฐ’์œผ๋กœ๋ถ€ํ„ฐ ๊ณ„์‚ฐ ๊ฐ€๋Šฅํ•œ ๊ฐ’์ž…๋‹ˆ๋‹ค -> state๋กœ ๊ด€๋ฆฌํ•  ํ•„์š” ์—†์Šต๋‹ˆ๋‹ค. - ๋ Œ๋”ํ•  ๋•Œ ๊ณ„์‚ฐํ•ด์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด ๋ณด์ž…๋‹ˆ๋‹ค.
@@ -0,0 +1,85 @@ +import React from 'react'; +import { withRouter } from 'react-router-dom'; +import InputBox from './InputBox/InputBox'; +import './JaehyunLogin.scss'; + +class JaehyunLogin extends React.Component { + constructor(props) { + super(props); + + this.state = { + userName: '', + password: '', + }; + } + + inputChangeHandler = e => { + const { name, value } = e.target; + let userIdCheck = true; + if (name === 'userName') { + this.setState({ + userName: value, + }); + userIdCheck = value.indexOf('@') === -1; + } + if (name === 'password') { + let passwordCheck = true; + this.setState({ + password: value, + }); + passwordCheck = value.length < 5; + } + }; + + goToMain = e => { + e.preventDefault(); + fetch('http://10.58.0.158:8000/users/signup', { + method: 'POST', + body: JSON.stringify({ + email: this.state.userName, + password: this.state.password, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + + this.props.history.push('./JaehyunMain'); + }; + + render() { + return ( + <main className="container"> + <div className="titleText">Westagram</div> + <form action="summit"> + <InputBox + name="userName" + type="email" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + recivedValue={this.inputChangeHandler} + /> + <InputBox + name="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + recivedValue={this.inputChangeHandler} + /> + <button + id="loginButton" + onClick={this.goToMain} + disabled={this.userIdCheck || this.passwordCheck} + style={ + this.userIdCheck || this.passwordCheck + ? { opacity: '10%' } + : { opacity: '100%' } + } + > + ๋กœ๊ทธ์ธ + </button> + </form> + <h3 className="passwordText">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</h3> + </main> + ); + } +} + +export default withRouter(JaehyunLogin);
JavaScript
์ฃผ์„ ์‚ญ์ œํ•ด์ฃผ์„ธ์š”~
@@ -0,0 +1,85 @@ +import React from 'react'; +import { withRouter } from 'react-router-dom'; +import InputBox from './InputBox/InputBox'; +import './JaehyunLogin.scss'; + +class JaehyunLogin extends React.Component { + constructor(props) { + super(props); + + this.state = { + userName: '', + password: '', + }; + } + + inputChangeHandler = e => { + const { name, value } = e.target; + let userIdCheck = true; + if (name === 'userName') { + this.setState({ + userName: value, + }); + userIdCheck = value.indexOf('@') === -1; + } + if (name === 'password') { + let passwordCheck = true; + this.setState({ + password: value, + }); + passwordCheck = value.length < 5; + } + }; + + goToMain = e => { + e.preventDefault(); + fetch('http://10.58.0.158:8000/users/signup', { + method: 'POST', + body: JSON.stringify({ + email: this.state.userName, + password: this.state.password, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + + this.props.history.push('./JaehyunMain'); + }; + + render() { + return ( + <main className="container"> + <div className="titleText">Westagram</div> + <form action="summit"> + <InputBox + name="userName" + type="email" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + recivedValue={this.inputChangeHandler} + /> + <InputBox + name="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + recivedValue={this.inputChangeHandler} + /> + <button + id="loginButton" + onClick={this.goToMain} + disabled={this.userIdCheck || this.passwordCheck} + style={ + this.userIdCheck || this.passwordCheck + ? { opacity: '10%' } + : { opacity: '100%' } + } + > + ๋กœ๊ทธ์ธ + </button> + </form> + <h3 className="passwordText">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</h3> + </main> + ); + } +} + +export default withRouter(JaehyunLogin);
JavaScript
```suggestion const { name, value } = e.target; this.setState({[name]:value}); } ``` ๊ณ„์‚ฐ๋œ ์†์„ฑ๋ช… ์‚ฌ์šฉํ•ด์„œ ์ค„์ผ ์ˆ˜ ์žˆ์–ด๋ณด์ž…๋‹ˆ๋‹ค, passwordCheck, userIdCheck๋Š” ํ•„์š”์—†๋Š” ๊ฐ’์ด๋‹ˆ๊นŒ ์—†์• ๋„ ๋˜๋ณด์ž…๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  check๋Š” ๋ญ”๊ฐ€ ์ฒดํฌ๋ฐ•์Šค๊ฐ€ ์ฒดํฌ๋˜๊ณ  ์•ˆ๋˜๊ณ  ๊ฐ™์ง€ ์•Š๋‚˜์š”? isPasswordValid ๋“ฑ์˜ ์˜๋ฏธ๊ฐ€ ๋“œ๋Ÿฌ๋‚˜๊ณ , boolean์ž„์„ ์•Œ์•„๋ณผ ์ˆ˜ ์žˆ๋Š” ๋„ค์ด๋ฐ์„ ํ•ด์ฃผ์„ธ์š”
@@ -0,0 +1,85 @@ +import React from 'react'; +import { withRouter } from 'react-router-dom'; +import InputBox from './InputBox/InputBox'; +import './JaehyunLogin.scss'; + +class JaehyunLogin extends React.Component { + constructor(props) { + super(props); + + this.state = { + userName: '', + password: '', + }; + } + + inputChangeHandler = e => { + const { name, value } = e.target; + let userIdCheck = true; + if (name === 'userName') { + this.setState({ + userName: value, + }); + userIdCheck = value.indexOf('@') === -1; + } + if (name === 'password') { + let passwordCheck = true; + this.setState({ + password: value, + }); + passwordCheck = value.length < 5; + } + }; + + goToMain = e => { + e.preventDefault(); + fetch('http://10.58.0.158:8000/users/signup', { + method: 'POST', + body: JSON.stringify({ + email: this.state.userName, + password: this.state.password, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + + this.props.history.push('./JaehyunMain'); + }; + + render() { + return ( + <main className="container"> + <div className="titleText">Westagram</div> + <form action="summit"> + <InputBox + name="userName" + type="email" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + recivedValue={this.inputChangeHandler} + /> + <InputBox + name="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + recivedValue={this.inputChangeHandler} + /> + <button + id="loginButton" + onClick={this.goToMain} + disabled={this.userIdCheck || this.passwordCheck} + style={ + this.userIdCheck || this.passwordCheck + ? { opacity: '10%' } + : { opacity: '100%' } + } + > + ๋กœ๊ทธ์ธ + </button> + </form> + <h3 className="passwordText">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</h3> + </main> + ); + } +} + +export default withRouter(JaehyunLogin);
JavaScript
๋ฐ˜๋ณต๋˜๋Š” UI๋กœ ๋ณด์ž…๋‹ˆ๋‹ค, ์ƒ์ˆ˜๋ฐ์ดํ„ฐ + Array.map method ํ™œ์šฉํ•ด์„œ ํ‘œํ˜„ํ•ด๋ณด์„ธ์š”
@@ -0,0 +1,85 @@ +import React from 'react'; +import { withRouter } from 'react-router-dom'; +import InputBox from './InputBox/InputBox'; +import './JaehyunLogin.scss'; + +class JaehyunLogin extends React.Component { + constructor(props) { + super(props); + + this.state = { + userName: '', + password: '', + }; + } + + inputChangeHandler = e => { + const { name, value } = e.target; + let userIdCheck = true; + if (name === 'userName') { + this.setState({ + userName: value, + }); + userIdCheck = value.indexOf('@') === -1; + } + if (name === 'password') { + let passwordCheck = true; + this.setState({ + password: value, + }); + passwordCheck = value.length < 5; + } + }; + + goToMain = e => { + e.preventDefault(); + fetch('http://10.58.0.158:8000/users/signup', { + method: 'POST', + body: JSON.stringify({ + email: this.state.userName, + password: this.state.password, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + + this.props.history.push('./JaehyunMain'); + }; + + render() { + return ( + <main className="container"> + <div className="titleText">Westagram</div> + <form action="summit"> + <InputBox + name="userName" + type="email" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + recivedValue={this.inputChangeHandler} + /> + <InputBox + name="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + recivedValue={this.inputChangeHandler} + /> + <button + id="loginButton" + onClick={this.goToMain} + disabled={this.userIdCheck || this.passwordCheck} + style={ + this.userIdCheck || this.passwordCheck + ? { opacity: '10%' } + : { opacity: '100%' } + } + > + ๋กœ๊ทธ์ธ + </button> + </form> + <h3 className="passwordText">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</h3> + </main> + ); + } +} + +export default withRouter(JaehyunLogin);
JavaScript
- `id` ๋ณด๋‹ค๋Š” `className` ์„ ํ™œ์šฉํ•ด์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค. - HTML์—์„œ `id` ๋Š” ๋ฌธ์„œ ๋‚ด์—์„œ ์œ ์ผํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ด์œ ๋กœ ๋‹จ์ผ ์š”์†Œ๋ฅผ ๋‹ค๋ฃจ๋Š” ๊ฒฝ์šฐ `id`๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. - ํ•˜์ง€๋งŒย ์ •๋ง๋กœ ํ•ด๋‹น ์š”์†Œ์— ๋Œ€ํ•œ ์ด๋ฒคํŠธ๋‚˜ ์Šคํƒ€์ผ ํ•ธ๋“ค๋ง์ด ํ”„๋กœ์ ํŠธ ์ „์ฒด์—์„œ ๋‹จ ํ•œ๋ฒˆ๋งŒ ์‚ฌ์šฉ ๋˜๋Š”์ง€ย ์ถฉ๋ถ„ํžˆ ๊ณ ๋ฏผํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ์ปดํฌ๋„ŒํŠธ๋Š” ์žฌ์‚ฌ์šฉ ๋  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ™์€ ์š”์†Œ๊ฐ€ ์—ฌ๋Ÿฌ๋ฒˆ ์ƒ์„ฑ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ด์œ ๋กœ ๋ณดํ†ต์˜ ๊ฒฝ์šฐ์—๋Š” `className` ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,85 @@ +import React from 'react'; +import { withRouter } from 'react-router-dom'; +import InputBox from './InputBox/InputBox'; +import './JaehyunLogin.scss'; + +class JaehyunLogin extends React.Component { + constructor(props) { + super(props); + + this.state = { + userName: '', + password: '', + }; + } + + inputChangeHandler = e => { + const { name, value } = e.target; + let userIdCheck = true; + if (name === 'userName') { + this.setState({ + userName: value, + }); + userIdCheck = value.indexOf('@') === -1; + } + if (name === 'password') { + let passwordCheck = true; + this.setState({ + password: value, + }); + passwordCheck = value.length < 5; + } + }; + + goToMain = e => { + e.preventDefault(); + fetch('http://10.58.0.158:8000/users/signup', { + method: 'POST', + body: JSON.stringify({ + email: this.state.userName, + password: this.state.password, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + + this.props.history.push('./JaehyunMain'); + }; + + render() { + return ( + <main className="container"> + <div className="titleText">Westagram</div> + <form action="summit"> + <InputBox + name="userName" + type="email" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + recivedValue={this.inputChangeHandler} + /> + <InputBox + name="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + recivedValue={this.inputChangeHandler} + /> + <button + id="loginButton" + onClick={this.goToMain} + disabled={this.userIdCheck || this.passwordCheck} + style={ + this.userIdCheck || this.passwordCheck + ? { opacity: '10%' } + : { opacity: '100%' } + } + > + ๋กœ๊ทธ์ธ + </button> + </form> + <h3 className="passwordText">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</h3> + </main> + ); + } +} + +export default withRouter(JaehyunLogin);
JavaScript
inline-style๋ณด๋‹ค className์„ ๋™์ ์œผ๋กœ ๋ฐ”๊พธ๋Š” ์‹์œผ๋กœ ์Šคํƒ€์ผ๋ง ํ•ด์ฃผ์„ธ์š”
@@ -0,0 +1,20 @@ +import React from 'react'; + +class Content extends React.Component { + constructor(props) { + super(props); + } + + render() { + return ( + <li key={this.props.key} style={{ listStyle: 'none' }}> + <span style={{ fontWeight: 'bold', marginRight: '20px' }}> + {this.props.userName} + </span> + <span>{this.props.content}</span> + </li> + ); + } +} + +export default Content;
JavaScript
state๋ฅผ ๋งŒ๋“ค์ง€ ์•Š์„ ๊ฒฝ์šฐ constructor ์•ˆํ•ด์ฃผ์…”๋„ ๋ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,20 @@ +import React from 'react'; + +class Content extends React.Component { + constructor(props) { + super(props); + } + + render() { + return ( + <li key={this.props.key} style={{ listStyle: 'none' }}> + <span style={{ fontWeight: 'bold', marginRight: '20px' }}> + {this.props.userName} + </span> + <span>{this.props.content}</span> + </li> + ); + } +} + +export default Content;
JavaScript
key props์€ Array.map method๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์—ฌ๋Ÿฌ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ๋ถ€์—ฌํ•ด์•„ํ•˜๋Š” ๊ฒƒ์ธ๋ฐ ์—ฌ๊ธฐ์„œ๋Š” map์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. key prop ๋ถ€์—ฌํ•˜๋Š” ์˜๋ฏธ๊ฐ€ ์—†์–ด๋ณด์ž…๋‹ˆ๋‹ค, ๊ทธ๋ฆฌ๊ณ  inline-style์€ ์ง€์–‘ํ•ด์ฃผ์‹œ๊ณ  className์„ ํ†ตํ•œ ์Šคํƒ€์ผ๋ง ํ•ด์ฃผ์„ธ์š”, ๋‚˜๋จธ์ง€ ๋ถ€๋ถ„๋„ ๋งˆ์ฐฌ๊ฐ€์ง€์ž…๋‹ˆ๋‹ค,
@@ -0,0 +1,26 @@ +import React from 'react'; + +class InputForm extends React.Component { + constructor(props) { + super(props); + } + + render() { + return ( + <form onSubmit={this.addContent}> + <input + name="comment" + className="replyInput" + type="text" + placeholder="๋Œ“๊ธ€๋‹ฌ๊ธฐ..." + onKeyUp={this.currentState} + /> + <button className="postButton" type="submit"> + ๊ฒŒ์‹œ + </button> + </form> + ); + } +} + +export default InputForm;
JavaScript
currenState๋ผ๋Š” ํ•จ์ˆ˜๋Š” ๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค! undefined๊ฐ€ ํ• ๋‹น๋˜๊ณ  ์žˆ์„ ๊ฒƒ ๊ฐ™๋„ค์š”
@@ -0,0 +1,26 @@ +import React from 'react'; + +class InputForm extends React.Component { + constructor(props) { + super(props); + } + + render() { + return ( + <form onSubmit={this.addContent}> + <input + name="comment" + className="replyInput" + type="text" + placeholder="๋Œ“๊ธ€๋‹ฌ๊ธฐ..." + onKeyUp={this.currentState} + /> + <button className="postButton" type="submit"> + ๊ฒŒ์‹œ + </button> + </form> + ); + } +} + +export default InputForm;
JavaScript
addContent๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์—†์–ด๋ณด์ž…๋‹ˆ๋‹ค!
@@ -0,0 +1,183 @@ +import React from 'react'; +import { withRouter } from 'react-router'; +import './JaehyunMain.scss'; +import Nav from '../../../components/Nav/Nav'; +import Content from './Content/Content'; + +class JaehyunMain extends React.Component { + constructor(props) { + super(props); + + this.state = { + userName: [], + newContent: '', + contents: [], + }; + } + + currentState = e => { + const newContent = e.target.value; + this.setState({ newContent: newContent }); + if (e.key === 'Enter') { + e.target.value = ''; + } + }; + + addContent = e => { + e.preventDefault(); + const newContent = this.state.newContent; + if (!newContent.length) { + alert('๋Œ“๊ธ€์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!!'); + return; + } + this.setState({ + contents: this.state.contents.concat(newContent), + newConetent: '', + }); + e.target.reset(); + }; + + render() { + return ( + <main className="JaehyunMain"> + <Nav /> + <section className="feedWraper"> + <article> + <div className="feedHeader"> + <div className="feedProfile"> + <img + className="feedProfileImage" + src="/images/jaehyun/hoit_logo.jpg" + alt="Profile" + /> + <div className="userId">hoit_studio</div> + </div> + <img + className="moreButtonImage" + src="/images/jaehyun/more.png" + alt="more" + /> + </div> + <img + className="firstFeed" + src="/images/jaehyun/styx.png" + alt="feedimage" + /> + <div className="feedContent"> + <div className="feedIcons"> + <div className="feedLeftIcons"> + <img + className="likeIcon" + src="/images/jaehyun/heart.png" + alt="like" + /> + <img + className="dmIcon" + src="/images/jaehyun/speech-bubble.png" + alt="dm" + /> + <img + className="shareIcon" + src="/images/jaehyun/send.png" + alt="share" + /> + </div> + <img + className="bookmarkIcon" + src="/images/jaehyun/ribbon.png" + alt="bookmark" + /> + </div> + <div className="feedDescription"> + <p className="feedLike">์ข‹์•„์š” 2๊ฐœ</p> + <span className="userId">hoit_studio</span> Styx : isonomiฤ + official trailer + <p className="hashTag">#Styx #hoitstudio</p> + <ul id="reply"> + {this.state.contents.map((content, index) => { + return ( + <Content key={index} userName={index} content={content} /> + ); + })} + </ul> + </div> + </div> + <div className="feedReply"> + <img + className="smileIcon" + src="/images/jaehyun/smile.png" + alt="smile" + /> + <form onSubmit={this.addContent}> + <input + name="comment" + className="replyInput" + type="text" + placeholder="๋Œ“๊ธ€๋‹ฌ๊ธฐ..." + onKeyUp={this.currentState} + /> + <button className="postButton" type="submit"> + ๊ฒŒ์‹œ + </button> + </form> + </div> + </article> + <aside> + <div className="account"> + <div className="accountUser"> + <img + className="accountUserIcon" + src="/images/jaehyun/hoit_logo.jpg" + alt="profile" + /> + <div className="accountUserId"> + hoit_studio + <p>hoit_studio</p> + </div> + </div> + <p>์ „ํ™˜</p> + </div> + <div className="story"> + <div className="storyTop"> + <p>์Šคํ† ๋ฆฌ</p> + <p>๋ชจ๋‘ ๋ณด๊ธฐ</p> + </div> + <div className="storyContent"> + <img + className="otherUserIcon" + src="/images/jaehyun/user.png" + alt="profile" + /> + <p className="otherUserId">hoit_studio</p> + </div> + </div> + <div className="recommendUser"> + <div className="recommendUserTop"> + <p>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</p> + <p>๋ชจ๋‘ ๋ณด๊ธฐ</p> + </div> + <div className="recommendUserContent"> + <div className="recommendUserLeftContent"> + <img + className="otherUserIcon" + src="/images/jaehyun/user.png" + alt="profile " + /> + <p className="otherUserId">hoit_studio</p> + </div> + <p>ํŒ”๋กœ์šฐ</p> + </div> + </div> + <footer> + ์†Œ๊ฐœ ใƒป ๋„์›€๋ง ใƒป ํ™๋ณด ์„ผํ„ฐ ใƒป API ใƒป ์ฑ„์šฉ ์ •๋ณด ใƒป + ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ ใƒป ์•ฝ๊ด€ ใƒป ์œ„์น˜ ใƒป ์ธ๊ธฐ ใƒป ๊ณ„์ • ใƒป ํ•ด์‹œํƒœ๊ทธ + ใƒป์–ธ์–ด ยฉ 2021 INSTAGRAM FROM FACEBOOK + </footer> + </aside> + </section> + </main> + ); + } +} + +export default withRouter(JaehyunMain);
JavaScript
```suggestion this.setState({ newContent }); ``` ๊ฐ์ฒด ๋‹จ์ถ• ์†์„ฑ๋ช…์„ ์ด์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,183 @@ +import React from 'react'; +import { withRouter } from 'react-router'; +import './JaehyunMain.scss'; +import Nav from '../../../components/Nav/Nav'; +import Content from './Content/Content'; + +class JaehyunMain extends React.Component { + constructor(props) { + super(props); + + this.state = { + userName: [], + newContent: '', + contents: [], + }; + } + + currentState = e => { + const newContent = e.target.value; + this.setState({ newContent: newContent }); + if (e.key === 'Enter') { + e.target.value = ''; + } + }; + + addContent = e => { + e.preventDefault(); + const newContent = this.state.newContent; + if (!newContent.length) { + alert('๋Œ“๊ธ€์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!!'); + return; + } + this.setState({ + contents: this.state.contents.concat(newContent), + newConetent: '', + }); + e.target.reset(); + }; + + render() { + return ( + <main className="JaehyunMain"> + <Nav /> + <section className="feedWraper"> + <article> + <div className="feedHeader"> + <div className="feedProfile"> + <img + className="feedProfileImage" + src="/images/jaehyun/hoit_logo.jpg" + alt="Profile" + /> + <div className="userId">hoit_studio</div> + </div> + <img + className="moreButtonImage" + src="/images/jaehyun/more.png" + alt="more" + /> + </div> + <img + className="firstFeed" + src="/images/jaehyun/styx.png" + alt="feedimage" + /> + <div className="feedContent"> + <div className="feedIcons"> + <div className="feedLeftIcons"> + <img + className="likeIcon" + src="/images/jaehyun/heart.png" + alt="like" + /> + <img + className="dmIcon" + src="/images/jaehyun/speech-bubble.png" + alt="dm" + /> + <img + className="shareIcon" + src="/images/jaehyun/send.png" + alt="share" + /> + </div> + <img + className="bookmarkIcon" + src="/images/jaehyun/ribbon.png" + alt="bookmark" + /> + </div> + <div className="feedDescription"> + <p className="feedLike">์ข‹์•„์š” 2๊ฐœ</p> + <span className="userId">hoit_studio</span> Styx : isonomiฤ + official trailer + <p className="hashTag">#Styx #hoitstudio</p> + <ul id="reply"> + {this.state.contents.map((content, index) => { + return ( + <Content key={index} userName={index} content={content} /> + ); + })} + </ul> + </div> + </div> + <div className="feedReply"> + <img + className="smileIcon" + src="/images/jaehyun/smile.png" + alt="smile" + /> + <form onSubmit={this.addContent}> + <input + name="comment" + className="replyInput" + type="text" + placeholder="๋Œ“๊ธ€๋‹ฌ๊ธฐ..." + onKeyUp={this.currentState} + /> + <button className="postButton" type="submit"> + ๊ฒŒ์‹œ + </button> + </form> + </div> + </article> + <aside> + <div className="account"> + <div className="accountUser"> + <img + className="accountUserIcon" + src="/images/jaehyun/hoit_logo.jpg" + alt="profile" + /> + <div className="accountUserId"> + hoit_studio + <p>hoit_studio</p> + </div> + </div> + <p>์ „ํ™˜</p> + </div> + <div className="story"> + <div className="storyTop"> + <p>์Šคํ† ๋ฆฌ</p> + <p>๋ชจ๋‘ ๋ณด๊ธฐ</p> + </div> + <div className="storyContent"> + <img + className="otherUserIcon" + src="/images/jaehyun/user.png" + alt="profile" + /> + <p className="otherUserId">hoit_studio</p> + </div> + </div> + <div className="recommendUser"> + <div className="recommendUserTop"> + <p>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</p> + <p>๋ชจ๋‘ ๋ณด๊ธฐ</p> + </div> + <div className="recommendUserContent"> + <div className="recommendUserLeftContent"> + <img + className="otherUserIcon" + src="/images/jaehyun/user.png" + alt="profile " + /> + <p className="otherUserId">hoit_studio</p> + </div> + <p>ํŒ”๋กœ์šฐ</p> + </div> + </div> + <footer> + ์†Œ๊ฐœ ใƒป ๋„์›€๋ง ใƒป ํ™๋ณด ์„ผํ„ฐ ใƒป API ใƒป ์ฑ„์šฉ ์ •๋ณด ใƒป + ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ ใƒป ์•ฝ๊ด€ ใƒป ์œ„์น˜ ใƒป ์ธ๊ธฐ ใƒป ๊ณ„์ • ใƒป ํ•ด์‹œํƒœ๊ทธ + ใƒป์–ธ์–ด ยฉ 2021 INSTAGRAM FROM FACEBOOK + </footer> + </aside> + </section> + </main> + ); + } +} + +export default withRouter(JaehyunMain);
JavaScript
alt ์†์„ฑ์ด ์ตœ์ƒ๋‹จ์— ์œ„์น˜ํ•˜๋„๋ก ์ˆœ์„œ ์กฐ์ •ํ•ด์ฃผ์„ธ์š”
@@ -0,0 +1,183 @@ +import React from 'react'; +import { withRouter } from 'react-router'; +import './JaehyunMain.scss'; +import Nav from '../../../components/Nav/Nav'; +import Content from './Content/Content'; + +class JaehyunMain extends React.Component { + constructor(props) { + super(props); + + this.state = { + userName: [], + newContent: '', + contents: [], + }; + } + + currentState = e => { + const newContent = e.target.value; + this.setState({ newContent: newContent }); + if (e.key === 'Enter') { + e.target.value = ''; + } + }; + + addContent = e => { + e.preventDefault(); + const newContent = this.state.newContent; + if (!newContent.length) { + alert('๋Œ“๊ธ€์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!!'); + return; + } + this.setState({ + contents: this.state.contents.concat(newContent), + newConetent: '', + }); + e.target.reset(); + }; + + render() { + return ( + <main className="JaehyunMain"> + <Nav /> + <section className="feedWraper"> + <article> + <div className="feedHeader"> + <div className="feedProfile"> + <img + className="feedProfileImage" + src="/images/jaehyun/hoit_logo.jpg" + alt="Profile" + /> + <div className="userId">hoit_studio</div> + </div> + <img + className="moreButtonImage" + src="/images/jaehyun/more.png" + alt="more" + /> + </div> + <img + className="firstFeed" + src="/images/jaehyun/styx.png" + alt="feedimage" + /> + <div className="feedContent"> + <div className="feedIcons"> + <div className="feedLeftIcons"> + <img + className="likeIcon" + src="/images/jaehyun/heart.png" + alt="like" + /> + <img + className="dmIcon" + src="/images/jaehyun/speech-bubble.png" + alt="dm" + /> + <img + className="shareIcon" + src="/images/jaehyun/send.png" + alt="share" + /> + </div> + <img + className="bookmarkIcon" + src="/images/jaehyun/ribbon.png" + alt="bookmark" + /> + </div> + <div className="feedDescription"> + <p className="feedLike">์ข‹์•„์š” 2๊ฐœ</p> + <span className="userId">hoit_studio</span> Styx : isonomiฤ + official trailer + <p className="hashTag">#Styx #hoitstudio</p> + <ul id="reply"> + {this.state.contents.map((content, index) => { + return ( + <Content key={index} userName={index} content={content} /> + ); + })} + </ul> + </div> + </div> + <div className="feedReply"> + <img + className="smileIcon" + src="/images/jaehyun/smile.png" + alt="smile" + /> + <form onSubmit={this.addContent}> + <input + name="comment" + className="replyInput" + type="text" + placeholder="๋Œ“๊ธ€๋‹ฌ๊ธฐ..." + onKeyUp={this.currentState} + /> + <button className="postButton" type="submit"> + ๊ฒŒ์‹œ + </button> + </form> + </div> + </article> + <aside> + <div className="account"> + <div className="accountUser"> + <img + className="accountUserIcon" + src="/images/jaehyun/hoit_logo.jpg" + alt="profile" + /> + <div className="accountUserId"> + hoit_studio + <p>hoit_studio</p> + </div> + </div> + <p>์ „ํ™˜</p> + </div> + <div className="story"> + <div className="storyTop"> + <p>์Šคํ† ๋ฆฌ</p> + <p>๋ชจ๋‘ ๋ณด๊ธฐ</p> + </div> + <div className="storyContent"> + <img + className="otherUserIcon" + src="/images/jaehyun/user.png" + alt="profile" + /> + <p className="otherUserId">hoit_studio</p> + </div> + </div> + <div className="recommendUser"> + <div className="recommendUserTop"> + <p>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</p> + <p>๋ชจ๋‘ ๋ณด๊ธฐ</p> + </div> + <div className="recommendUserContent"> + <div className="recommendUserLeftContent"> + <img + className="otherUserIcon" + src="/images/jaehyun/user.png" + alt="profile " + /> + <p className="otherUserId">hoit_studio</p> + </div> + <p>ํŒ”๋กœ์šฐ</p> + </div> + </div> + <footer> + ์†Œ๊ฐœ ใƒป ๋„์›€๋ง ใƒป ํ™๋ณด ์„ผํ„ฐ ใƒป API ใƒป ์ฑ„์šฉ ์ •๋ณด ใƒป + ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ ใƒป ์•ฝ๊ด€ ใƒป ์œ„์น˜ ใƒป ์ธ๊ธฐ ใƒป ๊ณ„์ • ใƒป ํ•ด์‹œํƒœ๊ทธ + ใƒป์–ธ์–ด ยฉ 2021 INSTAGRAM FROM FACEBOOK + </footer> + </aside> + </section> + </main> + ); + } +} + +export default withRouter(JaehyunMain);
JavaScript
className ์‚ฌ์šฉํ•ด์ฃผ์„ธ์š”
@@ -0,0 +1,280 @@ +.JaehyunMain { + .fixedTop { + position: fixed; + top: 0; + left: 0; + right: 0; + background-color: white; + border-bottom: 2px solid #ebebeb; + + nav { + display: flex; + justify-content: space-between; + padding: 15px; + max-width: 1100px; + width: 100%; + margin: 0 auto; + + .westagramTitle { + margin: 0 15px; + font-size: 25px; + font-family: 'Lobster', cursive; + cursor: pointer; + } + + .inputContainer { + position: relative; + } + + .searchInput { + width: 250px; + height: 30px; + + border: 1px solid #b2b4b7; + border-radius: 3px; + background-color: #fafafa; + padding-left: 25px; + } + + .searchIcon { + position: absolute; + top: 10px; + left: 90px; + width: 10px; + height: 10px; + } + + .searchText { + position: absolute; + top: 7px; + left: 100px; + width: 30px; + font-size: 14px; + } + + .homeIcon, + .sendIcon, + .exploreIcon, + .heartIcon, + .profileIcon { + width: 25px; + height: 25px; + margin: 0 15px; + } + + .homeIcon, + .sendIcon, + .exploreIcon, + .heartIcon, + .profileIcon:hover { + cursor: pointer; + } + } + } + + .feedWraper { + display: flex; + padding-top: 100px; + max-width: 1100px; + margin: 0 auto; + + article { + background-color: white; + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-right: 30px; + width: 700px; + text-align: center; + + .feedHeader { + display: flex; + justify-content: space-between; + align-items: center; + + height: 60px; + padding: 15px 15px; + border-bottom: 1px solid lightgray; + + .feedProfile { + display: flex; + justify-content: space-between; + align-items: center; + } + + .feedProfileImage { + width: 35px; + height: 35px; + border-radius: 70%; + } + + .userId { + margin-left: 10px; + font-weight: bold; + } + } + + .moreButtonImage { + width: 13px; + height: 13px; + cursor: pointer; + } + + .firstFeed { + width: 300px; + height: 500px; + } + + .feedIcons { + display: flex; + justify-content: space-between; + align-items: center; + padding: 0 10px; + } + + .likeIcon, + .dmIcon, + .shareIcon, + .bookmarkIcon { + width: 25px; + height: 25px; + cursor: pointer; + } + + .likeIcon, + .dmIcon, + .shareIcon { + margin-left: 15px; + } + + .feedDescription { + margin-left: 20px; + text-align: left; + } + + .feedReply { + display: flex; + justify-content: space-between; + align-items: center; + border-top: 1px solid lightgray; + padding: 10px; + margin-top: 20px; + + .replyContent { + margin-right: 100px; + } + + .smileIcon { + width: 25px; + height: 25px; + } + + .replyInput { + width: 570px; + height: 30px; + border: 0; + } + .postButton { + color: #0996f6; + border: 0; + margin-left: 5px; + cursor: pointer; + background-color: white; + } + } + .name { + font-weight: bold; + } + + .delete { + float: right; + margin-right: 20px; + cursor: pointer; + } + } + } + + aside { + width: calc(100% - 700px); + + .account { + display: flex; + justify-content: space-between; + align-items: center; + + .accountUser { + display: flex; + justify-content: center; + align-items: center; + } + + .accountUserIcon { + width: 50px; + height: 50px; + margin-right: 20px; + + border-radius: 70%; + } + } + + .story { + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-top: 20px; + } + + .storyTop { + display: flex; + justify-content: space-between; + align-items: center; + padding: 20px; + } + + .storyContent { + display: flex; + justify-content: left; + align-items: center; + padding: 10px; + } + .otherUserId { + margin-left: 10px; + font-size: 15px; + } + .otherUserIcon { + width: 30px; + height: 30px; + border-radius: 70%; + } + + .recommendUser { + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-top: 10px; + } + + .recommendUserTop { + display: flex; + justify-content: space-between; + align-items: center; + padding: 20px; + } + + .recommendUserContent { + display: flex; + justify-content: space-between; + align-items: center; + padding: 10px; + } + .recommendUserLeftContent { + display: flex; + justify-content: center; + align-items: center; + } + + footer { + color: #dfdfdf; + font-size: 12px; + text-align: left; + margin-top: 20px; + } + } +}
Unknown
์ตœ์ƒ์œ„ ๋„ค์ŠคํŒ…ํ•˜๋Š” ์š”์†Œ์˜ ํด๋ž˜์Šค๋„ค์ž„์€ ์ปดํฌ๋„ŒํŠธ ๋ช…๊ณผ ๋™์ผํ•˜๊ฒŒ ๋ถ€์—ฌํ•ด์ฃผ์‹œ๊ณ , ํด๋ž˜์Šค ๋„ค์ž„์„ ์ด์šฉํ•ด์„œ ์ตœ์ƒ์œ„ ๋„ค์ŠคํŒ…์„ ํ•ด์ฃผ์‹œ๋Š”๊ฒŒ ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ์™€ css ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•  ํ™•๋ฅ ์„ ๋‚ฎ์ถœ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,280 @@ +.JaehyunMain { + .fixedTop { + position: fixed; + top: 0; + left: 0; + right: 0; + background-color: white; + border-bottom: 2px solid #ebebeb; + + nav { + display: flex; + justify-content: space-between; + padding: 15px; + max-width: 1100px; + width: 100%; + margin: 0 auto; + + .westagramTitle { + margin: 0 15px; + font-size: 25px; + font-family: 'Lobster', cursive; + cursor: pointer; + } + + .inputContainer { + position: relative; + } + + .searchInput { + width: 250px; + height: 30px; + + border: 1px solid #b2b4b7; + border-radius: 3px; + background-color: #fafafa; + padding-left: 25px; + } + + .searchIcon { + position: absolute; + top: 10px; + left: 90px; + width: 10px; + height: 10px; + } + + .searchText { + position: absolute; + top: 7px; + left: 100px; + width: 30px; + font-size: 14px; + } + + .homeIcon, + .sendIcon, + .exploreIcon, + .heartIcon, + .profileIcon { + width: 25px; + height: 25px; + margin: 0 15px; + } + + .homeIcon, + .sendIcon, + .exploreIcon, + .heartIcon, + .profileIcon:hover { + cursor: pointer; + } + } + } + + .feedWraper { + display: flex; + padding-top: 100px; + max-width: 1100px; + margin: 0 auto; + + article { + background-color: white; + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-right: 30px; + width: 700px; + text-align: center; + + .feedHeader { + display: flex; + justify-content: space-between; + align-items: center; + + height: 60px; + padding: 15px 15px; + border-bottom: 1px solid lightgray; + + .feedProfile { + display: flex; + justify-content: space-between; + align-items: center; + } + + .feedProfileImage { + width: 35px; + height: 35px; + border-radius: 70%; + } + + .userId { + margin-left: 10px; + font-weight: bold; + } + } + + .moreButtonImage { + width: 13px; + height: 13px; + cursor: pointer; + } + + .firstFeed { + width: 300px; + height: 500px; + } + + .feedIcons { + display: flex; + justify-content: space-between; + align-items: center; + padding: 0 10px; + } + + .likeIcon, + .dmIcon, + .shareIcon, + .bookmarkIcon { + width: 25px; + height: 25px; + cursor: pointer; + } + + .likeIcon, + .dmIcon, + .shareIcon { + margin-left: 15px; + } + + .feedDescription { + margin-left: 20px; + text-align: left; + } + + .feedReply { + display: flex; + justify-content: space-between; + align-items: center; + border-top: 1px solid lightgray; + padding: 10px; + margin-top: 20px; + + .replyContent { + margin-right: 100px; + } + + .smileIcon { + width: 25px; + height: 25px; + } + + .replyInput { + width: 570px; + height: 30px; + border: 0; + } + .postButton { + color: #0996f6; + border: 0; + margin-left: 5px; + cursor: pointer; + background-color: white; + } + } + .name { + font-weight: bold; + } + + .delete { + float: right; + margin-right: 20px; + cursor: pointer; + } + } + } + + aside { + width: calc(100% - 700px); + + .account { + display: flex; + justify-content: space-between; + align-items: center; + + .accountUser { + display: flex; + justify-content: center; + align-items: center; + } + + .accountUserIcon { + width: 50px; + height: 50px; + margin-right: 20px; + + border-radius: 70%; + } + } + + .story { + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-top: 20px; + } + + .storyTop { + display: flex; + justify-content: space-between; + align-items: center; + padding: 20px; + } + + .storyContent { + display: flex; + justify-content: left; + align-items: center; + padding: 10px; + } + .otherUserId { + margin-left: 10px; + font-size: 15px; + } + .otherUserIcon { + width: 30px; + height: 30px; + border-radius: 70%; + } + + .recommendUser { + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-top: 10px; + } + + .recommendUserTop { + display: flex; + justify-content: space-between; + align-items: center; + padding: 20px; + } + + .recommendUserContent { + display: flex; + justify-content: space-between; + align-items: center; + padding: 10px; + } + .recommendUserLeftContent { + display: flex; + justify-content: center; + align-items: center; + } + + footer { + color: #dfdfdf; + font-size: 12px; + text-align: left; + margin-top: 20px; + } + } +}
Unknown
section์€ ์ด๋ฏธ display:block์˜ ์†์„ฑ์ด๊ธฐ๋•Œ๋ฌธ์—, width:100%๋ฅผ ๋ถ€์—ฌํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,280 @@ +.JaehyunMain { + .fixedTop { + position: fixed; + top: 0; + left: 0; + right: 0; + background-color: white; + border-bottom: 2px solid #ebebeb; + + nav { + display: flex; + justify-content: space-between; + padding: 15px; + max-width: 1100px; + width: 100%; + margin: 0 auto; + + .westagramTitle { + margin: 0 15px; + font-size: 25px; + font-family: 'Lobster', cursive; + cursor: pointer; + } + + .inputContainer { + position: relative; + } + + .searchInput { + width: 250px; + height: 30px; + + border: 1px solid #b2b4b7; + border-radius: 3px; + background-color: #fafafa; + padding-left: 25px; + } + + .searchIcon { + position: absolute; + top: 10px; + left: 90px; + width: 10px; + height: 10px; + } + + .searchText { + position: absolute; + top: 7px; + left: 100px; + width: 30px; + font-size: 14px; + } + + .homeIcon, + .sendIcon, + .exploreIcon, + .heartIcon, + .profileIcon { + width: 25px; + height: 25px; + margin: 0 15px; + } + + .homeIcon, + .sendIcon, + .exploreIcon, + .heartIcon, + .profileIcon:hover { + cursor: pointer; + } + } + } + + .feedWraper { + display: flex; + padding-top: 100px; + max-width: 1100px; + margin: 0 auto; + + article { + background-color: white; + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-right: 30px; + width: 700px; + text-align: center; + + .feedHeader { + display: flex; + justify-content: space-between; + align-items: center; + + height: 60px; + padding: 15px 15px; + border-bottom: 1px solid lightgray; + + .feedProfile { + display: flex; + justify-content: space-between; + align-items: center; + } + + .feedProfileImage { + width: 35px; + height: 35px; + border-radius: 70%; + } + + .userId { + margin-left: 10px; + font-weight: bold; + } + } + + .moreButtonImage { + width: 13px; + height: 13px; + cursor: pointer; + } + + .firstFeed { + width: 300px; + height: 500px; + } + + .feedIcons { + display: flex; + justify-content: space-between; + align-items: center; + padding: 0 10px; + } + + .likeIcon, + .dmIcon, + .shareIcon, + .bookmarkIcon { + width: 25px; + height: 25px; + cursor: pointer; + } + + .likeIcon, + .dmIcon, + .shareIcon { + margin-left: 15px; + } + + .feedDescription { + margin-left: 20px; + text-align: left; + } + + .feedReply { + display: flex; + justify-content: space-between; + align-items: center; + border-top: 1px solid lightgray; + padding: 10px; + margin-top: 20px; + + .replyContent { + margin-right: 100px; + } + + .smileIcon { + width: 25px; + height: 25px; + } + + .replyInput { + width: 570px; + height: 30px; + border: 0; + } + .postButton { + color: #0996f6; + border: 0; + margin-left: 5px; + cursor: pointer; + background-color: white; + } + } + .name { + font-weight: bold; + } + + .delete { + float: right; + margin-right: 20px; + cursor: pointer; + } + } + } + + aside { + width: calc(100% - 700px); + + .account { + display: flex; + justify-content: space-between; + align-items: center; + + .accountUser { + display: flex; + justify-content: center; + align-items: center; + } + + .accountUserIcon { + width: 50px; + height: 50px; + margin-right: 20px; + + border-radius: 70%; + } + } + + .story { + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-top: 20px; + } + + .storyTop { + display: flex; + justify-content: space-between; + align-items: center; + padding: 20px; + } + + .storyContent { + display: flex; + justify-content: left; + align-items: center; + padding: 10px; + } + .otherUserId { + margin-left: 10px; + font-size: 15px; + } + .otherUserIcon { + width: 30px; + height: 30px; + border-radius: 70%; + } + + .recommendUser { + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-top: 10px; + } + + .recommendUserTop { + display: flex; + justify-content: space-between; + align-items: center; + padding: 20px; + } + + .recommendUserContent { + display: flex; + justify-content: space-between; + align-items: center; + padding: 10px; + } + .recommendUserLeftContent { + display: flex; + justify-content: center; + align-items: center; + } + + footer { + color: #dfdfdf; + font-size: 12px; + text-align: left; + margin-top: 20px; + } + } +}
Unknown
๊ฐ€๋Šฅํ•œ ํƒœ๊ทธ ์…€๋ ‰ํ„ฐ๋ณด๋‹ค ํด๋ž˜์Šค๋„ค์ž„์„ ๋ถ€์—ฌํ•ด์„œ ์„ ํƒํ•ด์ฃผ์„ธ์š”! ํƒœ๊ทธ์…€๋ ‰ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ๋‹ค๋ฅธ ์š”์†Œ๋“ค์— ์˜ํ–ฅ์„ ๋ฏธ์น  ์—ฌ์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,280 @@ +.JaehyunMain { + .fixedTop { + position: fixed; + top: 0; + left: 0; + right: 0; + background-color: white; + border-bottom: 2px solid #ebebeb; + + nav { + display: flex; + justify-content: space-between; + padding: 15px; + max-width: 1100px; + width: 100%; + margin: 0 auto; + + .westagramTitle { + margin: 0 15px; + font-size: 25px; + font-family: 'Lobster', cursive; + cursor: pointer; + } + + .inputContainer { + position: relative; + } + + .searchInput { + width: 250px; + height: 30px; + + border: 1px solid #b2b4b7; + border-radius: 3px; + background-color: #fafafa; + padding-left: 25px; + } + + .searchIcon { + position: absolute; + top: 10px; + left: 90px; + width: 10px; + height: 10px; + } + + .searchText { + position: absolute; + top: 7px; + left: 100px; + width: 30px; + font-size: 14px; + } + + .homeIcon, + .sendIcon, + .exploreIcon, + .heartIcon, + .profileIcon { + width: 25px; + height: 25px; + margin: 0 15px; + } + + .homeIcon, + .sendIcon, + .exploreIcon, + .heartIcon, + .profileIcon:hover { + cursor: pointer; + } + } + } + + .feedWraper { + display: flex; + padding-top: 100px; + max-width: 1100px; + margin: 0 auto; + + article { + background-color: white; + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-right: 30px; + width: 700px; + text-align: center; + + .feedHeader { + display: flex; + justify-content: space-between; + align-items: center; + + height: 60px; + padding: 15px 15px; + border-bottom: 1px solid lightgray; + + .feedProfile { + display: flex; + justify-content: space-between; + align-items: center; + } + + .feedProfileImage { + width: 35px; + height: 35px; + border-radius: 70%; + } + + .userId { + margin-left: 10px; + font-weight: bold; + } + } + + .moreButtonImage { + width: 13px; + height: 13px; + cursor: pointer; + } + + .firstFeed { + width: 300px; + height: 500px; + } + + .feedIcons { + display: flex; + justify-content: space-between; + align-items: center; + padding: 0 10px; + } + + .likeIcon, + .dmIcon, + .shareIcon, + .bookmarkIcon { + width: 25px; + height: 25px; + cursor: pointer; + } + + .likeIcon, + .dmIcon, + .shareIcon { + margin-left: 15px; + } + + .feedDescription { + margin-left: 20px; + text-align: left; + } + + .feedReply { + display: flex; + justify-content: space-between; + align-items: center; + border-top: 1px solid lightgray; + padding: 10px; + margin-top: 20px; + + .replyContent { + margin-right: 100px; + } + + .smileIcon { + width: 25px; + height: 25px; + } + + .replyInput { + width: 570px; + height: 30px; + border: 0; + } + .postButton { + color: #0996f6; + border: 0; + margin-left: 5px; + cursor: pointer; + background-color: white; + } + } + .name { + font-weight: bold; + } + + .delete { + float: right; + margin-right: 20px; + cursor: pointer; + } + } + } + + aside { + width: calc(100% - 700px); + + .account { + display: flex; + justify-content: space-between; + align-items: center; + + .accountUser { + display: flex; + justify-content: center; + align-items: center; + } + + .accountUserIcon { + width: 50px; + height: 50px; + margin-right: 20px; + + border-radius: 70%; + } + } + + .story { + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-top: 20px; + } + + .storyTop { + display: flex; + justify-content: space-between; + align-items: center; + padding: 20px; + } + + .storyContent { + display: flex; + justify-content: left; + align-items: center; + padding: 10px; + } + .otherUserId { + margin-left: 10px; + font-size: 15px; + } + .otherUserIcon { + width: 30px; + height: 30px; + border-radius: 70%; + } + + .recommendUser { + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-top: 10px; + } + + .recommendUserTop { + display: flex; + justify-content: space-between; + align-items: center; + padding: 20px; + } + + .recommendUserContent { + display: flex; + justify-content: space-between; + align-items: center; + padding: 10px; + } + .recommendUserLeftContent { + display: flex; + justify-content: center; + align-items: center; + } + + footer { + color: #dfdfdf; + font-size: 12px; + text-align: left; + margin-top: 20px; + } + } +}
Unknown
์ด๋ ‡๊ฒŒ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ์†์„ฑ๋“ค์€ mixin์œผ๋กœ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉํ•ด๋„ ์ข‹๊ฒ ๋„ค์š”
@@ -0,0 +1,280 @@ +.JaehyunMain { + .fixedTop { + position: fixed; + top: 0; + left: 0; + right: 0; + background-color: white; + border-bottom: 2px solid #ebebeb; + + nav { + display: flex; + justify-content: space-between; + padding: 15px; + max-width: 1100px; + width: 100%; + margin: 0 auto; + + .westagramTitle { + margin: 0 15px; + font-size: 25px; + font-family: 'Lobster', cursive; + cursor: pointer; + } + + .inputContainer { + position: relative; + } + + .searchInput { + width: 250px; + height: 30px; + + border: 1px solid #b2b4b7; + border-radius: 3px; + background-color: #fafafa; + padding-left: 25px; + } + + .searchIcon { + position: absolute; + top: 10px; + left: 90px; + width: 10px; + height: 10px; + } + + .searchText { + position: absolute; + top: 7px; + left: 100px; + width: 30px; + font-size: 14px; + } + + .homeIcon, + .sendIcon, + .exploreIcon, + .heartIcon, + .profileIcon { + width: 25px; + height: 25px; + margin: 0 15px; + } + + .homeIcon, + .sendIcon, + .exploreIcon, + .heartIcon, + .profileIcon:hover { + cursor: pointer; + } + } + } + + .feedWraper { + display: flex; + padding-top: 100px; + max-width: 1100px; + margin: 0 auto; + + article { + background-color: white; + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-right: 30px; + width: 700px; + text-align: center; + + .feedHeader { + display: flex; + justify-content: space-between; + align-items: center; + + height: 60px; + padding: 15px 15px; + border-bottom: 1px solid lightgray; + + .feedProfile { + display: flex; + justify-content: space-between; + align-items: center; + } + + .feedProfileImage { + width: 35px; + height: 35px; + border-radius: 70%; + } + + .userId { + margin-left: 10px; + font-weight: bold; + } + } + + .moreButtonImage { + width: 13px; + height: 13px; + cursor: pointer; + } + + .firstFeed { + width: 300px; + height: 500px; + } + + .feedIcons { + display: flex; + justify-content: space-between; + align-items: center; + padding: 0 10px; + } + + .likeIcon, + .dmIcon, + .shareIcon, + .bookmarkIcon { + width: 25px; + height: 25px; + cursor: pointer; + } + + .likeIcon, + .dmIcon, + .shareIcon { + margin-left: 15px; + } + + .feedDescription { + margin-left: 20px; + text-align: left; + } + + .feedReply { + display: flex; + justify-content: space-between; + align-items: center; + border-top: 1px solid lightgray; + padding: 10px; + margin-top: 20px; + + .replyContent { + margin-right: 100px; + } + + .smileIcon { + width: 25px; + height: 25px; + } + + .replyInput { + width: 570px; + height: 30px; + border: 0; + } + .postButton { + color: #0996f6; + border: 0; + margin-left: 5px; + cursor: pointer; + background-color: white; + } + } + .name { + font-weight: bold; + } + + .delete { + float: right; + margin-right: 20px; + cursor: pointer; + } + } + } + + aside { + width: calc(100% - 700px); + + .account { + display: flex; + justify-content: space-between; + align-items: center; + + .accountUser { + display: flex; + justify-content: center; + align-items: center; + } + + .accountUserIcon { + width: 50px; + height: 50px; + margin-right: 20px; + + border-radius: 70%; + } + } + + .story { + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-top: 20px; + } + + .storyTop { + display: flex; + justify-content: space-between; + align-items: center; + padding: 20px; + } + + .storyContent { + display: flex; + justify-content: left; + align-items: center; + padding: 10px; + } + .otherUserId { + margin-left: 10px; + font-size: 15px; + } + .otherUserIcon { + width: 30px; + height: 30px; + border-radius: 70%; + } + + .recommendUser { + border: 2px solid #e9e9e9; + border-radius: 3px; + margin-top: 10px; + } + + .recommendUserTop { + display: flex; + justify-content: space-between; + align-items: center; + padding: 20px; + } + + .recommendUserContent { + display: flex; + justify-content: space-between; + align-items: center; + padding: 10px; + } + .recommendUserLeftContent { + display: flex; + justify-content: center; + align-items: center; + } + + footer { + color: #dfdfdf; + font-size: 12px; + text-align: left; + margin-top: 20px; + } + } +}
Unknown
์—ฐ์šฑ๋‹˜ ๋ฆฌ๋ทฐ ๋„ˆ๋ฌด ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,177 @@ +@import '../../../styles/variable.scss'; + +@mixin flex { + display: flex; + justify-content: center; + align-items: center; +} + +@mixin login-input { + width: 266px; + height: 36px; + border: $boxBorder; + background-color: #fafafa; + color: #a4a4a4; + border-radius: 2px; + margin-bottom: 6px; + font-size: 12px; + padding-left: 8px; +} + +.Login { + background-color: $backGroundColor; + + .main-box { + width: 350px; + height: 385px; + border: $boxBorder; + background-color: $white; + margin: 44px auto 10px auto; + + .logo { + font-family: 'lobster'; + font-size: 40px; + letter-spacing: -1px; + text-align: center; + margin: 40px auto; + } + + .login-wrap { + display: flex; + justify-content: center; + flex-wrap: wrap; + margin-bottom: 8px; + + .nameEmail { + @include login-input; + &:focus { + outline: 1px solid #a8a8a8; + } + } + + .passWord { + @include login-input; + &:focus { + outline: 1px solid #a8a8a8; + } + } + + .login-btn { + width: 266px; + height: 30px; + margin: 8px 0; + border: none; + border-radius: 4px; + background-color: $instaBlue; + opacity: 1; + color: $white; + font-size: 13.5px; + font-weight: bold; + cursor: pointer; + + &:disabled { + opacity: 0.5; + } + } + } + + .or-wrap { + @include flex; + + .or-line { + width: 105px; + height: 1px; + background-color: #dbdbdb; + align-items: center; + } + + .or { + font-size: 13px; + font-weight: bold; + color: #a8a8a8; + margin: 0 17px; + } + } + + .facebook-login { + @include flex; + margin: 20px auto; + color: none; + + .facebook-btn { + background-color: transparent; + border: none; + cursor: pointer; + } + + .facebook-icon { + width: 16px; + height: 16px; + margin-right: 5px; + } + + span { + color: $faceBookColor; + font-weight: bold; + position: relative; + bottom: 2px; + } + } + + .forgot-password { + color: $faceBookColor; + font-size: 12px; + text-align: center; + + .forgot-btn { + color: $faceBookColor; + background-color: transparent; + cursor: pointer; + + &:visited { + color: transparent; + } + } + } + } + + .join-box { + width: 350px; + height: 60px; + border: 1px solid #dbdbdb; + background-color: $white; + text-align: center; + margin: 0 auto 20px auto; + @include flex; + + .let-join { + font-size: 14px; + + .signup-btn { + font-weight: bold; + color: $instaBlue; + background-color: transparent; + cursor: pointer; + } + } + } + + .app-down { + .app-down-text { + text-align: center; + font-size: 14px; + } + + .download-image { + display: flex; + justify-content: center; + + .appstore-link, + .googleplay-link { + width: 136px; + height: 40px; + margin: 20px 4px; + } + } + } +}
Unknown
- index.js์—์„œ importํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์—ฌ๊ธฐ์„œ๋Š” ์•ˆํ•˜์…”๋„ ๋ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,177 @@ +@import '../../../styles/variable.scss'; + +@mixin flex { + display: flex; + justify-content: center; + align-items: center; +} + +@mixin login-input { + width: 266px; + height: 36px; + border: $boxBorder; + background-color: #fafafa; + color: #a4a4a4; + border-radius: 2px; + margin-bottom: 6px; + font-size: 12px; + padding-left: 8px; +} + +.Login { + background-color: $backGroundColor; + + .main-box { + width: 350px; + height: 385px; + border: $boxBorder; + background-color: $white; + margin: 44px auto 10px auto; + + .logo { + font-family: 'lobster'; + font-size: 40px; + letter-spacing: -1px; + text-align: center; + margin: 40px auto; + } + + .login-wrap { + display: flex; + justify-content: center; + flex-wrap: wrap; + margin-bottom: 8px; + + .nameEmail { + @include login-input; + &:focus { + outline: 1px solid #a8a8a8; + } + } + + .passWord { + @include login-input; + &:focus { + outline: 1px solid #a8a8a8; + } + } + + .login-btn { + width: 266px; + height: 30px; + margin: 8px 0; + border: none; + border-radius: 4px; + background-color: $instaBlue; + opacity: 1; + color: $white; + font-size: 13.5px; + font-weight: bold; + cursor: pointer; + + &:disabled { + opacity: 0.5; + } + } + } + + .or-wrap { + @include flex; + + .or-line { + width: 105px; + height: 1px; + background-color: #dbdbdb; + align-items: center; + } + + .or { + font-size: 13px; + font-weight: bold; + color: #a8a8a8; + margin: 0 17px; + } + } + + .facebook-login { + @include flex; + margin: 20px auto; + color: none; + + .facebook-btn { + background-color: transparent; + border: none; + cursor: pointer; + } + + .facebook-icon { + width: 16px; + height: 16px; + margin-right: 5px; + } + + span { + color: $faceBookColor; + font-weight: bold; + position: relative; + bottom: 2px; + } + } + + .forgot-password { + color: $faceBookColor; + font-size: 12px; + text-align: center; + + .forgot-btn { + color: $faceBookColor; + background-color: transparent; + cursor: pointer; + + &:visited { + color: transparent; + } + } + } + } + + .join-box { + width: 350px; + height: 60px; + border: 1px solid #dbdbdb; + background-color: $white; + text-align: center; + margin: 0 auto 20px auto; + @include flex; + + .let-join { + font-size: 14px; + + .signup-btn { + font-weight: bold; + color: $instaBlue; + background-color: transparent; + cursor: pointer; + } + } + } + + .app-down { + .app-down-text { + text-align: center; + font-size: 14px; + } + + .download-image { + display: flex; + justify-content: center; + + .appstore-link, + .googleplay-link { + width: 136px; + height: 40px; + margin: 20px 4px; + } + } + } +}
Unknown
- mixin ์‚ฌ์šฉํ•ด์ฃผ์‹  ๊ฒƒ ์ข‹์Šต๋‹ˆ๋‹ค. - ๋‹ค๋ฅธ ๋ถ„๋“ค๊นŒ์ง€ ์‚ฌ์šฉํ•˜์‹ค ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„์ด๋ผ๊ณ  ์ƒ๊ฐ๋˜์‹œ๋ฉด variables.scss๋กœ ์˜ฎ๊ฒจ์„œ ์ง„ํ–‰ํ•ด ์ฃผ์„ธ์š”.
@@ -0,0 +1,177 @@ +@import '../../../styles/variable.scss'; + +@mixin flex { + display: flex; + justify-content: center; + align-items: center; +} + +@mixin login-input { + width: 266px; + height: 36px; + border: $boxBorder; + background-color: #fafafa; + color: #a4a4a4; + border-radius: 2px; + margin-bottom: 6px; + font-size: 12px; + padding-left: 8px; +} + +.Login { + background-color: $backGroundColor; + + .main-box { + width: 350px; + height: 385px; + border: $boxBorder; + background-color: $white; + margin: 44px auto 10px auto; + + .logo { + font-family: 'lobster'; + font-size: 40px; + letter-spacing: -1px; + text-align: center; + margin: 40px auto; + } + + .login-wrap { + display: flex; + justify-content: center; + flex-wrap: wrap; + margin-bottom: 8px; + + .nameEmail { + @include login-input; + &:focus { + outline: 1px solid #a8a8a8; + } + } + + .passWord { + @include login-input; + &:focus { + outline: 1px solid #a8a8a8; + } + } + + .login-btn { + width: 266px; + height: 30px; + margin: 8px 0; + border: none; + border-radius: 4px; + background-color: $instaBlue; + opacity: 1; + color: $white; + font-size: 13.5px; + font-weight: bold; + cursor: pointer; + + &:disabled { + opacity: 0.5; + } + } + } + + .or-wrap { + @include flex; + + .or-line { + width: 105px; + height: 1px; + background-color: #dbdbdb; + align-items: center; + } + + .or { + font-size: 13px; + font-weight: bold; + color: #a8a8a8; + margin: 0 17px; + } + } + + .facebook-login { + @include flex; + margin: 20px auto; + color: none; + + .facebook-btn { + background-color: transparent; + border: none; + cursor: pointer; + } + + .facebook-icon { + width: 16px; + height: 16px; + margin-right: 5px; + } + + span { + color: $faceBookColor; + font-weight: bold; + position: relative; + bottom: 2px; + } + } + + .forgot-password { + color: $faceBookColor; + font-size: 12px; + text-align: center; + + .forgot-btn { + color: $faceBookColor; + background-color: transparent; + cursor: pointer; + + &:visited { + color: transparent; + } + } + } + } + + .join-box { + width: 350px; + height: 60px; + border: 1px solid #dbdbdb; + background-color: $white; + text-align: center; + margin: 0 auto 20px auto; + @include flex; + + .let-join { + font-size: 14px; + + .signup-btn { + font-weight: bold; + color: $instaBlue; + background-color: transparent; + cursor: pointer; + } + } + } + + .app-down { + .app-down-text { + text-align: center; + font-size: 14px; + } + + .download-image { + display: flex; + justify-content: center; + + .appstore-link, + .googleplay-link { + width: 136px; + height: 40px; + margin: 20px 4px; + } + } + } +}
Unknown
- nesting ํ•ด์ฃผ์„ธ์š”. - ๋˜ ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•œ ์†์„ฑ ์ฃผ์‹œ๋Š” ๊ฒƒ์€ ์ง€ํ–ฅํ•ด ์ฃผ์‹œ๊ณ  className์„ ํ™œ์šฉํ•ด ์ฃผ์„ธ์š”.
@@ -1,7 +1,138 @@ -import React from 'react'; +import React, { useState } from 'react'; +import { useNavigate, Link } from 'react-router-dom'; -function Login() { - return <div>Gaeul Login</div>; -} +const Login = () => { + const [inputValues, setInputValues] = useState({ + userId: '', + password: '', + }); + + const handleInput = event => { + const { name, value } = event.target; + setInputValues({ ...inputValues, [name]: value }); + }; + + const isValidLogin = !( + inputValues.userId.includes('@') && inputValues.password.length >= 5 + ); + + const navigate = useNavigate(); + + function signUp(e) { + e.preventDefault(); + fetch('http://10.58.2.36:3001/auth/signup', { + method: 'POST', + headers: { 'Content-Type': 'application/json;charset=utf-8' }, + body: JSON.stringify({ + email: inputValues.userId, + password: inputValues.password, + }), + }); + } + + function login(e) { + e.preventDefault(); + fetch('http://10.58.2.36:3001/auth/signin', { + method: 'POST', + headers: { 'Content-Type': 'application/json;charset=utf-8' }, + body: JSON.stringify({ + email: inputValues.userId, + password: inputValues.password, + }), + }) + .then(response => response.json()) + .then(data => { + if (!!data.accessToken) { + alert('ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!'); + localStorage.setItem('token', data.accessToken); + navigate('/maing'); + } else if (data.message === 'INVALID_ID') { + alert('์•„์ด๋””๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”!'); + } else if (data.message === 'INVALID_PW') { + alert('๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”!'); + } + }); + } + + return ( + <div className="Login"> + <section className="main-box"> + <div className="logo">Westagram</div> + + <form className="login-wrap" onSubmit={login}> + <input + name="userId" + type="text" + className="nameEmail" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={handleInput} + value={inputValues.userId} + /> + <input + name="password" + type="password" + className="passWord" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={handleInput} + value={inputValues.password} + /> + <button className="login-btn" disabled={isValidLogin}> + ๋กœ๊ทธ์ธ + </button> + </form> + + <div className="or-wrap"> + <div className="or-line" /> + <p className="or">๋˜๋Š”</p> + <div className="or-line" /> + </div> + + <div className="facebook-login"> + <button className="facebook-btn"> + <img + className="facebook-icon" + src="images/Gaeul/facebook_icon.png" + alt="facebook icon" + /> + <span>Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</span> + </button> + </div> + + <div className="forgot-password"> + <button className="forgot-btn">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</button> + </div> + </section> + + <section className="join-box"> + <p className="let-join"> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”? + <button className="signup-btn" onClick={signUp}> + ๊ฐ€์ž…ํ•˜๊ธฐ + </button> + </p> + </section> + + <div className="app-down"> + <p className="app-down-text">์•ฑ์„ ๋‹ค์šด๋กœ๋“œํ•˜์„ธ์š”.</p> + <div className="download-image"> + <Link to="https://apps.apple.com/app/instagram/id389801252?vt=lo"> + <img + className="appstore-link" + src="images/Gaeul/appstoredownload.png" + alt="go to appstore" + /> + </Link> + <Link to="https://play.google.com/store/apps/details?id=com.instagram.androidreferrer=utm_source%3Dinstagramweb%26utm_campaign%3DloginPage%26ig_mid%3D9B98617F-78AA-471A-A22F-E8F80A1366E9%26utm_content%3Dlo%26utm_medium%3Dbadge"> + <img + className="googleplay-link" + src="images/Gaeul/googleplaydownload.png" + alt="go to googleplay" + /> + </Link> + </div> + </div> + </div> + ); +}; export default Login;
JavaScript
- ๋ถˆํ•„์š”ํ•œ ์ฃผ์„์€ ์‚ญ์ œํ•ด ์ฃผ์„ธ์š”.
@@ -1,7 +1,138 @@ -import React from 'react'; +import React, { useState } from 'react'; +import { useNavigate, Link } from 'react-router-dom'; -function Login() { - return <div>Gaeul Login</div>; -} +const Login = () => { + const [inputValues, setInputValues] = useState({ + userId: '', + password: '', + }); + + const handleInput = event => { + const { name, value } = event.target; + setInputValues({ ...inputValues, [name]: value }); + }; + + const isValidLogin = !( + inputValues.userId.includes('@') && inputValues.password.length >= 5 + ); + + const navigate = useNavigate(); + + function signUp(e) { + e.preventDefault(); + fetch('http://10.58.2.36:3001/auth/signup', { + method: 'POST', + headers: { 'Content-Type': 'application/json;charset=utf-8' }, + body: JSON.stringify({ + email: inputValues.userId, + password: inputValues.password, + }), + }); + } + + function login(e) { + e.preventDefault(); + fetch('http://10.58.2.36:3001/auth/signin', { + method: 'POST', + headers: { 'Content-Type': 'application/json;charset=utf-8' }, + body: JSON.stringify({ + email: inputValues.userId, + password: inputValues.password, + }), + }) + .then(response => response.json()) + .then(data => { + if (!!data.accessToken) { + alert('ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!'); + localStorage.setItem('token', data.accessToken); + navigate('/maing'); + } else if (data.message === 'INVALID_ID') { + alert('์•„์ด๋””๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”!'); + } else if (data.message === 'INVALID_PW') { + alert('๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”!'); + } + }); + } + + return ( + <div className="Login"> + <section className="main-box"> + <div className="logo">Westagram</div> + + <form className="login-wrap" onSubmit={login}> + <input + name="userId" + type="text" + className="nameEmail" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={handleInput} + value={inputValues.userId} + /> + <input + name="password" + type="password" + className="passWord" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={handleInput} + value={inputValues.password} + /> + <button className="login-btn" disabled={isValidLogin}> + ๋กœ๊ทธ์ธ + </button> + </form> + + <div className="or-wrap"> + <div className="or-line" /> + <p className="or">๋˜๋Š”</p> + <div className="or-line" /> + </div> + + <div className="facebook-login"> + <button className="facebook-btn"> + <img + className="facebook-icon" + src="images/Gaeul/facebook_icon.png" + alt="facebook icon" + /> + <span>Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</span> + </button> + </div> + + <div className="forgot-password"> + <button className="forgot-btn">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</button> + </div> + </section> + + <section className="join-box"> + <p className="let-join"> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”? + <button className="signup-btn" onClick={signUp}> + ๊ฐ€์ž…ํ•˜๊ธฐ + </button> + </p> + </section> + + <div className="app-down"> + <p className="app-down-text">์•ฑ์„ ๋‹ค์šด๋กœ๋“œํ•˜์„ธ์š”.</p> + <div className="download-image"> + <Link to="https://apps.apple.com/app/instagram/id389801252?vt=lo"> + <img + className="appstore-link" + src="images/Gaeul/appstoredownload.png" + alt="go to appstore" + /> + </Link> + <Link to="https://play.google.com/store/apps/details?id=com.instagram.androidreferrer=utm_source%3Dinstagramweb%26utm_campaign%3DloginPage%26ig_mid%3D9B98617F-78AA-471A-A22F-E8F80A1366E9%26utm_content%3Dlo%26utm_medium%3Dbadge"> + <img + className="googleplay-link" + src="images/Gaeul/googleplaydownload.png" + alt="go to googleplay" + /> + </Link> + </div> + </div> + </div> + ); +}; export default Login;
JavaScript
- ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•ด ์ฃผ์‹œ๊ณ  className์€ ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ๋กœ ํ•ด์ฃผ์„ธ์š”.
@@ -1,7 +1,138 @@ -import React from 'react'; +import React, { useState } from 'react'; +import { useNavigate, Link } from 'react-router-dom'; -function Login() { - return <div>Gaeul Login</div>; -} +const Login = () => { + const [inputValues, setInputValues] = useState({ + userId: '', + password: '', + }); + + const handleInput = event => { + const { name, value } = event.target; + setInputValues({ ...inputValues, [name]: value }); + }; + + const isValidLogin = !( + inputValues.userId.includes('@') && inputValues.password.length >= 5 + ); + + const navigate = useNavigate(); + + function signUp(e) { + e.preventDefault(); + fetch('http://10.58.2.36:3001/auth/signup', { + method: 'POST', + headers: { 'Content-Type': 'application/json;charset=utf-8' }, + body: JSON.stringify({ + email: inputValues.userId, + password: inputValues.password, + }), + }); + } + + function login(e) { + e.preventDefault(); + fetch('http://10.58.2.36:3001/auth/signin', { + method: 'POST', + headers: { 'Content-Type': 'application/json;charset=utf-8' }, + body: JSON.stringify({ + email: inputValues.userId, + password: inputValues.password, + }), + }) + .then(response => response.json()) + .then(data => { + if (!!data.accessToken) { + alert('ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!'); + localStorage.setItem('token', data.accessToken); + navigate('/maing'); + } else if (data.message === 'INVALID_ID') { + alert('์•„์ด๋””๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”!'); + } else if (data.message === 'INVALID_PW') { + alert('๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”!'); + } + }); + } + + return ( + <div className="Login"> + <section className="main-box"> + <div className="logo">Westagram</div> + + <form className="login-wrap" onSubmit={login}> + <input + name="userId" + type="text" + className="nameEmail" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={handleInput} + value={inputValues.userId} + /> + <input + name="password" + type="password" + className="passWord" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={handleInput} + value={inputValues.password} + /> + <button className="login-btn" disabled={isValidLogin}> + ๋กœ๊ทธ์ธ + </button> + </form> + + <div className="or-wrap"> + <div className="or-line" /> + <p className="or">๋˜๋Š”</p> + <div className="or-line" /> + </div> + + <div className="facebook-login"> + <button className="facebook-btn"> + <img + className="facebook-icon" + src="images/Gaeul/facebook_icon.png" + alt="facebook icon" + /> + <span>Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</span> + </button> + </div> + + <div className="forgot-password"> + <button className="forgot-btn">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</button> + </div> + </section> + + <section className="join-box"> + <p className="let-join"> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”? + <button className="signup-btn" onClick={signUp}> + ๊ฐ€์ž…ํ•˜๊ธฐ + </button> + </p> + </section> + + <div className="app-down"> + <p className="app-down-text">์•ฑ์„ ๋‹ค์šด๋กœ๋“œํ•˜์„ธ์š”.</p> + <div className="download-image"> + <Link to="https://apps.apple.com/app/instagram/id389801252?vt=lo"> + <img + className="appstore-link" + src="images/Gaeul/appstoredownload.png" + alt="go to appstore" + /> + </Link> + <Link to="https://play.google.com/store/apps/details?id=com.instagram.androidreferrer=utm_source%3Dinstagramweb%26utm_campaign%3DloginPage%26ig_mid%3D9B98617F-78AA-471A-A22F-E8F80A1366E9%26utm_content%3Dlo%26utm_medium%3Dbadge"> + <img + className="googleplay-link" + src="images/Gaeul/googleplaydownload.png" + alt="go to googleplay" + /> + </Link> + </div> + </div> + </div> + ); +}; export default Login;
JavaScript
- return ์•ˆ์ชฝ์€ render์™€ ๊ด€๋ จ๋œ ๋ถ€๋ถ„์ด๋ผ ๋กœ์ง์€ ์ตœ๋Œ€ํ•œ ํ•จ์ˆ˜ ์˜์—ญ์— ์ž‘์„ฑํ•ด ์ฃผ์„ธ์š”.
@@ -1,7 +1,138 @@ -import React from 'react'; +import React, { useState } from 'react'; +import { useNavigate, Link } from 'react-router-dom'; -function Login() { - return <div>Gaeul Login</div>; -} +const Login = () => { + const [inputValues, setInputValues] = useState({ + userId: '', + password: '', + }); + + const handleInput = event => { + const { name, value } = event.target; + setInputValues({ ...inputValues, [name]: value }); + }; + + const isValidLogin = !( + inputValues.userId.includes('@') && inputValues.password.length >= 5 + ); + + const navigate = useNavigate(); + + function signUp(e) { + e.preventDefault(); + fetch('http://10.58.2.36:3001/auth/signup', { + method: 'POST', + headers: { 'Content-Type': 'application/json;charset=utf-8' }, + body: JSON.stringify({ + email: inputValues.userId, + password: inputValues.password, + }), + }); + } + + function login(e) { + e.preventDefault(); + fetch('http://10.58.2.36:3001/auth/signin', { + method: 'POST', + headers: { 'Content-Type': 'application/json;charset=utf-8' }, + body: JSON.stringify({ + email: inputValues.userId, + password: inputValues.password, + }), + }) + .then(response => response.json()) + .then(data => { + if (!!data.accessToken) { + alert('ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!'); + localStorage.setItem('token', data.accessToken); + navigate('/maing'); + } else if (data.message === 'INVALID_ID') { + alert('์•„์ด๋””๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”!'); + } else if (data.message === 'INVALID_PW') { + alert('๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”!'); + } + }); + } + + return ( + <div className="Login"> + <section className="main-box"> + <div className="logo">Westagram</div> + + <form className="login-wrap" onSubmit={login}> + <input + name="userId" + type="text" + className="nameEmail" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={handleInput} + value={inputValues.userId} + /> + <input + name="password" + type="password" + className="passWord" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={handleInput} + value={inputValues.password} + /> + <button className="login-btn" disabled={isValidLogin}> + ๋กœ๊ทธ์ธ + </button> + </form> + + <div className="or-wrap"> + <div className="or-line" /> + <p className="or">๋˜๋Š”</p> + <div className="or-line" /> + </div> + + <div className="facebook-login"> + <button className="facebook-btn"> + <img + className="facebook-icon" + src="images/Gaeul/facebook_icon.png" + alt="facebook icon" + /> + <span>Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</span> + </button> + </div> + + <div className="forgot-password"> + <button className="forgot-btn">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</button> + </div> + </section> + + <section className="join-box"> + <p className="let-join"> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”? + <button className="signup-btn" onClick={signUp}> + ๊ฐ€์ž…ํ•˜๊ธฐ + </button> + </p> + </section> + + <div className="app-down"> + <p className="app-down-text">์•ฑ์„ ๋‹ค์šด๋กœ๋“œํ•˜์„ธ์š”.</p> + <div className="download-image"> + <Link to="https://apps.apple.com/app/instagram/id389801252?vt=lo"> + <img + className="appstore-link" + src="images/Gaeul/appstoredownload.png" + alt="go to appstore" + /> + </Link> + <Link to="https://play.google.com/store/apps/details?id=com.instagram.androidreferrer=utm_source%3Dinstagramweb%26utm_campaign%3DloginPage%26ig_mid%3D9B98617F-78AA-471A-A22F-E8F80A1366E9%26utm_content%3Dlo%26utm_medium%3Dbadge"> + <img + className="googleplay-link" + src="images/Gaeul/googleplaydownload.png" + alt="go to googleplay" + /> + </Link> + </div> + </div> + </div> + ); +}; export default Login;
JavaScript
- navigate๋Š” ์กฐ๊ฑด์ด ์žˆ์„ ๋•Œ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. - ๊ทธ๊ฒŒ ์•„๋‹ˆ๋ผ๋ฉด ๋ง์”€ํ•˜์‹  ๊ฒƒ ์ฒ˜๋Ÿผ Link ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ™œ์šฉํ•˜์…”๋„ ๋ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,100 @@ +@import '../../../styles/variable.scss'; + +p { + font-family: 'Roboto'; + letter-spacing: 0.2px; +} + +.Main { + background-color: $backGroundColor; + + .main { + display: flex; + justify-content: center; + padding-bottom: 100px; + + .main-right { + width: 250px; + height: 500px; + + .id-info-box { + display: flex; + justify-content: left; + align-items: center; + padding-left: 5px; + margin-bottom: 15px; + + .my-image { + width: 45px; + height: 45px; + border-radius: 50%; + background-color: black; + margin-right: 10px; + } + + .my-info { + p { + font-size: 14px; + } + + #my-id { + font-weight: 500; + margin-bottom: 3px; + } + + #my-id-text { + color: #adafb1; + } + } + } + + .site-info { + width: 220px; + display: flex; + flex-wrap: wrap; + + .site-info-list { + color: #c3c5c7; + font-size: 12px; + margin-bottom: 5px; + + a { + color: #c3c5c7; + } + + &:not(:last-child)::after { + content: '\00B7'; + color: lightgray; + margin: 0 3px; + } + } + + p { + color: #c3c5c7; + font-size: 12px; + margin-top: 15px; + line-height: 15px; + } + } + } + } +} + +/* media query */ +@media screen and (max-width: 750px) { + .header-wrap { + max-width: 750px; + } + + .main { + display: block; + + .feeds { + margin: 0 auto; + } + } + + .main-right { + display: none; + } +}
Unknown
- body๋Š” ๋‹ค๋ฅธ ํŽ˜์ด์ง€์—๋„ ์˜ํ–ฅ์„ ์ค„ ์ˆ˜ ์žˆ๊ฒ ๋„ค์š” - ํ•„์š”ํ•œ ๋ถ€๋ถ„์ด๋ผ๋ฉด common.scss์—์„œ ์ง„ํ–‰๋˜๊ฑฐ๋‚˜ ํŒ€์›๋“ค๊ณผ ๋…ผ์˜ ํ›„ ์ง„ํ–‰ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,100 @@ +@import '../../../styles/variable.scss'; + +p { + font-family: 'Roboto'; + letter-spacing: 0.2px; +} + +.Main { + background-color: $backGroundColor; + + .main { + display: flex; + justify-content: center; + padding-bottom: 100px; + + .main-right { + width: 250px; + height: 500px; + + .id-info-box { + display: flex; + justify-content: left; + align-items: center; + padding-left: 5px; + margin-bottom: 15px; + + .my-image { + width: 45px; + height: 45px; + border-radius: 50%; + background-color: black; + margin-right: 10px; + } + + .my-info { + p { + font-size: 14px; + } + + #my-id { + font-weight: 500; + margin-bottom: 3px; + } + + #my-id-text { + color: #adafb1; + } + } + } + + .site-info { + width: 220px; + display: flex; + flex-wrap: wrap; + + .site-info-list { + color: #c3c5c7; + font-size: 12px; + margin-bottom: 5px; + + a { + color: #c3c5c7; + } + + &:not(:last-child)::after { + content: '\00B7'; + color: lightgray; + margin: 0 3px; + } + } + + p { + color: #c3c5c7; + font-size: 12px; + margin-top: 15px; + line-height: 15px; + } + } + } + } +} + +/* media query */ +@media screen and (max-width: 750px) { + .header-wrap { + max-width: 750px; + } + + .main { + display: block; + + .feeds { + margin: 0 auto; + } + } + + .main-right { + display: none; + } +}
Unknown
- ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ถ„๋ฆฌํ•˜์…จ๋‹ค๋ฉด ํ•ด๋‹น css๋„ ๋ถ„๋ฆฌํ•˜์…”์„œ ์ง„ํ–‰ํ•˜์‹œ๋Š” ๊ฒŒ ๊ฐ€๋…์„ฑ์—๋„ ์ข‹๊ฒ ๋„ค์š”.
@@ -0,0 +1,82 @@ +import React, { useState } from 'react'; +import CommentList from './CommentList'; + +const Feeds = ({ feedData }) => { + const [input, setInput] = useState(''); + const [inputList, setInputList] = useState([]); + + const post = event => { + event.preventDefault(); + setInputList(inputList.concat(input)); + setInput(''); + }; + + const handleInput = event => { + setInput(event.target.value); + }; + + return ( + <div className="feeds" key={feedData.userId}> + <div className="user-bar"> + <div className="user"> + <div className="user-image" /> + <em className="user-id">{feedData.userId}</em> + </div> + <button id="feed-dot"> + <i className="fa-solid fa-ellipsis" /> + </button> + </div> + + <img className="article-img" src={feedData.url} alt="ํ”ผ๋“œ์ด๋ฏธ์ง€" /> + + <div className="article-icons"> + <div className="article-three-icons"> + <button> + <i className="fa-regular fa-heart" /> + </button> + <button> + <i className="fa-regular fa-comment" /> + </button> + <button> + <i className="fa-solid fa-arrow-up-from-bracket" /> + </button> + </div> + + <button className="bookmark"> + <i className="fa-regular fa-bookmark" /> + </button> + </div> + + <div className="like-user"> + <div className="like-user-img" /> + <p> + <b>{feedData.likeUser}</b>๋‹˜ ์™ธ <b>{feedData.like}๋ช…</b>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </p> + </div> + + <ul className="comments-ul"> + {inputList.map((input, idx) => { + return <CommentList key={idx} item={input} />; + })} + </ul> + + <form className="lets-comment" onSubmit={post}> + <input + className="comment-input" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onChange={handleInput} + value={input} + /> + <button + className={input ? 'submitCommentActive' : 'submitCommentInactive'} + disabled={!input} + > + ๊ฒŒ์‹œ + </button> + </form> + </div> + ); +}; + +export default Feeds;
JavaScript
- className์€ ์ปดํฌ๋„ŒํŠธ๋ช…๊ณผ ๊ฐ™๊ฒŒ ํ•ด์ฃผ์„ธ์š”.
@@ -0,0 +1,82 @@ +import React, { useState } from 'react'; +import CommentList from './CommentList'; + +const Feeds = ({ feedData }) => { + const [input, setInput] = useState(''); + const [inputList, setInputList] = useState([]); + + const post = event => { + event.preventDefault(); + setInputList(inputList.concat(input)); + setInput(''); + }; + + const handleInput = event => { + setInput(event.target.value); + }; + + return ( + <div className="feeds" key={feedData.userId}> + <div className="user-bar"> + <div className="user"> + <div className="user-image" /> + <em className="user-id">{feedData.userId}</em> + </div> + <button id="feed-dot"> + <i className="fa-solid fa-ellipsis" /> + </button> + </div> + + <img className="article-img" src={feedData.url} alt="ํ”ผ๋“œ์ด๋ฏธ์ง€" /> + + <div className="article-icons"> + <div className="article-three-icons"> + <button> + <i className="fa-regular fa-heart" /> + </button> + <button> + <i className="fa-regular fa-comment" /> + </button> + <button> + <i className="fa-solid fa-arrow-up-from-bracket" /> + </button> + </div> + + <button className="bookmark"> + <i className="fa-regular fa-bookmark" /> + </button> + </div> + + <div className="like-user"> + <div className="like-user-img" /> + <p> + <b>{feedData.likeUser}</b>๋‹˜ ์™ธ <b>{feedData.like}๋ช…</b>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </p> + </div> + + <ul className="comments-ul"> + {inputList.map((input, idx) => { + return <CommentList key={idx} item={input} />; + })} + </ul> + + <form className="lets-comment" onSubmit={post}> + <input + className="comment-input" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onChange={handleInput} + value={input} + /> + <button + className={input ? 'submitCommentActive' : 'submitCommentInactive'} + disabled={!input} + > + ๊ฒŒ์‹œ + </button> + </form> + </div> + ); +}; + +export default Feeds;
JavaScript
- alt๋Š” ์œ ์ €๊ฐ€ ๋ณด๋Š” ํ…์ŠคํŠธ ์ž…๋‹ˆ๋‹ค. - ์œ ์ € ์ž…์žฅ์—์„œ ์ž‘์„ฑํ•ด ์ฃผ์„ธ์š”.
@@ -0,0 +1,82 @@ +import React, { useState } from 'react'; +import CommentList from './CommentList'; + +const Feeds = ({ feedData }) => { + const [input, setInput] = useState(''); + const [inputList, setInputList] = useState([]); + + const post = event => { + event.preventDefault(); + setInputList(inputList.concat(input)); + setInput(''); + }; + + const handleInput = event => { + setInput(event.target.value); + }; + + return ( + <div className="feeds" key={feedData.userId}> + <div className="user-bar"> + <div className="user"> + <div className="user-image" /> + <em className="user-id">{feedData.userId}</em> + </div> + <button id="feed-dot"> + <i className="fa-solid fa-ellipsis" /> + </button> + </div> + + <img className="article-img" src={feedData.url} alt="ํ”ผ๋“œ์ด๋ฏธ์ง€" /> + + <div className="article-icons"> + <div className="article-three-icons"> + <button> + <i className="fa-regular fa-heart" /> + </button> + <button> + <i className="fa-regular fa-comment" /> + </button> + <button> + <i className="fa-solid fa-arrow-up-from-bracket" /> + </button> + </div> + + <button className="bookmark"> + <i className="fa-regular fa-bookmark" /> + </button> + </div> + + <div className="like-user"> + <div className="like-user-img" /> + <p> + <b>{feedData.likeUser}</b>๋‹˜ ์™ธ <b>{feedData.like}๋ช…</b>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </p> + </div> + + <ul className="comments-ul"> + {inputList.map((input, idx) => { + return <CommentList key={idx} item={input} />; + })} + </ul> + + <form className="lets-comment" onSubmit={post}> + <input + className="comment-input" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onChange={handleInput} + value={input} + /> + <button + className={input ? 'submitCommentActive' : 'submitCommentInactive'} + disabled={!input} + > + ๊ฒŒ์‹œ + </button> + </form> + </div> + ); +}; + +export default Feeds;
JavaScript
- onKeyup ๋ณด๋‹ค๋Š” ๋ณ€์ˆ˜๋กœ ๋™์  ๊ด€๋ฆฌ๋ฅผ ํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. - ๋ณ€์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด ๋™์ ์œผ๋กœ ๊ด€๋ฆฌํ•œ๋‹ค๋ฉด state๊ฐ€ ์—†์–ด๋„ ๋˜๊ฒ ๋„ค์š”.
@@ -0,0 +1,82 @@ +import React, { useState } from 'react'; +import CommentList from './CommentList'; + +const Feeds = ({ feedData }) => { + const [input, setInput] = useState(''); + const [inputList, setInputList] = useState([]); + + const post = event => { + event.preventDefault(); + setInputList(inputList.concat(input)); + setInput(''); + }; + + const handleInput = event => { + setInput(event.target.value); + }; + + return ( + <div className="feeds" key={feedData.userId}> + <div className="user-bar"> + <div className="user"> + <div className="user-image" /> + <em className="user-id">{feedData.userId}</em> + </div> + <button id="feed-dot"> + <i className="fa-solid fa-ellipsis" /> + </button> + </div> + + <img className="article-img" src={feedData.url} alt="ํ”ผ๋“œ์ด๋ฏธ์ง€" /> + + <div className="article-icons"> + <div className="article-three-icons"> + <button> + <i className="fa-regular fa-heart" /> + </button> + <button> + <i className="fa-regular fa-comment" /> + </button> + <button> + <i className="fa-solid fa-arrow-up-from-bracket" /> + </button> + </div> + + <button className="bookmark"> + <i className="fa-regular fa-bookmark" /> + </button> + </div> + + <div className="like-user"> + <div className="like-user-img" /> + <p> + <b>{feedData.likeUser}</b>๋‹˜ ์™ธ <b>{feedData.like}๋ช…</b>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </p> + </div> + + <ul className="comments-ul"> + {inputList.map((input, idx) => { + return <CommentList key={idx} item={input} />; + })} + </ul> + + <form className="lets-comment" onSubmit={post}> + <input + className="comment-input" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onChange={handleInput} + value={input} + /> + <button + className={input ? 'submitCommentActive' : 'submitCommentInactive'} + disabled={!input} + > + ๊ฒŒ์‹œ + </button> + </form> + </div> + ); +}; + +export default Feeds;
JavaScript
- form ํƒœ๊ทธ ์•ˆ์— ์žˆ๋‹ค๋ฉด ๋ฒ„ํŠผ์—๋Š” ๋”ฐ๋กœ onClick์„ ๋ถ€์—ฌํ•˜์ง€ ์•Š์œผ์…”๋„ ๋ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,261 @@ +// +// LoginViewController_TVING.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/11. +// + +import UIKit + +import SnapKit +import Then + +struct TvingUserInfo { + var id: String? + var password: String? + var nickName: String? +} + +final class LoginViewController_TVING: BaseViewController { + + // MARK: - Property + + private let mainView = LoginView() + private let nickNameBottomSheet = AddNickNameBottomSheetUIView() + + var user = TvingUserInfo() + + private var bottomSheetKeyboardEnable: Bool = false + + // MARK: - Target + + private func target() { + mainView.idTextField.delegate = self + mainView.passwordTextField.delegate = self + + mainView.idTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + mainView.passwordTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + mainView.logInBtn.addTarget(self, action: #selector(tappedLogInBtn), for: .touchUpInside) + mainView.goToMakeNicknameBtn.addTarget(self, action: #selector(tappedMakeNickNameBtn), for: .touchUpInside) + } + + private func targetBottomSheet() { + nickNameBottomSheet.nickNameTextField.delegate = self + + nickNameBottomSheet.nickNameTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + nickNameBottomSheet.saveNickNameBtn.addTarget(self, action: #selector(tappedSavedNickNameBtn), for: .touchUpInside) + + let bottomSheetBackgroundTap = UITapGestureRecognizer(target: self, action: #selector(TappedBottomSheetBackground)) + nickNameBottomSheet.dimmendView.addGestureRecognizer(bottomSheetBackgroundTap) + } + + // MARK: - Lift Cycle + + override func loadView() { + self.view = mainView + view.addSubview(nickNameBottomSheet) + + nickNameBottomSheet.snp.makeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + target() + targetBottomSheet() + setKeyboardObserver() // ํ‚ค๋ณด๋“œ ํ™œ์„ฑํ™”์— ๋”ฐ๋ฅธ bottomSheet ๋†’์ด ์กฐ์ ˆ ์œ„ํ•ด + } + + override func viewWillAppear(_ animated: Bool) { + initView() + } + +} + +private extension LoginViewController_TVING { + + // MARK: - objc func + + @objc + func tappedLogInBtn() { + saveUserEmail() + let welcomViewController = WelcomeViewController() + welcomViewController.idDataBind(idOrNick: getNickNameOrId()) + self.navigationController?.pushViewController(welcomViewController, animated: true) + } + + @objc + func tappedMakeNickNameBtn() { + showBottomSheet() + } + + @objc + func tappedSavedNickNameBtn() { + saveUserNickName() + hideBottomSheet() + } + + @objc func TappedBottomSheetBackground(_ tapRecognizer: UITapGestureRecognizer) { + hideBottomSheet() + } + + @objc func keyboardWillShow(notification: NSNotification) { + guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return } + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - (nickNameBottomSheet.bottomSheetHeight + keyboardSize.height) + } + } + + @objc func keyboardWillHide(notification: NSNotification) { + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - nickNameBottomSheet.bottomSheetHeight + } + } + + // MARK: - custom func + + func saveUserEmail(){ + guard let id = mainView.idTextField.text else { return } + user.id = id + } + + func saveUserNickName() { + guard let nickName = nickNameBottomSheet.nickNameTextField.text else { return } + user.nickName = nickName + } + + func getNickNameOrId() -> String { + if let nickName = user.nickName { + return nickName + } else { + guard let id = user.id else { return "" } + return id + } + } + + func isIDValid() -> Bool { + guard let id = mainView.idTextField.text else { return false } + return id.isValidEmail() + } + + func showBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = true + nickNameBottomSheet.snp.remakeConstraints { + $0.edges.equalToSuperview() + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height) + }) + } + + func hideBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = false + nickNameBottomSheet.snp.remakeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: self.view.frame.height, width: self.view.frame.width, height: self.view.frame.height) + } + ) + } + + func initView() { + mainView.idTextField.text = nil + mainView.passwordTextField.text = nil + nickNameBottomSheet.nickNameTextField.text = nil + user = TvingUserInfo() + mainView.logInBtn.enableDisableButtonSet(isEnable: false, setColor: .black, setTextColor: .tvingGray2) + } + + func setKeyboardObserver() { + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + } + +} + +// MARK: - TextFieldDelegate + +extension LoginViewController_TVING: UITextFieldDelegate { + + // textField๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldDidBeginEditing(_ textField: UITextField) { + textField.layer.borderColor = UIColor.tvingGray2.cgColor + textField.layer.borderWidth = 0.7 + } + + // textField ๋น„ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { + textField.layer.borderWidth = 0 + + idValidPrint() + + return true + } + + @objc + private func textFieldDidChange(_ textField: UITextField) { + + if let nickNameText = nickNameBottomSheet.nickNameTextField.text { + if (!nickNameText.isValidNickName()) { + nickNameBottomSheet.nickNameTextField.text = nil + } + } + + let idPwIsFull: Bool = mainView.idTextField.hasText && !mainView.passwordTextField.hasText + let saveIdPwBtnEnable: Bool = idPwIsFull && isIDValid() + + if (saveIdPwBtnEnable) { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + + let saveNickNameBtnEnable = !nickNameBottomSheet.nickNameTextField.hasText + + if (saveNickNameBtnEnable) { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + } + + private func idValidPrint() { + + if (!(mainView.idTextField.text?.isValidEmail() ?? false) && !mainView.idTextField.hasText) { + mainView.idTextField.layer.borderColor = UIColor.tvingRed.cgColor + mainView.idTextField.layer.borderWidth = 0.7 + + mainView.idInvalidLabel.isHidden = false + mainView.idInvalidLabel.snp.remakeConstraints { + $0.leading.equalTo(mainView.idTextField.snp.leading) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(5) + } + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(30) + $0.leading.trailing.equalToSuperview().inset(20) + } + } else { + mainView.idTextField.layer.borderWidth = 0 + + mainView.idInvalidLabel.isHidden = true + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + } + } + +}
Swift
์–ด๋–ค TextField์ธ์ง€ ๋ช…์‹œ ์•ˆํ•ด์ฃผ๊ณ  editing์ด ์‹œ์ž‘๋œ textField์—๋Š” ์ž๋™์œผ๋กœ ์ ์šฉ๋˜๋Š”๊ตฌ๋‚˜ ์˜ค ์ƒ๊ฐ๋ชปํ–ˆ๋Š”๋ฐ ๋ฐฐ์› ์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž๊ฐ์‚ฌํ•ด์š”
@@ -0,0 +1,205 @@ +// +// LoginView.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/16. +// + +import UIKit + +class LoginView: UIView { + + // MARK: - Object Setting + + private let mainLabel = UILabel().then { + $0.text = "TVING ID ๋กœ๊ทธ์ธ" + $0.font = .tvingMedium(ofSize: 23) + $0.textColor = .tvingGray1 + $0.textAlignment = .center + } + + let idTextField = CustomTextField().then { + $0.placeholder = "์ด๋ฉ”์ผ" + $0.setPlaceholderColor(.tvingGray2) + $0.font = .tvingMedium(ofSize: 15) + $0.textColor = .tvingGray2 + $0.backgroundColor = .tvingGray4 + $0.keyboardType = .emailAddress + } + + let idInvalidLabel = UILabel().then { + $0.textColor = .systemRed + $0.font = .systemFont(ofSize: 12) + $0.text = "* ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์€ ์ด๋ฉ”์ผ ํ˜•์‹์ž…๋‹ˆ๋‹ค ๐Ÿ˜ญ" + $0.isHidden = true + } + + let passwordTextField = CustomPasswordTextField().then { + $0.placeholder = "๋น„๋ฐ€๋ฒˆํ˜ธ" + $0.setPlaceholderColor(.tvingGray2) + $0.font = .tvingMedium(ofSize: 15) + $0.textColor = .tvingGray2 + $0.backgroundColor = .tvingGray4 + $0.keyboardType = .asciiCapable + } + + lazy var logInBtn = UIButton().then { + $0.setTitle("๋กœ๊ทธ์ธํ•˜๊ธฐ", for: .normal) + $0.setTitleColor(.tvingGray2, for: .normal) + $0.titleLabel?.font = .tvingMedium(ofSize: 14) + $0.titleLabel?.textAlignment = .center + $0.layer.borderColor = UIColor.tvingGray4.cgColor + $0.layer.borderWidth = 1 + $0.layer.cornerRadius = 3 + $0.isEnabled = false + } + + private let idPasswordStackView = UIStackView().then { + $0.axis = .horizontal + $0.distribution = .fill + $0.alignment = .center + $0.spacing = 40 + } + + lazy var findIdBtn = UIButton().then { + $0.setTitle("์•„์ด๋”” ์ฐพ๊ธฐ", for: .normal) + $0.setTitleColor(.tvingGray2, for: .normal) + $0.titleLabel?.font = .tvingMedium(ofSize: 14) + $0.titleLabel?.textAlignment = .center + } + + lazy var findPasswordBtn = UIButton().then { + $0.setTitle("๋น„๋ฐ€๋ฒˆํ˜ธ ์ฐพ๊ธฐ", for: .normal) + $0.setTitleColor(.tvingGray2, for: .normal) + $0.titleLabel?.font = .tvingMedium(ofSize: 14) + $0.titleLabel?.textAlignment = .center + } + + private let makeAccountStackView = UIStackView().then { + $0.axis = .horizontal + $0.distribution = .fill + $0.alignment = .center + $0.spacing = 20 + } + + let askExistAccountLabel = UILabel().then { + $0.text = "์•„์ง ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”?" + $0.font = .tvingRegular(ofSize: 14) + $0.textColor = .tvingGray3 + $0.textAlignment = .center + } + + lazy var goToMakeNicknameBtn = UIButton().then { + $0.setTitle("๋‹‰๋„ค์ž„ ๋งŒ๋“ค๋Ÿฌ๊ฐ€๊ธฐ", for: .normal) + $0.setTitleColor(.tvingGray2, for: .normal) + $0.titleLabel?.font = .tvingRegular(ofSize: 14) + $0.titleLabel?.textAlignment = .center + $0.setUnderline() + } + + lazy var backBtn = UIButton().then { + $0.setImage(UIImage(named: "btn_before"), for: .normal) + } + + override init(frame: CGRect) { + super.init(frame: frame) + + style() + hierarchy() + setLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + +} + +private extension LoginView { + + func style() { + self.backgroundColor = .black + } + + func hierarchy() { + self.addSubviews(mainLabel, + idTextField, + idInvalidLabel, + passwordTextField, + logInBtn, + idPasswordStackView, + makeAccountStackView, + backBtn) + idPasswordStackView.addArrangedSubviews(findIdBtn, + findPasswordBtn) + makeAccountStackView.addArrangedSubviews(askExistAccountLabel, + goToMakeNicknameBtn) + } + + + func setLayout() { + + mainLabel.snp.makeConstraints{ + $0.height.equalTo(37) + $0.top.equalTo(self.safeAreaLayoutGuide).inset(50) + $0.leading.trailing.equalToSuperview().inset(100) + } + + idTextField.snp.makeConstraints{ + $0.height.equalTo(52) + $0.top.equalTo(mainLabel.snp.bottom).offset(31) + $0.leading.trailing.equalToSuperview().inset(20) + } + + passwordTextField.snp.makeConstraints{ + $0.height.equalTo(52) + $0.top.equalTo(idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + + logInBtn.snp.makeConstraints{ + $0.height.equalTo(52) + $0.top.equalTo(passwordTextField.snp.bottom).offset(21) + $0.leading.trailing.equalToSuperview().inset(20) + } + + idPasswordStackView.snp.makeConstraints { + $0.height.equalTo(25) + $0.top.equalTo(logInBtn.snp.bottom).offset(30) + $0.centerX.equalToSuperview().inset(80) + } + + makeAccountStackView.snp.makeConstraints { + $0.height.equalTo(25) + $0.top.equalTo(idPasswordStackView.snp.bottom).offset(30) + $0.centerX.equalToSuperview().inset(50) + } + + backBtn.snp.makeConstraints{ + $0.height.equalTo(15) + $0.width.equalTo(8) + $0.top.equalTo(self.safeAreaLayoutGuide).inset(25) + $0.leading.equalToSuperview().inset(24) + } + + findIdBtn.snp.makeConstraints{ + $0.width.equalTo(70) + $0.height.equalTo(22) + } + + findPasswordBtn.snp.makeConstraints{ + $0.width.equalTo(80) + $0.height.equalTo(22) + } + + askExistAccountLabel.snp.makeConstraints{ + $0.width.equalTo(140) + $0.height.equalTo(22) + } + + goToMakeNicknameBtn.snp.makeConstraints{ + $0.width.equalTo(128) + $0.height.equalTo(22) + } + } +}
Swift
๊ฐ๊ฐ ์ขŒ์šฐ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•˜๋ฉด ๊ธฐ๊ธฐ๋งˆ๋‹ค ์ฐจ์ด๊ฐ€ ์ข€ ๋‚˜ํƒ€๋‚  ๊ฑฐ ๊ฐ™์•„์š”! ๊ฐ€์šด๋ฐ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ฌถ์„ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•(stackview)๋„ ์ข‹์„ ๊ฑฐ๊ฐ™์•„์š” ใ…Žใ…Ž
@@ -0,0 +1,261 @@ +// +// LoginViewController_TVING.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/11. +// + +import UIKit + +import SnapKit +import Then + +struct TvingUserInfo { + var id: String? + var password: String? + var nickName: String? +} + +final class LoginViewController_TVING: BaseViewController { + + // MARK: - Property + + private let mainView = LoginView() + private let nickNameBottomSheet = AddNickNameBottomSheetUIView() + + var user = TvingUserInfo() + + private var bottomSheetKeyboardEnable: Bool = false + + // MARK: - Target + + private func target() { + mainView.idTextField.delegate = self + mainView.passwordTextField.delegate = self + + mainView.idTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + mainView.passwordTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + mainView.logInBtn.addTarget(self, action: #selector(tappedLogInBtn), for: .touchUpInside) + mainView.goToMakeNicknameBtn.addTarget(self, action: #selector(tappedMakeNickNameBtn), for: .touchUpInside) + } + + private func targetBottomSheet() { + nickNameBottomSheet.nickNameTextField.delegate = self + + nickNameBottomSheet.nickNameTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + nickNameBottomSheet.saveNickNameBtn.addTarget(self, action: #selector(tappedSavedNickNameBtn), for: .touchUpInside) + + let bottomSheetBackgroundTap = UITapGestureRecognizer(target: self, action: #selector(TappedBottomSheetBackground)) + nickNameBottomSheet.dimmendView.addGestureRecognizer(bottomSheetBackgroundTap) + } + + // MARK: - Lift Cycle + + override func loadView() { + self.view = mainView + view.addSubview(nickNameBottomSheet) + + nickNameBottomSheet.snp.makeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + target() + targetBottomSheet() + setKeyboardObserver() // ํ‚ค๋ณด๋“œ ํ™œ์„ฑํ™”์— ๋”ฐ๋ฅธ bottomSheet ๋†’์ด ์กฐ์ ˆ ์œ„ํ•ด + } + + override func viewWillAppear(_ animated: Bool) { + initView() + } + +} + +private extension LoginViewController_TVING { + + // MARK: - objc func + + @objc + func tappedLogInBtn() { + saveUserEmail() + let welcomViewController = WelcomeViewController() + welcomViewController.idDataBind(idOrNick: getNickNameOrId()) + self.navigationController?.pushViewController(welcomViewController, animated: true) + } + + @objc + func tappedMakeNickNameBtn() { + showBottomSheet() + } + + @objc + func tappedSavedNickNameBtn() { + saveUserNickName() + hideBottomSheet() + } + + @objc func TappedBottomSheetBackground(_ tapRecognizer: UITapGestureRecognizer) { + hideBottomSheet() + } + + @objc func keyboardWillShow(notification: NSNotification) { + guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return } + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - (nickNameBottomSheet.bottomSheetHeight + keyboardSize.height) + } + } + + @objc func keyboardWillHide(notification: NSNotification) { + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - nickNameBottomSheet.bottomSheetHeight + } + } + + // MARK: - custom func + + func saveUserEmail(){ + guard let id = mainView.idTextField.text else { return } + user.id = id + } + + func saveUserNickName() { + guard let nickName = nickNameBottomSheet.nickNameTextField.text else { return } + user.nickName = nickName + } + + func getNickNameOrId() -> String { + if let nickName = user.nickName { + return nickName + } else { + guard let id = user.id else { return "" } + return id + } + } + + func isIDValid() -> Bool { + guard let id = mainView.idTextField.text else { return false } + return id.isValidEmail() + } + + func showBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = true + nickNameBottomSheet.snp.remakeConstraints { + $0.edges.equalToSuperview() + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height) + }) + } + + func hideBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = false + nickNameBottomSheet.snp.remakeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: self.view.frame.height, width: self.view.frame.width, height: self.view.frame.height) + } + ) + } + + func initView() { + mainView.idTextField.text = nil + mainView.passwordTextField.text = nil + nickNameBottomSheet.nickNameTextField.text = nil + user = TvingUserInfo() + mainView.logInBtn.enableDisableButtonSet(isEnable: false, setColor: .black, setTextColor: .tvingGray2) + } + + func setKeyboardObserver() { + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + } + +} + +// MARK: - TextFieldDelegate + +extension LoginViewController_TVING: UITextFieldDelegate { + + // textField๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldDidBeginEditing(_ textField: UITextField) { + textField.layer.borderColor = UIColor.tvingGray2.cgColor + textField.layer.borderWidth = 0.7 + } + + // textField ๋น„ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { + textField.layer.borderWidth = 0 + + idValidPrint() + + return true + } + + @objc + private func textFieldDidChange(_ textField: UITextField) { + + if let nickNameText = nickNameBottomSheet.nickNameTextField.text { + if (!nickNameText.isValidNickName()) { + nickNameBottomSheet.nickNameTextField.text = nil + } + } + + let idPwIsFull: Bool = mainView.idTextField.hasText && !mainView.passwordTextField.hasText + let saveIdPwBtnEnable: Bool = idPwIsFull && isIDValid() + + if (saveIdPwBtnEnable) { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + + let saveNickNameBtnEnable = !nickNameBottomSheet.nickNameTextField.hasText + + if (saveNickNameBtnEnable) { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + } + + private func idValidPrint() { + + if (!(mainView.idTextField.text?.isValidEmail() ?? false) && !mainView.idTextField.hasText) { + mainView.idTextField.layer.borderColor = UIColor.tvingRed.cgColor + mainView.idTextField.layer.borderWidth = 0.7 + + mainView.idInvalidLabel.isHidden = false + mainView.idInvalidLabel.snp.remakeConstraints { + $0.leading.equalTo(mainView.idTextField.snp.leading) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(5) + } + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(30) + $0.leading.trailing.equalToSuperview().inset(20) + } + } else { + mainView.idTextField.layer.borderWidth = 0 + + mainView.idInvalidLabel.isHidden = true + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + } + } + +}
Swift
UIView๋ฅผ ๋”ฐ๋กœ ๋นผ๋‹ˆ๊นŒ ํ™• ์ฝ”๋“œ๊ฐ€ ์งง์•„์กŒ๋„ค์š” ์ €๋„ ๋‹ค์Œ์—” ์ด๋Ÿฐ์‹์œผ๋กœ ํ•ด๋ด์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ใ…Žใ…Ž
@@ -0,0 +1,261 @@ +// +// LoginViewController_TVING.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/11. +// + +import UIKit + +import SnapKit +import Then + +struct TvingUserInfo { + var id: String? + var password: String? + var nickName: String? +} + +final class LoginViewController_TVING: BaseViewController { + + // MARK: - Property + + private let mainView = LoginView() + private let nickNameBottomSheet = AddNickNameBottomSheetUIView() + + var user = TvingUserInfo() + + private var bottomSheetKeyboardEnable: Bool = false + + // MARK: - Target + + private func target() { + mainView.idTextField.delegate = self + mainView.passwordTextField.delegate = self + + mainView.idTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + mainView.passwordTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + mainView.logInBtn.addTarget(self, action: #selector(tappedLogInBtn), for: .touchUpInside) + mainView.goToMakeNicknameBtn.addTarget(self, action: #selector(tappedMakeNickNameBtn), for: .touchUpInside) + } + + private func targetBottomSheet() { + nickNameBottomSheet.nickNameTextField.delegate = self + + nickNameBottomSheet.nickNameTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + nickNameBottomSheet.saveNickNameBtn.addTarget(self, action: #selector(tappedSavedNickNameBtn), for: .touchUpInside) + + let bottomSheetBackgroundTap = UITapGestureRecognizer(target: self, action: #selector(TappedBottomSheetBackground)) + nickNameBottomSheet.dimmendView.addGestureRecognizer(bottomSheetBackgroundTap) + } + + // MARK: - Lift Cycle + + override func loadView() { + self.view = mainView + view.addSubview(nickNameBottomSheet) + + nickNameBottomSheet.snp.makeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + target() + targetBottomSheet() + setKeyboardObserver() // ํ‚ค๋ณด๋“œ ํ™œ์„ฑํ™”์— ๋”ฐ๋ฅธ bottomSheet ๋†’์ด ์กฐ์ ˆ ์œ„ํ•ด + } + + override func viewWillAppear(_ animated: Bool) { + initView() + } + +} + +private extension LoginViewController_TVING { + + // MARK: - objc func + + @objc + func tappedLogInBtn() { + saveUserEmail() + let welcomViewController = WelcomeViewController() + welcomViewController.idDataBind(idOrNick: getNickNameOrId()) + self.navigationController?.pushViewController(welcomViewController, animated: true) + } + + @objc + func tappedMakeNickNameBtn() { + showBottomSheet() + } + + @objc + func tappedSavedNickNameBtn() { + saveUserNickName() + hideBottomSheet() + } + + @objc func TappedBottomSheetBackground(_ tapRecognizer: UITapGestureRecognizer) { + hideBottomSheet() + } + + @objc func keyboardWillShow(notification: NSNotification) { + guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return } + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - (nickNameBottomSheet.bottomSheetHeight + keyboardSize.height) + } + } + + @objc func keyboardWillHide(notification: NSNotification) { + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - nickNameBottomSheet.bottomSheetHeight + } + } + + // MARK: - custom func + + func saveUserEmail(){ + guard let id = mainView.idTextField.text else { return } + user.id = id + } + + func saveUserNickName() { + guard let nickName = nickNameBottomSheet.nickNameTextField.text else { return } + user.nickName = nickName + } + + func getNickNameOrId() -> String { + if let nickName = user.nickName { + return nickName + } else { + guard let id = user.id else { return "" } + return id + } + } + + func isIDValid() -> Bool { + guard let id = mainView.idTextField.text else { return false } + return id.isValidEmail() + } + + func showBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = true + nickNameBottomSheet.snp.remakeConstraints { + $0.edges.equalToSuperview() + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height) + }) + } + + func hideBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = false + nickNameBottomSheet.snp.remakeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: self.view.frame.height, width: self.view.frame.width, height: self.view.frame.height) + } + ) + } + + func initView() { + mainView.idTextField.text = nil + mainView.passwordTextField.text = nil + nickNameBottomSheet.nickNameTextField.text = nil + user = TvingUserInfo() + mainView.logInBtn.enableDisableButtonSet(isEnable: false, setColor: .black, setTextColor: .tvingGray2) + } + + func setKeyboardObserver() { + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + } + +} + +// MARK: - TextFieldDelegate + +extension LoginViewController_TVING: UITextFieldDelegate { + + // textField๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldDidBeginEditing(_ textField: UITextField) { + textField.layer.borderColor = UIColor.tvingGray2.cgColor + textField.layer.borderWidth = 0.7 + } + + // textField ๋น„ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { + textField.layer.borderWidth = 0 + + idValidPrint() + + return true + } + + @objc + private func textFieldDidChange(_ textField: UITextField) { + + if let nickNameText = nickNameBottomSheet.nickNameTextField.text { + if (!nickNameText.isValidNickName()) { + nickNameBottomSheet.nickNameTextField.text = nil + } + } + + let idPwIsFull: Bool = mainView.idTextField.hasText && !mainView.passwordTextField.hasText + let saveIdPwBtnEnable: Bool = idPwIsFull && isIDValid() + + if (saveIdPwBtnEnable) { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + + let saveNickNameBtnEnable = !nickNameBottomSheet.nickNameTextField.hasText + + if (saveNickNameBtnEnable) { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + } + + private func idValidPrint() { + + if (!(mainView.idTextField.text?.isValidEmail() ?? false) && !mainView.idTextField.hasText) { + mainView.idTextField.layer.borderColor = UIColor.tvingRed.cgColor + mainView.idTextField.layer.borderWidth = 0.7 + + mainView.idInvalidLabel.isHidden = false + mainView.idInvalidLabel.snp.remakeConstraints { + $0.leading.equalTo(mainView.idTextField.snp.leading) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(5) + } + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(30) + $0.leading.trailing.equalToSuperview().inset(20) + } + } else { + mainView.idTextField.layer.borderWidth = 0 + + mainView.idInvalidLabel.isHidden = true + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + } + } + +}
Swift
targetํ•จ์ˆ˜ ๋”ฐ๋กœ ๋บ€ ๊ฑฐ ์งฑ์ด์—์—ฌ ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค
@@ -0,0 +1,261 @@ +// +// LoginViewController_TVING.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/11. +// + +import UIKit + +import SnapKit +import Then + +struct TvingUserInfo { + var id: String? + var password: String? + var nickName: String? +} + +final class LoginViewController_TVING: BaseViewController { + + // MARK: - Property + + private let mainView = LoginView() + private let nickNameBottomSheet = AddNickNameBottomSheetUIView() + + var user = TvingUserInfo() + + private var bottomSheetKeyboardEnable: Bool = false + + // MARK: - Target + + private func target() { + mainView.idTextField.delegate = self + mainView.passwordTextField.delegate = self + + mainView.idTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + mainView.passwordTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + mainView.logInBtn.addTarget(self, action: #selector(tappedLogInBtn), for: .touchUpInside) + mainView.goToMakeNicknameBtn.addTarget(self, action: #selector(tappedMakeNickNameBtn), for: .touchUpInside) + } + + private func targetBottomSheet() { + nickNameBottomSheet.nickNameTextField.delegate = self + + nickNameBottomSheet.nickNameTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + nickNameBottomSheet.saveNickNameBtn.addTarget(self, action: #selector(tappedSavedNickNameBtn), for: .touchUpInside) + + let bottomSheetBackgroundTap = UITapGestureRecognizer(target: self, action: #selector(TappedBottomSheetBackground)) + nickNameBottomSheet.dimmendView.addGestureRecognizer(bottomSheetBackgroundTap) + } + + // MARK: - Lift Cycle + + override func loadView() { + self.view = mainView + view.addSubview(nickNameBottomSheet) + + nickNameBottomSheet.snp.makeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + target() + targetBottomSheet() + setKeyboardObserver() // ํ‚ค๋ณด๋“œ ํ™œ์„ฑํ™”์— ๋”ฐ๋ฅธ bottomSheet ๋†’์ด ์กฐ์ ˆ ์œ„ํ•ด + } + + override func viewWillAppear(_ animated: Bool) { + initView() + } + +} + +private extension LoginViewController_TVING { + + // MARK: - objc func + + @objc + func tappedLogInBtn() { + saveUserEmail() + let welcomViewController = WelcomeViewController() + welcomViewController.idDataBind(idOrNick: getNickNameOrId()) + self.navigationController?.pushViewController(welcomViewController, animated: true) + } + + @objc + func tappedMakeNickNameBtn() { + showBottomSheet() + } + + @objc + func tappedSavedNickNameBtn() { + saveUserNickName() + hideBottomSheet() + } + + @objc func TappedBottomSheetBackground(_ tapRecognizer: UITapGestureRecognizer) { + hideBottomSheet() + } + + @objc func keyboardWillShow(notification: NSNotification) { + guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return } + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - (nickNameBottomSheet.bottomSheetHeight + keyboardSize.height) + } + } + + @objc func keyboardWillHide(notification: NSNotification) { + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - nickNameBottomSheet.bottomSheetHeight + } + } + + // MARK: - custom func + + func saveUserEmail(){ + guard let id = mainView.idTextField.text else { return } + user.id = id + } + + func saveUserNickName() { + guard let nickName = nickNameBottomSheet.nickNameTextField.text else { return } + user.nickName = nickName + } + + func getNickNameOrId() -> String { + if let nickName = user.nickName { + return nickName + } else { + guard let id = user.id else { return "" } + return id + } + } + + func isIDValid() -> Bool { + guard let id = mainView.idTextField.text else { return false } + return id.isValidEmail() + } + + func showBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = true + nickNameBottomSheet.snp.remakeConstraints { + $0.edges.equalToSuperview() + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height) + }) + } + + func hideBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = false + nickNameBottomSheet.snp.remakeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: self.view.frame.height, width: self.view.frame.width, height: self.view.frame.height) + } + ) + } + + func initView() { + mainView.idTextField.text = nil + mainView.passwordTextField.text = nil + nickNameBottomSheet.nickNameTextField.text = nil + user = TvingUserInfo() + mainView.logInBtn.enableDisableButtonSet(isEnable: false, setColor: .black, setTextColor: .tvingGray2) + } + + func setKeyboardObserver() { + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + } + +} + +// MARK: - TextFieldDelegate + +extension LoginViewController_TVING: UITextFieldDelegate { + + // textField๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldDidBeginEditing(_ textField: UITextField) { + textField.layer.borderColor = UIColor.tvingGray2.cgColor + textField.layer.borderWidth = 0.7 + } + + // textField ๋น„ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { + textField.layer.borderWidth = 0 + + idValidPrint() + + return true + } + + @objc + private func textFieldDidChange(_ textField: UITextField) { + + if let nickNameText = nickNameBottomSheet.nickNameTextField.text { + if (!nickNameText.isValidNickName()) { + nickNameBottomSheet.nickNameTextField.text = nil + } + } + + let idPwIsFull: Bool = mainView.idTextField.hasText && !mainView.passwordTextField.hasText + let saveIdPwBtnEnable: Bool = idPwIsFull && isIDValid() + + if (saveIdPwBtnEnable) { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + + let saveNickNameBtnEnable = !nickNameBottomSheet.nickNameTextField.hasText + + if (saveNickNameBtnEnable) { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + } + + private func idValidPrint() { + + if (!(mainView.idTextField.text?.isValidEmail() ?? false) && !mainView.idTextField.hasText) { + mainView.idTextField.layer.borderColor = UIColor.tvingRed.cgColor + mainView.idTextField.layer.borderWidth = 0.7 + + mainView.idInvalidLabel.isHidden = false + mainView.idInvalidLabel.snp.remakeConstraints { + $0.leading.equalTo(mainView.idTextField.snp.leading) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(5) + } + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(30) + $0.leading.trailing.equalToSuperview().inset(20) + } + } else { + mainView.idTextField.layer.borderWidth = 0 + + mainView.idInvalidLabel.isHidden = true + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + } + } + +}
Swift
์šฐ์™€ ํ‚ค๋ณด๋“œ ์ฒ˜๋ฆฌ๊นŒ์ง€ !! ์งฑ์ด๊ตฐ์—ฌ
@@ -0,0 +1,261 @@ +// +// LoginViewController_TVING.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/11. +// + +import UIKit + +import SnapKit +import Then + +struct TvingUserInfo { + var id: String? + var password: String? + var nickName: String? +} + +final class LoginViewController_TVING: BaseViewController { + + // MARK: - Property + + private let mainView = LoginView() + private let nickNameBottomSheet = AddNickNameBottomSheetUIView() + + var user = TvingUserInfo() + + private var bottomSheetKeyboardEnable: Bool = false + + // MARK: - Target + + private func target() { + mainView.idTextField.delegate = self + mainView.passwordTextField.delegate = self + + mainView.idTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + mainView.passwordTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + mainView.logInBtn.addTarget(self, action: #selector(tappedLogInBtn), for: .touchUpInside) + mainView.goToMakeNicknameBtn.addTarget(self, action: #selector(tappedMakeNickNameBtn), for: .touchUpInside) + } + + private func targetBottomSheet() { + nickNameBottomSheet.nickNameTextField.delegate = self + + nickNameBottomSheet.nickNameTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + nickNameBottomSheet.saveNickNameBtn.addTarget(self, action: #selector(tappedSavedNickNameBtn), for: .touchUpInside) + + let bottomSheetBackgroundTap = UITapGestureRecognizer(target: self, action: #selector(TappedBottomSheetBackground)) + nickNameBottomSheet.dimmendView.addGestureRecognizer(bottomSheetBackgroundTap) + } + + // MARK: - Lift Cycle + + override func loadView() { + self.view = mainView + view.addSubview(nickNameBottomSheet) + + nickNameBottomSheet.snp.makeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + target() + targetBottomSheet() + setKeyboardObserver() // ํ‚ค๋ณด๋“œ ํ™œ์„ฑํ™”์— ๋”ฐ๋ฅธ bottomSheet ๋†’์ด ์กฐ์ ˆ ์œ„ํ•ด + } + + override func viewWillAppear(_ animated: Bool) { + initView() + } + +} + +private extension LoginViewController_TVING { + + // MARK: - objc func + + @objc + func tappedLogInBtn() { + saveUserEmail() + let welcomViewController = WelcomeViewController() + welcomViewController.idDataBind(idOrNick: getNickNameOrId()) + self.navigationController?.pushViewController(welcomViewController, animated: true) + } + + @objc + func tappedMakeNickNameBtn() { + showBottomSheet() + } + + @objc + func tappedSavedNickNameBtn() { + saveUserNickName() + hideBottomSheet() + } + + @objc func TappedBottomSheetBackground(_ tapRecognizer: UITapGestureRecognizer) { + hideBottomSheet() + } + + @objc func keyboardWillShow(notification: NSNotification) { + guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return } + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - (nickNameBottomSheet.bottomSheetHeight + keyboardSize.height) + } + } + + @objc func keyboardWillHide(notification: NSNotification) { + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - nickNameBottomSheet.bottomSheetHeight + } + } + + // MARK: - custom func + + func saveUserEmail(){ + guard let id = mainView.idTextField.text else { return } + user.id = id + } + + func saveUserNickName() { + guard let nickName = nickNameBottomSheet.nickNameTextField.text else { return } + user.nickName = nickName + } + + func getNickNameOrId() -> String { + if let nickName = user.nickName { + return nickName + } else { + guard let id = user.id else { return "" } + return id + } + } + + func isIDValid() -> Bool { + guard let id = mainView.idTextField.text else { return false } + return id.isValidEmail() + } + + func showBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = true + nickNameBottomSheet.snp.remakeConstraints { + $0.edges.equalToSuperview() + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height) + }) + } + + func hideBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = false + nickNameBottomSheet.snp.remakeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: self.view.frame.height, width: self.view.frame.width, height: self.view.frame.height) + } + ) + } + + func initView() { + mainView.idTextField.text = nil + mainView.passwordTextField.text = nil + nickNameBottomSheet.nickNameTextField.text = nil + user = TvingUserInfo() + mainView.logInBtn.enableDisableButtonSet(isEnable: false, setColor: .black, setTextColor: .tvingGray2) + } + + func setKeyboardObserver() { + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + } + +} + +// MARK: - TextFieldDelegate + +extension LoginViewController_TVING: UITextFieldDelegate { + + // textField๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldDidBeginEditing(_ textField: UITextField) { + textField.layer.borderColor = UIColor.tvingGray2.cgColor + textField.layer.borderWidth = 0.7 + } + + // textField ๋น„ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { + textField.layer.borderWidth = 0 + + idValidPrint() + + return true + } + + @objc + private func textFieldDidChange(_ textField: UITextField) { + + if let nickNameText = nickNameBottomSheet.nickNameTextField.text { + if (!nickNameText.isValidNickName()) { + nickNameBottomSheet.nickNameTextField.text = nil + } + } + + let idPwIsFull: Bool = mainView.idTextField.hasText && !mainView.passwordTextField.hasText + let saveIdPwBtnEnable: Bool = idPwIsFull && isIDValid() + + if (saveIdPwBtnEnable) { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + + let saveNickNameBtnEnable = !nickNameBottomSheet.nickNameTextField.hasText + + if (saveNickNameBtnEnable) { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + } + + private func idValidPrint() { + + if (!(mainView.idTextField.text?.isValidEmail() ?? false) && !mainView.idTextField.hasText) { + mainView.idTextField.layer.borderColor = UIColor.tvingRed.cgColor + mainView.idTextField.layer.borderWidth = 0.7 + + mainView.idInvalidLabel.isHidden = false + mainView.idInvalidLabel.snp.remakeConstraints { + $0.leading.equalTo(mainView.idTextField.snp.leading) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(5) + } + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(30) + $0.leading.trailing.equalToSuperview().inset(20) + } + } else { + mainView.idTextField.layer.borderWidth = 0 + + mainView.idInvalidLabel.isHidden = true + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + } + } + +}
Swift
์™• ๊ตฌ์กฐ์ฒด๋กœ ๋ฌถ์–ด์ฃผ๋Š” ๊ฑฐ ๊นŒ์ง€!
@@ -0,0 +1,261 @@ +// +// LoginViewController_TVING.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/11. +// + +import UIKit + +import SnapKit +import Then + +struct TvingUserInfo { + var id: String? + var password: String? + var nickName: String? +} + +final class LoginViewController_TVING: BaseViewController { + + // MARK: - Property + + private let mainView = LoginView() + private let nickNameBottomSheet = AddNickNameBottomSheetUIView() + + var user = TvingUserInfo() + + private var bottomSheetKeyboardEnable: Bool = false + + // MARK: - Target + + private func target() { + mainView.idTextField.delegate = self + mainView.passwordTextField.delegate = self + + mainView.idTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + mainView.passwordTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + mainView.logInBtn.addTarget(self, action: #selector(tappedLogInBtn), for: .touchUpInside) + mainView.goToMakeNicknameBtn.addTarget(self, action: #selector(tappedMakeNickNameBtn), for: .touchUpInside) + } + + private func targetBottomSheet() { + nickNameBottomSheet.nickNameTextField.delegate = self + + nickNameBottomSheet.nickNameTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + nickNameBottomSheet.saveNickNameBtn.addTarget(self, action: #selector(tappedSavedNickNameBtn), for: .touchUpInside) + + let bottomSheetBackgroundTap = UITapGestureRecognizer(target: self, action: #selector(TappedBottomSheetBackground)) + nickNameBottomSheet.dimmendView.addGestureRecognizer(bottomSheetBackgroundTap) + } + + // MARK: - Lift Cycle + + override func loadView() { + self.view = mainView + view.addSubview(nickNameBottomSheet) + + nickNameBottomSheet.snp.makeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + target() + targetBottomSheet() + setKeyboardObserver() // ํ‚ค๋ณด๋“œ ํ™œ์„ฑํ™”์— ๋”ฐ๋ฅธ bottomSheet ๋†’์ด ์กฐ์ ˆ ์œ„ํ•ด + } + + override func viewWillAppear(_ animated: Bool) { + initView() + } + +} + +private extension LoginViewController_TVING { + + // MARK: - objc func + + @objc + func tappedLogInBtn() { + saveUserEmail() + let welcomViewController = WelcomeViewController() + welcomViewController.idDataBind(idOrNick: getNickNameOrId()) + self.navigationController?.pushViewController(welcomViewController, animated: true) + } + + @objc + func tappedMakeNickNameBtn() { + showBottomSheet() + } + + @objc + func tappedSavedNickNameBtn() { + saveUserNickName() + hideBottomSheet() + } + + @objc func TappedBottomSheetBackground(_ tapRecognizer: UITapGestureRecognizer) { + hideBottomSheet() + } + + @objc func keyboardWillShow(notification: NSNotification) { + guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return } + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - (nickNameBottomSheet.bottomSheetHeight + keyboardSize.height) + } + } + + @objc func keyboardWillHide(notification: NSNotification) { + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - nickNameBottomSheet.bottomSheetHeight + } + } + + // MARK: - custom func + + func saveUserEmail(){ + guard let id = mainView.idTextField.text else { return } + user.id = id + } + + func saveUserNickName() { + guard let nickName = nickNameBottomSheet.nickNameTextField.text else { return } + user.nickName = nickName + } + + func getNickNameOrId() -> String { + if let nickName = user.nickName { + return nickName + } else { + guard let id = user.id else { return "" } + return id + } + } + + func isIDValid() -> Bool { + guard let id = mainView.idTextField.text else { return false } + return id.isValidEmail() + } + + func showBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = true + nickNameBottomSheet.snp.remakeConstraints { + $0.edges.equalToSuperview() + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height) + }) + } + + func hideBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = false + nickNameBottomSheet.snp.remakeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: self.view.frame.height, width: self.view.frame.width, height: self.view.frame.height) + } + ) + } + + func initView() { + mainView.idTextField.text = nil + mainView.passwordTextField.text = nil + nickNameBottomSheet.nickNameTextField.text = nil + user = TvingUserInfo() + mainView.logInBtn.enableDisableButtonSet(isEnable: false, setColor: .black, setTextColor: .tvingGray2) + } + + func setKeyboardObserver() { + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + } + +} + +// MARK: - TextFieldDelegate + +extension LoginViewController_TVING: UITextFieldDelegate { + + // textField๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldDidBeginEditing(_ textField: UITextField) { + textField.layer.borderColor = UIColor.tvingGray2.cgColor + textField.layer.borderWidth = 0.7 + } + + // textField ๋น„ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { + textField.layer.borderWidth = 0 + + idValidPrint() + + return true + } + + @objc + private func textFieldDidChange(_ textField: UITextField) { + + if let nickNameText = nickNameBottomSheet.nickNameTextField.text { + if (!nickNameText.isValidNickName()) { + nickNameBottomSheet.nickNameTextField.text = nil + } + } + + let idPwIsFull: Bool = mainView.idTextField.hasText && !mainView.passwordTextField.hasText + let saveIdPwBtnEnable: Bool = idPwIsFull && isIDValid() + + if (saveIdPwBtnEnable) { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + + let saveNickNameBtnEnable = !nickNameBottomSheet.nickNameTextField.hasText + + if (saveNickNameBtnEnable) { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + } + + private func idValidPrint() { + + if (!(mainView.idTextField.text?.isValidEmail() ?? false) && !mainView.idTextField.hasText) { + mainView.idTextField.layer.borderColor = UIColor.tvingRed.cgColor + mainView.idTextField.layer.borderWidth = 0.7 + + mainView.idInvalidLabel.isHidden = false + mainView.idInvalidLabel.snp.remakeConstraints { + $0.leading.equalTo(mainView.idTextField.snp.leading) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(5) + } + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(30) + $0.leading.trailing.equalToSuperview().inset(20) + } + } else { + mainView.idTextField.layer.borderWidth = 0 + + mainView.idInvalidLabel.isHidden = true + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + } + } + +}
Swift
๊ตฌ์กฐ์ฒด์—์„œ ๋ณ€์ˆ˜๋“ค์„ ""๋กœ ์ดˆ๊ธฐํ™”ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์˜ต์…”๋„ ์ฒ˜๋ฆฌํ•ด๋‘๋Š”๊ฒŒ ์–ด๋–จ๊นŒ์š”? ๋‚˜์ค‘์— ๊ตฌ์กฐ์ฒด ๋ณ€์ˆ˜์— ๊ฐ’์„ ๋„ฃ๋‹ค๋ณด๋ฉด, ๋ณ€์ˆ˜๊ฐ€ ์‹ค์ œ๋กœ ๊ฐ’์ด ์—†๋Š” ์ƒํƒœ์ธ์ง€ ์•„๋‹ˆ๋ฉด ์˜๋„์ ์œผ๋กœ ๋นˆ ๊ฐ’์œผ๋กœ ์ดˆ๊ธฐํ™”๋œ ๊ฒƒ์ธ์ง€๋ฅผ ๊ตฌ๋ถ„ํ•˜๊ธฐ ์–ด๋ ต๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ ์ €๋Š” ?(์˜ต์…”๋„)์„ ์‚ฌ์šฉํ•ด๋ณด๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์•„์š”! `var id: String?` ์ด๋Ÿฐ ์‹์œผ๋กœ์š”
@@ -0,0 +1,261 @@ +// +// LoginViewController_TVING.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/11. +// + +import UIKit + +import SnapKit +import Then + +struct TvingUserInfo { + var id: String? + var password: String? + var nickName: String? +} + +final class LoginViewController_TVING: BaseViewController { + + // MARK: - Property + + private let mainView = LoginView() + private let nickNameBottomSheet = AddNickNameBottomSheetUIView() + + var user = TvingUserInfo() + + private var bottomSheetKeyboardEnable: Bool = false + + // MARK: - Target + + private func target() { + mainView.idTextField.delegate = self + mainView.passwordTextField.delegate = self + + mainView.idTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + mainView.passwordTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + mainView.logInBtn.addTarget(self, action: #selector(tappedLogInBtn), for: .touchUpInside) + mainView.goToMakeNicknameBtn.addTarget(self, action: #selector(tappedMakeNickNameBtn), for: .touchUpInside) + } + + private func targetBottomSheet() { + nickNameBottomSheet.nickNameTextField.delegate = self + + nickNameBottomSheet.nickNameTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + nickNameBottomSheet.saveNickNameBtn.addTarget(self, action: #selector(tappedSavedNickNameBtn), for: .touchUpInside) + + let bottomSheetBackgroundTap = UITapGestureRecognizer(target: self, action: #selector(TappedBottomSheetBackground)) + nickNameBottomSheet.dimmendView.addGestureRecognizer(bottomSheetBackgroundTap) + } + + // MARK: - Lift Cycle + + override func loadView() { + self.view = mainView + view.addSubview(nickNameBottomSheet) + + nickNameBottomSheet.snp.makeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + target() + targetBottomSheet() + setKeyboardObserver() // ํ‚ค๋ณด๋“œ ํ™œ์„ฑํ™”์— ๋”ฐ๋ฅธ bottomSheet ๋†’์ด ์กฐ์ ˆ ์œ„ํ•ด + } + + override func viewWillAppear(_ animated: Bool) { + initView() + } + +} + +private extension LoginViewController_TVING { + + // MARK: - objc func + + @objc + func tappedLogInBtn() { + saveUserEmail() + let welcomViewController = WelcomeViewController() + welcomViewController.idDataBind(idOrNick: getNickNameOrId()) + self.navigationController?.pushViewController(welcomViewController, animated: true) + } + + @objc + func tappedMakeNickNameBtn() { + showBottomSheet() + } + + @objc + func tappedSavedNickNameBtn() { + saveUserNickName() + hideBottomSheet() + } + + @objc func TappedBottomSheetBackground(_ tapRecognizer: UITapGestureRecognizer) { + hideBottomSheet() + } + + @objc func keyboardWillShow(notification: NSNotification) { + guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return } + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - (nickNameBottomSheet.bottomSheetHeight + keyboardSize.height) + } + } + + @objc func keyboardWillHide(notification: NSNotification) { + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - nickNameBottomSheet.bottomSheetHeight + } + } + + // MARK: - custom func + + func saveUserEmail(){ + guard let id = mainView.idTextField.text else { return } + user.id = id + } + + func saveUserNickName() { + guard let nickName = nickNameBottomSheet.nickNameTextField.text else { return } + user.nickName = nickName + } + + func getNickNameOrId() -> String { + if let nickName = user.nickName { + return nickName + } else { + guard let id = user.id else { return "" } + return id + } + } + + func isIDValid() -> Bool { + guard let id = mainView.idTextField.text else { return false } + return id.isValidEmail() + } + + func showBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = true + nickNameBottomSheet.snp.remakeConstraints { + $0.edges.equalToSuperview() + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height) + }) + } + + func hideBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = false + nickNameBottomSheet.snp.remakeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: self.view.frame.height, width: self.view.frame.width, height: self.view.frame.height) + } + ) + } + + func initView() { + mainView.idTextField.text = nil + mainView.passwordTextField.text = nil + nickNameBottomSheet.nickNameTextField.text = nil + user = TvingUserInfo() + mainView.logInBtn.enableDisableButtonSet(isEnable: false, setColor: .black, setTextColor: .tvingGray2) + } + + func setKeyboardObserver() { + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + } + +} + +// MARK: - TextFieldDelegate + +extension LoginViewController_TVING: UITextFieldDelegate { + + // textField๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldDidBeginEditing(_ textField: UITextField) { + textField.layer.borderColor = UIColor.tvingGray2.cgColor + textField.layer.borderWidth = 0.7 + } + + // textField ๋น„ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { + textField.layer.borderWidth = 0 + + idValidPrint() + + return true + } + + @objc + private func textFieldDidChange(_ textField: UITextField) { + + if let nickNameText = nickNameBottomSheet.nickNameTextField.text { + if (!nickNameText.isValidNickName()) { + nickNameBottomSheet.nickNameTextField.text = nil + } + } + + let idPwIsFull: Bool = mainView.idTextField.hasText && !mainView.passwordTextField.hasText + let saveIdPwBtnEnable: Bool = idPwIsFull && isIDValid() + + if (saveIdPwBtnEnable) { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + + let saveNickNameBtnEnable = !nickNameBottomSheet.nickNameTextField.hasText + + if (saveNickNameBtnEnable) { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + } + + private func idValidPrint() { + + if (!(mainView.idTextField.text?.isValidEmail() ?? false) && !mainView.idTextField.hasText) { + mainView.idTextField.layer.borderColor = UIColor.tvingRed.cgColor + mainView.idTextField.layer.borderWidth = 0.7 + + mainView.idInvalidLabel.isHidden = false + mainView.idInvalidLabel.snp.remakeConstraints { + $0.leading.equalTo(mainView.idTextField.snp.leading) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(5) + } + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(30) + $0.leading.trailing.equalToSuperview().inset(20) + } + } else { + mainView.idTextField.layer.borderWidth = 0 + + mainView.idInvalidLabel.isHidden = true + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + } + } + +}
Swift
์Šค์œ„ํ”„ํŠธ์—์„œ ์ ‘๊ทผ ์ œ์–ด์ž๋ฅผ ๋”ฐ๋กœ ์„ ์–ธํ•˜์ง€ ์•Š์œผ๋ฉด internal ์ ‘๊ทผ์ด ๊ธฐ๋ณธ์ด๋ผ๊ณ  ํ•ด์š”! open-> public -> internal -> file-private -> private ์œผ๋กœ ๊ฐˆ ์ˆ˜๋ก ์ œํ•œ์ ์ธ ์ ‘๊ทผ์ž์ธ๋ฐ ์„œ๋กœ ๋‹ค๋ฅธ ๋ชจ๋“ˆ๋ผ๋ฆฌ ์ ‘๊ทผํ•˜๋Š” ์ƒํ™ฉ์ด ์•„๋‹ˆ๋ผ๋ฉด ๊ตณ์ด public์„ ์„ ์–ธํ•˜์—ฌ ์ ‘๊ทผ ์ˆ˜์ค€์„ ์•ฝํ•˜๊ฒŒ ํ•  ํ•„์š” ์—†๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋Š”๋ฐ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์„ธ์šฉ? https://zeddios.tistory.com/383
@@ -0,0 +1,261 @@ +// +// LoginViewController_TVING.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/11. +// + +import UIKit + +import SnapKit +import Then + +struct TvingUserInfo { + var id: String? + var password: String? + var nickName: String? +} + +final class LoginViewController_TVING: BaseViewController { + + // MARK: - Property + + private let mainView = LoginView() + private let nickNameBottomSheet = AddNickNameBottomSheetUIView() + + var user = TvingUserInfo() + + private var bottomSheetKeyboardEnable: Bool = false + + // MARK: - Target + + private func target() { + mainView.idTextField.delegate = self + mainView.passwordTextField.delegate = self + + mainView.idTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + mainView.passwordTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + mainView.logInBtn.addTarget(self, action: #selector(tappedLogInBtn), for: .touchUpInside) + mainView.goToMakeNicknameBtn.addTarget(self, action: #selector(tappedMakeNickNameBtn), for: .touchUpInside) + } + + private func targetBottomSheet() { + nickNameBottomSheet.nickNameTextField.delegate = self + + nickNameBottomSheet.nickNameTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + nickNameBottomSheet.saveNickNameBtn.addTarget(self, action: #selector(tappedSavedNickNameBtn), for: .touchUpInside) + + let bottomSheetBackgroundTap = UITapGestureRecognizer(target: self, action: #selector(TappedBottomSheetBackground)) + nickNameBottomSheet.dimmendView.addGestureRecognizer(bottomSheetBackgroundTap) + } + + // MARK: - Lift Cycle + + override func loadView() { + self.view = mainView + view.addSubview(nickNameBottomSheet) + + nickNameBottomSheet.snp.makeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + target() + targetBottomSheet() + setKeyboardObserver() // ํ‚ค๋ณด๋“œ ํ™œ์„ฑํ™”์— ๋”ฐ๋ฅธ bottomSheet ๋†’์ด ์กฐ์ ˆ ์œ„ํ•ด + } + + override func viewWillAppear(_ animated: Bool) { + initView() + } + +} + +private extension LoginViewController_TVING { + + // MARK: - objc func + + @objc + func tappedLogInBtn() { + saveUserEmail() + let welcomViewController = WelcomeViewController() + welcomViewController.idDataBind(idOrNick: getNickNameOrId()) + self.navigationController?.pushViewController(welcomViewController, animated: true) + } + + @objc + func tappedMakeNickNameBtn() { + showBottomSheet() + } + + @objc + func tappedSavedNickNameBtn() { + saveUserNickName() + hideBottomSheet() + } + + @objc func TappedBottomSheetBackground(_ tapRecognizer: UITapGestureRecognizer) { + hideBottomSheet() + } + + @objc func keyboardWillShow(notification: NSNotification) { + guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return } + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - (nickNameBottomSheet.bottomSheetHeight + keyboardSize.height) + } + } + + @objc func keyboardWillHide(notification: NSNotification) { + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - nickNameBottomSheet.bottomSheetHeight + } + } + + // MARK: - custom func + + func saveUserEmail(){ + guard let id = mainView.idTextField.text else { return } + user.id = id + } + + func saveUserNickName() { + guard let nickName = nickNameBottomSheet.nickNameTextField.text else { return } + user.nickName = nickName + } + + func getNickNameOrId() -> String { + if let nickName = user.nickName { + return nickName + } else { + guard let id = user.id else { return "" } + return id + } + } + + func isIDValid() -> Bool { + guard let id = mainView.idTextField.text else { return false } + return id.isValidEmail() + } + + func showBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = true + nickNameBottomSheet.snp.remakeConstraints { + $0.edges.equalToSuperview() + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height) + }) + } + + func hideBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = false + nickNameBottomSheet.snp.remakeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: self.view.frame.height, width: self.view.frame.width, height: self.view.frame.height) + } + ) + } + + func initView() { + mainView.idTextField.text = nil + mainView.passwordTextField.text = nil + nickNameBottomSheet.nickNameTextField.text = nil + user = TvingUserInfo() + mainView.logInBtn.enableDisableButtonSet(isEnable: false, setColor: .black, setTextColor: .tvingGray2) + } + + func setKeyboardObserver() { + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + } + +} + +// MARK: - TextFieldDelegate + +extension LoginViewController_TVING: UITextFieldDelegate { + + // textField๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldDidBeginEditing(_ textField: UITextField) { + textField.layer.borderColor = UIColor.tvingGray2.cgColor + textField.layer.borderWidth = 0.7 + } + + // textField ๋น„ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { + textField.layer.borderWidth = 0 + + idValidPrint() + + return true + } + + @objc + private func textFieldDidChange(_ textField: UITextField) { + + if let nickNameText = nickNameBottomSheet.nickNameTextField.text { + if (!nickNameText.isValidNickName()) { + nickNameBottomSheet.nickNameTextField.text = nil + } + } + + let idPwIsFull: Bool = mainView.idTextField.hasText && !mainView.passwordTextField.hasText + let saveIdPwBtnEnable: Bool = idPwIsFull && isIDValid() + + if (saveIdPwBtnEnable) { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + + let saveNickNameBtnEnable = !nickNameBottomSheet.nickNameTextField.hasText + + if (saveNickNameBtnEnable) { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + } + + private func idValidPrint() { + + if (!(mainView.idTextField.text?.isValidEmail() ?? false) && !mainView.idTextField.hasText) { + mainView.idTextField.layer.borderColor = UIColor.tvingRed.cgColor + mainView.idTextField.layer.borderWidth = 0.7 + + mainView.idInvalidLabel.isHidden = false + mainView.idInvalidLabel.snp.remakeConstraints { + $0.leading.equalTo(mainView.idTextField.snp.leading) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(5) + } + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(30) + $0.leading.trailing.equalToSuperview().inset(20) + } + } else { + mainView.idTextField.layer.borderWidth = 0 + + mainView.idInvalidLabel.isHidden = true + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + } + } + +}
Swift
public์ด ์„œ๋กœ ๋‹ค๋ฅธ ๋ชจ๋“ˆ์—์„œ๋„ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋กํ•˜๋Š” ์ ‘๊ทผ ์ œ์–ด๋ผ๊ณ  ํ•˜๋„ค์š”. ๋ชจ๋“ˆ์ด ์ƒ์†Œํ•ด์„œ ์ฐพ์•„๋ณด๋‹ˆ "Xcode์˜ ๊ฐ ๋นŒ๋“œ ๋Œ€์ƒ"์„ ๋ชจ๋“ˆ์ด๋ผ๊ณ  ํ•˜๋”๋ผ๊ณ ์š”. ํ”„๋กœ์ ํŠธ ํŒŒ์ผ์ด๋ผ๊ณ  ์ €๋Š” ์ดํ•ดํ–ˆ์–ด์š”!
@@ -0,0 +1,261 @@ +// +// LoginViewController_TVING.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/11. +// + +import UIKit + +import SnapKit +import Then + +struct TvingUserInfo { + var id: String? + var password: String? + var nickName: String? +} + +final class LoginViewController_TVING: BaseViewController { + + // MARK: - Property + + private let mainView = LoginView() + private let nickNameBottomSheet = AddNickNameBottomSheetUIView() + + var user = TvingUserInfo() + + private var bottomSheetKeyboardEnable: Bool = false + + // MARK: - Target + + private func target() { + mainView.idTextField.delegate = self + mainView.passwordTextField.delegate = self + + mainView.idTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + mainView.passwordTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + mainView.logInBtn.addTarget(self, action: #selector(tappedLogInBtn), for: .touchUpInside) + mainView.goToMakeNicknameBtn.addTarget(self, action: #selector(tappedMakeNickNameBtn), for: .touchUpInside) + } + + private func targetBottomSheet() { + nickNameBottomSheet.nickNameTextField.delegate = self + + nickNameBottomSheet.nickNameTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + nickNameBottomSheet.saveNickNameBtn.addTarget(self, action: #selector(tappedSavedNickNameBtn), for: .touchUpInside) + + let bottomSheetBackgroundTap = UITapGestureRecognizer(target: self, action: #selector(TappedBottomSheetBackground)) + nickNameBottomSheet.dimmendView.addGestureRecognizer(bottomSheetBackgroundTap) + } + + // MARK: - Lift Cycle + + override func loadView() { + self.view = mainView + view.addSubview(nickNameBottomSheet) + + nickNameBottomSheet.snp.makeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + target() + targetBottomSheet() + setKeyboardObserver() // ํ‚ค๋ณด๋“œ ํ™œ์„ฑํ™”์— ๋”ฐ๋ฅธ bottomSheet ๋†’์ด ์กฐ์ ˆ ์œ„ํ•ด + } + + override func viewWillAppear(_ animated: Bool) { + initView() + } + +} + +private extension LoginViewController_TVING { + + // MARK: - objc func + + @objc + func tappedLogInBtn() { + saveUserEmail() + let welcomViewController = WelcomeViewController() + welcomViewController.idDataBind(idOrNick: getNickNameOrId()) + self.navigationController?.pushViewController(welcomViewController, animated: true) + } + + @objc + func tappedMakeNickNameBtn() { + showBottomSheet() + } + + @objc + func tappedSavedNickNameBtn() { + saveUserNickName() + hideBottomSheet() + } + + @objc func TappedBottomSheetBackground(_ tapRecognizer: UITapGestureRecognizer) { + hideBottomSheet() + } + + @objc func keyboardWillShow(notification: NSNotification) { + guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return } + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - (nickNameBottomSheet.bottomSheetHeight + keyboardSize.height) + } + } + + @objc func keyboardWillHide(notification: NSNotification) { + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - nickNameBottomSheet.bottomSheetHeight + } + } + + // MARK: - custom func + + func saveUserEmail(){ + guard let id = mainView.idTextField.text else { return } + user.id = id + } + + func saveUserNickName() { + guard let nickName = nickNameBottomSheet.nickNameTextField.text else { return } + user.nickName = nickName + } + + func getNickNameOrId() -> String { + if let nickName = user.nickName { + return nickName + } else { + guard let id = user.id else { return "" } + return id + } + } + + func isIDValid() -> Bool { + guard let id = mainView.idTextField.text else { return false } + return id.isValidEmail() + } + + func showBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = true + nickNameBottomSheet.snp.remakeConstraints { + $0.edges.equalToSuperview() + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height) + }) + } + + func hideBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = false + nickNameBottomSheet.snp.remakeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: self.view.frame.height, width: self.view.frame.width, height: self.view.frame.height) + } + ) + } + + func initView() { + mainView.idTextField.text = nil + mainView.passwordTextField.text = nil + nickNameBottomSheet.nickNameTextField.text = nil + user = TvingUserInfo() + mainView.logInBtn.enableDisableButtonSet(isEnable: false, setColor: .black, setTextColor: .tvingGray2) + } + + func setKeyboardObserver() { + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + } + +} + +// MARK: - TextFieldDelegate + +extension LoginViewController_TVING: UITextFieldDelegate { + + // textField๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldDidBeginEditing(_ textField: UITextField) { + textField.layer.borderColor = UIColor.tvingGray2.cgColor + textField.layer.borderWidth = 0.7 + } + + // textField ๋น„ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { + textField.layer.borderWidth = 0 + + idValidPrint() + + return true + } + + @objc + private func textFieldDidChange(_ textField: UITextField) { + + if let nickNameText = nickNameBottomSheet.nickNameTextField.text { + if (!nickNameText.isValidNickName()) { + nickNameBottomSheet.nickNameTextField.text = nil + } + } + + let idPwIsFull: Bool = mainView.idTextField.hasText && !mainView.passwordTextField.hasText + let saveIdPwBtnEnable: Bool = idPwIsFull && isIDValid() + + if (saveIdPwBtnEnable) { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + + let saveNickNameBtnEnable = !nickNameBottomSheet.nickNameTextField.hasText + + if (saveNickNameBtnEnable) { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + } + + private func idValidPrint() { + + if (!(mainView.idTextField.text?.isValidEmail() ?? false) && !mainView.idTextField.hasText) { + mainView.idTextField.layer.borderColor = UIColor.tvingRed.cgColor + mainView.idTextField.layer.borderWidth = 0.7 + + mainView.idInvalidLabel.isHidden = false + mainView.idInvalidLabel.snp.remakeConstraints { + $0.leading.equalTo(mainView.idTextField.snp.leading) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(5) + } + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(30) + $0.leading.trailing.equalToSuperview().inset(20) + } + } else { + mainView.idTextField.layer.borderWidth = 0 + + mainView.idInvalidLabel.isHidden = true + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + } + } + +}
Swift
?? ๋ฐฉ์‹์œผ๋กœ ์˜ต์…”๋„ ์–ธ๋žฉํ•‘ํ•˜๋Š”๊ฒƒ๋„ ์ข‹์ง€๋งŒ! ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด if let ์ด๋‚˜ guard let์„ ์“ฐ๋ฉด ๋” ์ข‹์„๊ฒƒ ๊ฐ™์•„์š”~
@@ -0,0 +1,205 @@ +// +// LoginView.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/16. +// + +import UIKit + +class LoginView: UIView { + + // MARK: - Object Setting + + private let mainLabel = UILabel().then { + $0.text = "TVING ID ๋กœ๊ทธ์ธ" + $0.font = .tvingMedium(ofSize: 23) + $0.textColor = .tvingGray1 + $0.textAlignment = .center + } + + let idTextField = CustomTextField().then { + $0.placeholder = "์ด๋ฉ”์ผ" + $0.setPlaceholderColor(.tvingGray2) + $0.font = .tvingMedium(ofSize: 15) + $0.textColor = .tvingGray2 + $0.backgroundColor = .tvingGray4 + $0.keyboardType = .emailAddress + } + + let idInvalidLabel = UILabel().then { + $0.textColor = .systemRed + $0.font = .systemFont(ofSize: 12) + $0.text = "* ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์€ ์ด๋ฉ”์ผ ํ˜•์‹์ž…๋‹ˆ๋‹ค ๐Ÿ˜ญ" + $0.isHidden = true + } + + let passwordTextField = CustomPasswordTextField().then { + $0.placeholder = "๋น„๋ฐ€๋ฒˆํ˜ธ" + $0.setPlaceholderColor(.tvingGray2) + $0.font = .tvingMedium(ofSize: 15) + $0.textColor = .tvingGray2 + $0.backgroundColor = .tvingGray4 + $0.keyboardType = .asciiCapable + } + + lazy var logInBtn = UIButton().then { + $0.setTitle("๋กœ๊ทธ์ธํ•˜๊ธฐ", for: .normal) + $0.setTitleColor(.tvingGray2, for: .normal) + $0.titleLabel?.font = .tvingMedium(ofSize: 14) + $0.titleLabel?.textAlignment = .center + $0.layer.borderColor = UIColor.tvingGray4.cgColor + $0.layer.borderWidth = 1 + $0.layer.cornerRadius = 3 + $0.isEnabled = false + } + + private let idPasswordStackView = UIStackView().then { + $0.axis = .horizontal + $0.distribution = .fill + $0.alignment = .center + $0.spacing = 40 + } + + lazy var findIdBtn = UIButton().then { + $0.setTitle("์•„์ด๋”” ์ฐพ๊ธฐ", for: .normal) + $0.setTitleColor(.tvingGray2, for: .normal) + $0.titleLabel?.font = .tvingMedium(ofSize: 14) + $0.titleLabel?.textAlignment = .center + } + + lazy var findPasswordBtn = UIButton().then { + $0.setTitle("๋น„๋ฐ€๋ฒˆํ˜ธ ์ฐพ๊ธฐ", for: .normal) + $0.setTitleColor(.tvingGray2, for: .normal) + $0.titleLabel?.font = .tvingMedium(ofSize: 14) + $0.titleLabel?.textAlignment = .center + } + + private let makeAccountStackView = UIStackView().then { + $0.axis = .horizontal + $0.distribution = .fill + $0.alignment = .center + $0.spacing = 20 + } + + let askExistAccountLabel = UILabel().then { + $0.text = "์•„์ง ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”?" + $0.font = .tvingRegular(ofSize: 14) + $0.textColor = .tvingGray3 + $0.textAlignment = .center + } + + lazy var goToMakeNicknameBtn = UIButton().then { + $0.setTitle("๋‹‰๋„ค์ž„ ๋งŒ๋“ค๋Ÿฌ๊ฐ€๊ธฐ", for: .normal) + $0.setTitleColor(.tvingGray2, for: .normal) + $0.titleLabel?.font = .tvingRegular(ofSize: 14) + $0.titleLabel?.textAlignment = .center + $0.setUnderline() + } + + lazy var backBtn = UIButton().then { + $0.setImage(UIImage(named: "btn_before"), for: .normal) + } + + override init(frame: CGRect) { + super.init(frame: frame) + + style() + hierarchy() + setLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + +} + +private extension LoginView { + + func style() { + self.backgroundColor = .black + } + + func hierarchy() { + self.addSubviews(mainLabel, + idTextField, + idInvalidLabel, + passwordTextField, + logInBtn, + idPasswordStackView, + makeAccountStackView, + backBtn) + idPasswordStackView.addArrangedSubviews(findIdBtn, + findPasswordBtn) + makeAccountStackView.addArrangedSubviews(askExistAccountLabel, + goToMakeNicknameBtn) + } + + + func setLayout() { + + mainLabel.snp.makeConstraints{ + $0.height.equalTo(37) + $0.top.equalTo(self.safeAreaLayoutGuide).inset(50) + $0.leading.trailing.equalToSuperview().inset(100) + } + + idTextField.snp.makeConstraints{ + $0.height.equalTo(52) + $0.top.equalTo(mainLabel.snp.bottom).offset(31) + $0.leading.trailing.equalToSuperview().inset(20) + } + + passwordTextField.snp.makeConstraints{ + $0.height.equalTo(52) + $0.top.equalTo(idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + + logInBtn.snp.makeConstraints{ + $0.height.equalTo(52) + $0.top.equalTo(passwordTextField.snp.bottom).offset(21) + $0.leading.trailing.equalToSuperview().inset(20) + } + + idPasswordStackView.snp.makeConstraints { + $0.height.equalTo(25) + $0.top.equalTo(logInBtn.snp.bottom).offset(30) + $0.centerX.equalToSuperview().inset(80) + } + + makeAccountStackView.snp.makeConstraints { + $0.height.equalTo(25) + $0.top.equalTo(idPasswordStackView.snp.bottom).offset(30) + $0.centerX.equalToSuperview().inset(50) + } + + backBtn.snp.makeConstraints{ + $0.height.equalTo(15) + $0.width.equalTo(8) + $0.top.equalTo(self.safeAreaLayoutGuide).inset(25) + $0.leading.equalToSuperview().inset(24) + } + + findIdBtn.snp.makeConstraints{ + $0.width.equalTo(70) + $0.height.equalTo(22) + } + + findPasswordBtn.snp.makeConstraints{ + $0.width.equalTo(80) + $0.height.equalTo(22) + } + + askExistAccountLabel.snp.makeConstraints{ + $0.width.equalTo(140) + $0.height.equalTo(22) + } + + goToMakeNicknameBtn.snp.makeConstraints{ + $0.width.equalTo(128) + $0.height.equalTo(22) + } + } +}
Swift
๋ฒ„ํŠผ ์ปดํฌ๋„ŒํŠธ๋“ค์—๋งŒ lazy๋ฅผ ๋„ฃ์–ด์ฃผ์…จ๋Š”๋ฐ addTarget์—์„œ (๋…ธ๋ž€์ƒ‰)์›Œ๋‹์„ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด์„œ ๋„ฃ์€๊ฑฐ์ฃ ..? ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ ๋ฐฉ์‹์ค‘์— addTarget ๋ฐฉ์‹ ์™ธ์—๋„ addAction ๋ฐฉ์‹๋„ ์žˆ์–ด์š”! addAction ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ ํ•จ์ˆ˜์— @objc๋„ ๋ถ™์ด์ง€ ์•Š์•„๋„ ๋˜๊ณ , ์›Œ๋‹์„ ํ”ผํ•˜๊ธฐ ์œ„ํ•œ lazy๋„ ์•ˆ์จ๋„ ๋ฉ๋‹ˆ๋‹ค! ๊ฐ€๋…์„ฑ ์ธก๋ฉด์ด๋ž‘, ์ตœ๋Œ€ํ•œ objc ์š”์†Œ๋ฅผ ์ œ์™ธํ•˜๊ณ  UIKit ํ†ต์ผ์„ฑ์„ ์œ„ํ•ด addAction ๋ฐฉ์‹๋„ ์•Œ๊ณ  ์žˆ์œผ๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์•„์š”! ์•„๋ž˜๋Š” addAction ๋ฐฉ์‹์œผ๋กœ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐํ•œ ์˜ˆ์‹œ ์ฝ”๋“œ์—์š”! private func setButtonEvent() { self.datePickerView.setAction() let moveToTodayDateButtonAction = UIAction { [weak self] _ in self?.moveToTodayDate() } let moveToTodayDatePickerButtonAction = UIAction { [weak self] _ in self?.moveToDatePicker() } let moveToSettingViewAction = UIAction { [weak self] _ in self?.moveToSettingView() } self.homeCalenderView.todayButton.addAction(moveToTodayDateButtonAction, for: .touchUpInside) self.homeCalenderView.calendarMonthLabelButton.addAction(moveToTodayDatePickerButtonAction, for: .touchUpInside) self.homeCalenderView.calendarMonthPickButton.addAction(moveToTodayDatePickerButtonAction, for: .touchUpInside) self.profileButton.addAction(moveToSettingViewAction, for: .touchUpInside) }
@@ -0,0 +1,205 @@ +// +// LoginView.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/16. +// + +import UIKit + +class LoginView: UIView { + + // MARK: - Object Setting + + private let mainLabel = UILabel().then { + $0.text = "TVING ID ๋กœ๊ทธ์ธ" + $0.font = .tvingMedium(ofSize: 23) + $0.textColor = .tvingGray1 + $0.textAlignment = .center + } + + let idTextField = CustomTextField().then { + $0.placeholder = "์ด๋ฉ”์ผ" + $0.setPlaceholderColor(.tvingGray2) + $0.font = .tvingMedium(ofSize: 15) + $0.textColor = .tvingGray2 + $0.backgroundColor = .tvingGray4 + $0.keyboardType = .emailAddress + } + + let idInvalidLabel = UILabel().then { + $0.textColor = .systemRed + $0.font = .systemFont(ofSize: 12) + $0.text = "* ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์€ ์ด๋ฉ”์ผ ํ˜•์‹์ž…๋‹ˆ๋‹ค ๐Ÿ˜ญ" + $0.isHidden = true + } + + let passwordTextField = CustomPasswordTextField().then { + $0.placeholder = "๋น„๋ฐ€๋ฒˆํ˜ธ" + $0.setPlaceholderColor(.tvingGray2) + $0.font = .tvingMedium(ofSize: 15) + $0.textColor = .tvingGray2 + $0.backgroundColor = .tvingGray4 + $0.keyboardType = .asciiCapable + } + + lazy var logInBtn = UIButton().then { + $0.setTitle("๋กœ๊ทธ์ธํ•˜๊ธฐ", for: .normal) + $0.setTitleColor(.tvingGray2, for: .normal) + $0.titleLabel?.font = .tvingMedium(ofSize: 14) + $0.titleLabel?.textAlignment = .center + $0.layer.borderColor = UIColor.tvingGray4.cgColor + $0.layer.borderWidth = 1 + $0.layer.cornerRadius = 3 + $0.isEnabled = false + } + + private let idPasswordStackView = UIStackView().then { + $0.axis = .horizontal + $0.distribution = .fill + $0.alignment = .center + $0.spacing = 40 + } + + lazy var findIdBtn = UIButton().then { + $0.setTitle("์•„์ด๋”” ์ฐพ๊ธฐ", for: .normal) + $0.setTitleColor(.tvingGray2, for: .normal) + $0.titleLabel?.font = .tvingMedium(ofSize: 14) + $0.titleLabel?.textAlignment = .center + } + + lazy var findPasswordBtn = UIButton().then { + $0.setTitle("๋น„๋ฐ€๋ฒˆํ˜ธ ์ฐพ๊ธฐ", for: .normal) + $0.setTitleColor(.tvingGray2, for: .normal) + $0.titleLabel?.font = .tvingMedium(ofSize: 14) + $0.titleLabel?.textAlignment = .center + } + + private let makeAccountStackView = UIStackView().then { + $0.axis = .horizontal + $0.distribution = .fill + $0.alignment = .center + $0.spacing = 20 + } + + let askExistAccountLabel = UILabel().then { + $0.text = "์•„์ง ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”?" + $0.font = .tvingRegular(ofSize: 14) + $0.textColor = .tvingGray3 + $0.textAlignment = .center + } + + lazy var goToMakeNicknameBtn = UIButton().then { + $0.setTitle("๋‹‰๋„ค์ž„ ๋งŒ๋“ค๋Ÿฌ๊ฐ€๊ธฐ", for: .normal) + $0.setTitleColor(.tvingGray2, for: .normal) + $0.titleLabel?.font = .tvingRegular(ofSize: 14) + $0.titleLabel?.textAlignment = .center + $0.setUnderline() + } + + lazy var backBtn = UIButton().then { + $0.setImage(UIImage(named: "btn_before"), for: .normal) + } + + override init(frame: CGRect) { + super.init(frame: frame) + + style() + hierarchy() + setLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + +} + +private extension LoginView { + + func style() { + self.backgroundColor = .black + } + + func hierarchy() { + self.addSubviews(mainLabel, + idTextField, + idInvalidLabel, + passwordTextField, + logInBtn, + idPasswordStackView, + makeAccountStackView, + backBtn) + idPasswordStackView.addArrangedSubviews(findIdBtn, + findPasswordBtn) + makeAccountStackView.addArrangedSubviews(askExistAccountLabel, + goToMakeNicknameBtn) + } + + + func setLayout() { + + mainLabel.snp.makeConstraints{ + $0.height.equalTo(37) + $0.top.equalTo(self.safeAreaLayoutGuide).inset(50) + $0.leading.trailing.equalToSuperview().inset(100) + } + + idTextField.snp.makeConstraints{ + $0.height.equalTo(52) + $0.top.equalTo(mainLabel.snp.bottom).offset(31) + $0.leading.trailing.equalToSuperview().inset(20) + } + + passwordTextField.snp.makeConstraints{ + $0.height.equalTo(52) + $0.top.equalTo(idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + + logInBtn.snp.makeConstraints{ + $0.height.equalTo(52) + $0.top.equalTo(passwordTextField.snp.bottom).offset(21) + $0.leading.trailing.equalToSuperview().inset(20) + } + + idPasswordStackView.snp.makeConstraints { + $0.height.equalTo(25) + $0.top.equalTo(logInBtn.snp.bottom).offset(30) + $0.centerX.equalToSuperview().inset(80) + } + + makeAccountStackView.snp.makeConstraints { + $0.height.equalTo(25) + $0.top.equalTo(idPasswordStackView.snp.bottom).offset(30) + $0.centerX.equalToSuperview().inset(50) + } + + backBtn.snp.makeConstraints{ + $0.height.equalTo(15) + $0.width.equalTo(8) + $0.top.equalTo(self.safeAreaLayoutGuide).inset(25) + $0.leading.equalToSuperview().inset(24) + } + + findIdBtn.snp.makeConstraints{ + $0.width.equalTo(70) + $0.height.equalTo(22) + } + + findPasswordBtn.snp.makeConstraints{ + $0.width.equalTo(80) + $0.height.equalTo(22) + } + + askExistAccountLabel.snp.makeConstraints{ + $0.width.equalTo(140) + $0.height.equalTo(22) + } + + goToMakeNicknameBtn.snp.makeConstraints{ + $0.width.equalTo(128) + $0.height.equalTo(22) + } + } +}
Swift
์ด๊ฑด ์ œ๊ฐ€ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์ธ๋ฐ addSubviews ํ•  ๋•Œ ๊ฐ€๋กœ๋กœ ๊ธธ๊ฒŒ ์“ฐ๋Š”๊ฒƒ ๋ณด๋‹ค ์•„๋ž˜ ์ฝ”๋“œ์ฒ˜๋Ÿผ ์„ธ๋กœ๋กœ ๋Š˜๋ฆฌ๋Š”๊ฒŒ ๊ฐ€๋…์„ฑ์— ์ข‹๋”๋ผ๊ณ ์š”. ๋ฌผ๋ก  ์ฝ”๋“œ ์ค„์€ ๋Š˜์–ด๋‚˜์ง€๋งŒ์š”! ๊ฐ์ž ์„ ํ˜ธํ•˜๋Š” ์Šคํƒ€์ผ์ด ์žˆ๋Š”๊ฒƒ ๊ฐ™์€๋ฐ ์กฐ์‹ฌ์Šค๋ ˆ.. ์ œ์•ˆํ•ด๋ด…๋‹ˆ๋‹ค ใ…Žใ…Ž view.addSubviews(toolBarView, titleLabelStackView, houseImageView, homeGroupLabel, homeGroupCollectionView, homeRuleView, homeDivider, datePickerView, homeCalenderView, homeWeekCalendarCollectionView, calendarDailyTableView, emptyHouseWorkImage)
@@ -0,0 +1,45 @@ +// +// WelcomeViewController.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/12. +// + +import UIKit + +final class WelcomeViewController: BaseViewController { + + // MARK: - Property + + private let mainView = WelcomeView() + + // MARK: - Target + + private func target() { + mainView.goToMainBtn.addTarget(self, action: #selector(tappedGoToMainBtn), for: .touchUpInside) + } + + // MARK: - Lift Cycle + + override func loadView() { + self.view = mainView + } + + override func viewDidLoad() { + super.viewDidLoad() + + target() + } +} + +extension WelcomeViewController { + + func idDataBind(idOrNick: String) { + mainView.welcomeLabel.text = "\(idOrNick)๋‹˜\n๋ฐ˜๊ฐ€์›Œ์š”!" + } + + @objc + func tappedGoToMainBtn() { + self.navigationController?.popToRootViewController(animated: true) + } +}
Swift
์ œ๊ฐ€ ์ตœ๊ทผ์— ์ƒ๊ฐ ์—†์ด ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ ํ•จ์ˆ˜ ํ˜ธ์ถœ์„ viewWillAppear ์ชฝ์—์„œ ํ–ˆ๋‹ค๊ฐ€... ๋ฌธ์ œ๊ฐ€ ์ƒ๊ฒผ๋Š”๋ฐ viewDidLoad์— ๋„ˆ๋ฌด ์ž˜ ํ•ด๋‘์…จ๋„ค์š” ^~^
@@ -0,0 +1,261 @@ +// +// LoginViewController_TVING.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/11. +// + +import UIKit + +import SnapKit +import Then + +struct TvingUserInfo { + var id: String? + var password: String? + var nickName: String? +} + +final class LoginViewController_TVING: BaseViewController { + + // MARK: - Property + + private let mainView = LoginView() + private let nickNameBottomSheet = AddNickNameBottomSheetUIView() + + var user = TvingUserInfo() + + private var bottomSheetKeyboardEnable: Bool = false + + // MARK: - Target + + private func target() { + mainView.idTextField.delegate = self + mainView.passwordTextField.delegate = self + + mainView.idTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + mainView.passwordTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + mainView.logInBtn.addTarget(self, action: #selector(tappedLogInBtn), for: .touchUpInside) + mainView.goToMakeNicknameBtn.addTarget(self, action: #selector(tappedMakeNickNameBtn), for: .touchUpInside) + } + + private func targetBottomSheet() { + nickNameBottomSheet.nickNameTextField.delegate = self + + nickNameBottomSheet.nickNameTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + nickNameBottomSheet.saveNickNameBtn.addTarget(self, action: #selector(tappedSavedNickNameBtn), for: .touchUpInside) + + let bottomSheetBackgroundTap = UITapGestureRecognizer(target: self, action: #selector(TappedBottomSheetBackground)) + nickNameBottomSheet.dimmendView.addGestureRecognizer(bottomSheetBackgroundTap) + } + + // MARK: - Lift Cycle + + override func loadView() { + self.view = mainView + view.addSubview(nickNameBottomSheet) + + nickNameBottomSheet.snp.makeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + target() + targetBottomSheet() + setKeyboardObserver() // ํ‚ค๋ณด๋“œ ํ™œ์„ฑํ™”์— ๋”ฐ๋ฅธ bottomSheet ๋†’์ด ์กฐ์ ˆ ์œ„ํ•ด + } + + override func viewWillAppear(_ animated: Bool) { + initView() + } + +} + +private extension LoginViewController_TVING { + + // MARK: - objc func + + @objc + func tappedLogInBtn() { + saveUserEmail() + let welcomViewController = WelcomeViewController() + welcomViewController.idDataBind(idOrNick: getNickNameOrId()) + self.navigationController?.pushViewController(welcomViewController, animated: true) + } + + @objc + func tappedMakeNickNameBtn() { + showBottomSheet() + } + + @objc + func tappedSavedNickNameBtn() { + saveUserNickName() + hideBottomSheet() + } + + @objc func TappedBottomSheetBackground(_ tapRecognizer: UITapGestureRecognizer) { + hideBottomSheet() + } + + @objc func keyboardWillShow(notification: NSNotification) { + guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return } + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - (nickNameBottomSheet.bottomSheetHeight + keyboardSize.height) + } + } + + @objc func keyboardWillHide(notification: NSNotification) { + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - nickNameBottomSheet.bottomSheetHeight + } + } + + // MARK: - custom func + + func saveUserEmail(){ + guard let id = mainView.idTextField.text else { return } + user.id = id + } + + func saveUserNickName() { + guard let nickName = nickNameBottomSheet.nickNameTextField.text else { return } + user.nickName = nickName + } + + func getNickNameOrId() -> String { + if let nickName = user.nickName { + return nickName + } else { + guard let id = user.id else { return "" } + return id + } + } + + func isIDValid() -> Bool { + guard let id = mainView.idTextField.text else { return false } + return id.isValidEmail() + } + + func showBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = true + nickNameBottomSheet.snp.remakeConstraints { + $0.edges.equalToSuperview() + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height) + }) + } + + func hideBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = false + nickNameBottomSheet.snp.remakeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: self.view.frame.height, width: self.view.frame.width, height: self.view.frame.height) + } + ) + } + + func initView() { + mainView.idTextField.text = nil + mainView.passwordTextField.text = nil + nickNameBottomSheet.nickNameTextField.text = nil + user = TvingUserInfo() + mainView.logInBtn.enableDisableButtonSet(isEnable: false, setColor: .black, setTextColor: .tvingGray2) + } + + func setKeyboardObserver() { + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + } + +} + +// MARK: - TextFieldDelegate + +extension LoginViewController_TVING: UITextFieldDelegate { + + // textField๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldDidBeginEditing(_ textField: UITextField) { + textField.layer.borderColor = UIColor.tvingGray2.cgColor + textField.layer.borderWidth = 0.7 + } + + // textField ๋น„ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { + textField.layer.borderWidth = 0 + + idValidPrint() + + return true + } + + @objc + private func textFieldDidChange(_ textField: UITextField) { + + if let nickNameText = nickNameBottomSheet.nickNameTextField.text { + if (!nickNameText.isValidNickName()) { + nickNameBottomSheet.nickNameTextField.text = nil + } + } + + let idPwIsFull: Bool = mainView.idTextField.hasText && !mainView.passwordTextField.hasText + let saveIdPwBtnEnable: Bool = idPwIsFull && isIDValid() + + if (saveIdPwBtnEnable) { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + + let saveNickNameBtnEnable = !nickNameBottomSheet.nickNameTextField.hasText + + if (saveNickNameBtnEnable) { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + } + + private func idValidPrint() { + + if (!(mainView.idTextField.text?.isValidEmail() ?? false) && !mainView.idTextField.hasText) { + mainView.idTextField.layer.borderColor = UIColor.tvingRed.cgColor + mainView.idTextField.layer.borderWidth = 0.7 + + mainView.idInvalidLabel.isHidden = false + mainView.idInvalidLabel.snp.remakeConstraints { + $0.leading.equalTo(mainView.idTextField.snp.leading) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(5) + } + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(30) + $0.leading.trailing.equalToSuperview().inset(20) + } + } else { + mainView.idTextField.layer.borderWidth = 0 + + mainView.idInvalidLabel.isHidden = true + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + } + } + +}
Swift
๋” ์ด์ƒ ์ƒ์†๋˜์ง€ ์•Š๋Š” ํด๋ž˜์Šค๋ผ๋ฉด final ํ‚ค์›Œ๋“œ ๋ถ™์ด๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์•„์š”!
@@ -0,0 +1,261 @@ +// +// LoginViewController_TVING.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/11. +// + +import UIKit + +import SnapKit +import Then + +struct TvingUserInfo { + var id: String? + var password: String? + var nickName: String? +} + +final class LoginViewController_TVING: BaseViewController { + + // MARK: - Property + + private let mainView = LoginView() + private let nickNameBottomSheet = AddNickNameBottomSheetUIView() + + var user = TvingUserInfo() + + private var bottomSheetKeyboardEnable: Bool = false + + // MARK: - Target + + private func target() { + mainView.idTextField.delegate = self + mainView.passwordTextField.delegate = self + + mainView.idTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + mainView.passwordTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + mainView.logInBtn.addTarget(self, action: #selector(tappedLogInBtn), for: .touchUpInside) + mainView.goToMakeNicknameBtn.addTarget(self, action: #selector(tappedMakeNickNameBtn), for: .touchUpInside) + } + + private func targetBottomSheet() { + nickNameBottomSheet.nickNameTextField.delegate = self + + nickNameBottomSheet.nickNameTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + nickNameBottomSheet.saveNickNameBtn.addTarget(self, action: #selector(tappedSavedNickNameBtn), for: .touchUpInside) + + let bottomSheetBackgroundTap = UITapGestureRecognizer(target: self, action: #selector(TappedBottomSheetBackground)) + nickNameBottomSheet.dimmendView.addGestureRecognizer(bottomSheetBackgroundTap) + } + + // MARK: - Lift Cycle + + override func loadView() { + self.view = mainView + view.addSubview(nickNameBottomSheet) + + nickNameBottomSheet.snp.makeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + target() + targetBottomSheet() + setKeyboardObserver() // ํ‚ค๋ณด๋“œ ํ™œ์„ฑํ™”์— ๋”ฐ๋ฅธ bottomSheet ๋†’์ด ์กฐ์ ˆ ์œ„ํ•ด + } + + override func viewWillAppear(_ animated: Bool) { + initView() + } + +} + +private extension LoginViewController_TVING { + + // MARK: - objc func + + @objc + func tappedLogInBtn() { + saveUserEmail() + let welcomViewController = WelcomeViewController() + welcomViewController.idDataBind(idOrNick: getNickNameOrId()) + self.navigationController?.pushViewController(welcomViewController, animated: true) + } + + @objc + func tappedMakeNickNameBtn() { + showBottomSheet() + } + + @objc + func tappedSavedNickNameBtn() { + saveUserNickName() + hideBottomSheet() + } + + @objc func TappedBottomSheetBackground(_ tapRecognizer: UITapGestureRecognizer) { + hideBottomSheet() + } + + @objc func keyboardWillShow(notification: NSNotification) { + guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return } + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - (nickNameBottomSheet.bottomSheetHeight + keyboardSize.height) + } + } + + @objc func keyboardWillHide(notification: NSNotification) { + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - nickNameBottomSheet.bottomSheetHeight + } + } + + // MARK: - custom func + + func saveUserEmail(){ + guard let id = mainView.idTextField.text else { return } + user.id = id + } + + func saveUserNickName() { + guard let nickName = nickNameBottomSheet.nickNameTextField.text else { return } + user.nickName = nickName + } + + func getNickNameOrId() -> String { + if let nickName = user.nickName { + return nickName + } else { + guard let id = user.id else { return "" } + return id + } + } + + func isIDValid() -> Bool { + guard let id = mainView.idTextField.text else { return false } + return id.isValidEmail() + } + + func showBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = true + nickNameBottomSheet.snp.remakeConstraints { + $0.edges.equalToSuperview() + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height) + }) + } + + func hideBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = false + nickNameBottomSheet.snp.remakeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: self.view.frame.height, width: self.view.frame.width, height: self.view.frame.height) + } + ) + } + + func initView() { + mainView.idTextField.text = nil + mainView.passwordTextField.text = nil + nickNameBottomSheet.nickNameTextField.text = nil + user = TvingUserInfo() + mainView.logInBtn.enableDisableButtonSet(isEnable: false, setColor: .black, setTextColor: .tvingGray2) + } + + func setKeyboardObserver() { + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + } + +} + +// MARK: - TextFieldDelegate + +extension LoginViewController_TVING: UITextFieldDelegate { + + // textField๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldDidBeginEditing(_ textField: UITextField) { + textField.layer.borderColor = UIColor.tvingGray2.cgColor + textField.layer.borderWidth = 0.7 + } + + // textField ๋น„ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { + textField.layer.borderWidth = 0 + + idValidPrint() + + return true + } + + @objc + private func textFieldDidChange(_ textField: UITextField) { + + if let nickNameText = nickNameBottomSheet.nickNameTextField.text { + if (!nickNameText.isValidNickName()) { + nickNameBottomSheet.nickNameTextField.text = nil + } + } + + let idPwIsFull: Bool = mainView.idTextField.hasText && !mainView.passwordTextField.hasText + let saveIdPwBtnEnable: Bool = idPwIsFull && isIDValid() + + if (saveIdPwBtnEnable) { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + + let saveNickNameBtnEnable = !nickNameBottomSheet.nickNameTextField.hasText + + if (saveNickNameBtnEnable) { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + } + + private func idValidPrint() { + + if (!(mainView.idTextField.text?.isValidEmail() ?? false) && !mainView.idTextField.hasText) { + mainView.idTextField.layer.borderColor = UIColor.tvingRed.cgColor + mainView.idTextField.layer.borderWidth = 0.7 + + mainView.idInvalidLabel.isHidden = false + mainView.idInvalidLabel.snp.remakeConstraints { + $0.leading.equalTo(mainView.idTextField.snp.leading) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(5) + } + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(30) + $0.leading.trailing.equalToSuperview().inset(20) + } + } else { + mainView.idTextField.layer.borderWidth = 0 + + mainView.idInvalidLabel.isHidden = true + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + } + } + +}
Swift
์—ฌ๊ธฐ์„œ didSet์„ ์‚ฌ์šฉํ•ด์„œ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ์ข‹์„๊ฑฐ ๊ฐ™์•„์šฉ ์•„๋ž˜ ๋Œ€์ถฉ ์˜ˆ์‹œ๋ฅผ ์ ์—ˆ๋Š”๋ฐ ์ € ์ž์‹ ๋„ didSet์„ ์ž˜ ํ™œ์šฉํ•˜์ง€ ๋ชปํ•ด์„œ @meltsplit @seungchan2 ํ™•์ธ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค ```Swift public var nickName: String = โ€œ" { didSet { guard let nickName = nickNameBottomSheet.nickNameTextFeild.text else { return } self.nickName = nickName } } ```
@@ -0,0 +1,261 @@ +// +// LoginViewController_TVING.swift +// GO_SOPT_Seminar_Assingment +// +// Created by ๊น€๋‹ค์˜ˆ on 2023/04/11. +// + +import UIKit + +import SnapKit +import Then + +struct TvingUserInfo { + var id: String? + var password: String? + var nickName: String? +} + +final class LoginViewController_TVING: BaseViewController { + + // MARK: - Property + + private let mainView = LoginView() + private let nickNameBottomSheet = AddNickNameBottomSheetUIView() + + var user = TvingUserInfo() + + private var bottomSheetKeyboardEnable: Bool = false + + // MARK: - Target + + private func target() { + mainView.idTextField.delegate = self + mainView.passwordTextField.delegate = self + + mainView.idTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + mainView.passwordTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + mainView.logInBtn.addTarget(self, action: #selector(tappedLogInBtn), for: .touchUpInside) + mainView.goToMakeNicknameBtn.addTarget(self, action: #selector(tappedMakeNickNameBtn), for: .touchUpInside) + } + + private func targetBottomSheet() { + nickNameBottomSheet.nickNameTextField.delegate = self + + nickNameBottomSheet.nickNameTextField.addTarget(self, action: #selector(textFieldDidChange), for: .allEditingEvents) + + nickNameBottomSheet.saveNickNameBtn.addTarget(self, action: #selector(tappedSavedNickNameBtn), for: .touchUpInside) + + let bottomSheetBackgroundTap = UITapGestureRecognizer(target: self, action: #selector(TappedBottomSheetBackground)) + nickNameBottomSheet.dimmendView.addGestureRecognizer(bottomSheetBackgroundTap) + } + + // MARK: - Lift Cycle + + override func loadView() { + self.view = mainView + view.addSubview(nickNameBottomSheet) + + nickNameBottomSheet.snp.makeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + target() + targetBottomSheet() + setKeyboardObserver() // ํ‚ค๋ณด๋“œ ํ™œ์„ฑํ™”์— ๋”ฐ๋ฅธ bottomSheet ๋†’์ด ์กฐ์ ˆ ์œ„ํ•ด + } + + override func viewWillAppear(_ animated: Bool) { + initView() + } + +} + +private extension LoginViewController_TVING { + + // MARK: - objc func + + @objc + func tappedLogInBtn() { + saveUserEmail() + let welcomViewController = WelcomeViewController() + welcomViewController.idDataBind(idOrNick: getNickNameOrId()) + self.navigationController?.pushViewController(welcomViewController, animated: true) + } + + @objc + func tappedMakeNickNameBtn() { + showBottomSheet() + } + + @objc + func tappedSavedNickNameBtn() { + saveUserNickName() + hideBottomSheet() + } + + @objc func TappedBottomSheetBackground(_ tapRecognizer: UITapGestureRecognizer) { + hideBottomSheet() + } + + @objc func keyboardWillShow(notification: NSNotification) { + guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return } + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - (nickNameBottomSheet.bottomSheetHeight + keyboardSize.height) + } + } + + @objc func keyboardWillHide(notification: NSNotification) { + if (nickNameBottomSheet.nickNameTextField.isSelected){ + bottomSheetKeyboardEnable = true + nickNameBottomSheet.bottomSheetView.frame.origin.y = UIScreen.main.bounds.height - nickNameBottomSheet.bottomSheetHeight + } + } + + // MARK: - custom func + + func saveUserEmail(){ + guard let id = mainView.idTextField.text else { return } + user.id = id + } + + func saveUserNickName() { + guard let nickName = nickNameBottomSheet.nickNameTextField.text else { return } + user.nickName = nickName + } + + func getNickNameOrId() -> String { + if let nickName = user.nickName { + return nickName + } else { + guard let id = user.id else { return "" } + return id + } + } + + func isIDValid() -> Bool { + guard let id = mainView.idTextField.text else { return false } + return id.isValidEmail() + } + + func showBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = true + nickNameBottomSheet.snp.remakeConstraints { + $0.edges.equalToSuperview() + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height) + }) + } + + func hideBottomSheet() { + nickNameBottomSheet.nickNameTextField.isSelected = false + nickNameBottomSheet.snp.remakeConstraints { + $0.width.equalToSuperview() + $0.top.equalTo(view.snp.bottom) + } + UIView.animate(withDuration: 0.5, animations: { + self.nickNameBottomSheet.frame = CGRect(x: 0.0, y: self.view.frame.height, width: self.view.frame.width, height: self.view.frame.height) + } + ) + } + + func initView() { + mainView.idTextField.text = nil + mainView.passwordTextField.text = nil + nickNameBottomSheet.nickNameTextField.text = nil + user = TvingUserInfo() + mainView.logInBtn.enableDisableButtonSet(isEnable: false, setColor: .black, setTextColor: .tvingGray2) + } + + func setKeyboardObserver() { + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + } + +} + +// MARK: - TextFieldDelegate + +extension LoginViewController_TVING: UITextFieldDelegate { + + // textField๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldDidBeginEditing(_ textField: UITextField) { + textField.layer.borderColor = UIColor.tvingGray2.cgColor + textField.layer.borderWidth = 0.7 + } + + // textField ๋น„ํ™œ์„ฑํ™”๋˜๋ฉด + func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { + textField.layer.borderWidth = 0 + + idValidPrint() + + return true + } + + @objc + private func textFieldDidChange(_ textField: UITextField) { + + if let nickNameText = nickNameBottomSheet.nickNameTextField.text { + if (!nickNameText.isValidNickName()) { + nickNameBottomSheet.nickNameTextField.text = nil + } + } + + let idPwIsFull: Bool = mainView.idTextField.hasText && !mainView.passwordTextField.hasText + let saveIdPwBtnEnable: Bool = idPwIsFull && isIDValid() + + if (saveIdPwBtnEnable) { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + mainView.logInBtn.enableDisableButtonSet(isEnable: saveIdPwBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + + let saveNickNameBtnEnable = !nickNameBottomSheet.nickNameTextField.hasText + + if (saveNickNameBtnEnable) { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .tvingRed, setTextColor: .white) + }else { + nickNameBottomSheet.saveNickNameBtn.enableDisableButtonSet(isEnable: saveNickNameBtnEnable, setColor: .black, setTextColor: .tvingGray2) + } + } + + private func idValidPrint() { + + if (!(mainView.idTextField.text?.isValidEmail() ?? false) && !mainView.idTextField.hasText) { + mainView.idTextField.layer.borderColor = UIColor.tvingRed.cgColor + mainView.idTextField.layer.borderWidth = 0.7 + + mainView.idInvalidLabel.isHidden = false + mainView.idInvalidLabel.snp.remakeConstraints { + $0.leading.equalTo(mainView.idTextField.snp.leading) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(5) + } + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(30) + $0.leading.trailing.equalToSuperview().inset(20) + } + } else { + mainView.idTextField.layer.borderWidth = 0 + + mainView.idInvalidLabel.isHidden = true + + mainView.passwordTextField.snp.remakeConstraints { + $0.height.equalTo(52) + $0.top.equalTo(mainView.idTextField.snp.bottom).offset(7) + $0.leading.trailing.equalToSuperview().inset(20) + } + } + } + +}
Swift
์˜ต์…”๋„ ์ฒ˜๋ฆฌ์— ๋Œ€ํ•ด ๊ณต๋ถ€ํ•˜๋Š”๊ฑด ๋ถ„๋ช… ๋‚˜์ค‘์— ์ข‹์€ ์ž์‚ฐ์ด ๋ ๊ฑฐ์—์—ฌ!