code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,55 @@
+package subway.given;
+
+import io.restassured.response.*;
+import org.springframework.http.*;
+
+import java.util.*;
+
+import static io.restassured.RestAssured.*;
+
+public class GivenLineApi {
+
+ public static final String LINE_PATH = "/lines";
+ public static final String BG_COLOR_600 = "bg-color-600";
+
+ public static final String LINE_1 = "์ ๋ถ๋น์ ";
+ public static final String LINE_2 = "๋ถ๋น์ ";
+
+ public static final Long LINE_ID_1 = 1L;
+
+ public static final Long STATION_ID_1 = 1L;
+ public static final Long STATION_ID_2 = 2L;
+ public static final Long STATION_ID_3 = 3L;
+
+ public static ExtractableResponse<Response> createLine(
+ final String name,
+ final Long upStationId,
+ final Long downStationId
+ ) {
+
+ final var params = new HashMap<>();
+ params.put("name", name);
+ params.put("color", BG_COLOR_600);
+ params.put("upStationId", upStationId.toString());
+ params.put("downStationId", downStationId.toString());
+ params.put("distance", "10");
+
+ // When
+ return given().log().all()
+ .body(params)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .when()
+ .post(LINE_PATH)
+ .then().log().all()
+ .extract();
+ }
+
+ public static ExtractableResponse<Response> getLineById(final Long lineId) {
+ return given().log().all()
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .when()
+ .get(LINE_PATH + "/" + lineId)
+ .then().log().all()
+ .extract();
+ }
+} | Java | Map ์ผ๋ก ๋ง๋ค์ด์ ๋๊ธฐ๊ธฐ ๋ณด๋ค๋ DTO ๋ก ๋ง๋ค์ด๋ ์ข์ง ์์๊น์? โบ๏ธ |
@@ -0,0 +1,171 @@
+package subway.line.section;
+
+import io.restassured.response.*;
+import org.junit.jupiter.api.*;
+import org.springframework.boot.test.context.*;
+import org.springframework.test.annotation.*;
+
+import java.util.*;
+
+import static io.restassured.RestAssured.*;
+import static org.assertj.core.api.Assertions.*;
+import static org.springframework.http.HttpStatus.*;
+import static org.springframework.http.MediaType.*;
+import static subway.given.GivenLineApi.*;
+import static subway.given.GivenStationApi.*;
+
+@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+public class SectionAcceptanceTest {
+
+ public static final String BASE_SECTION_PATH = "/lines/1/sections";
+
+ @BeforeEach
+ void setUp() {
+ createStationApi(STATION_1);
+ createStationApi(STATION_2);
+ createStationApi(STATION_3);
+ createLine(LINE_1, STATION_ID_1, STATION_ID_2);
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ํ๋์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์์ ๋,
+ * When: ๊ตฌ๊ฐ์ ์ถ๊ฐ ๋ฑ๋กํ๋ฉด
+ * Then: ๋ชฉ๋ก ์กฐํ ์ ์ถ๊ฐ๋ ๊ตฌ๊ฐ์ ํ์ธํ ์ ์๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ๋ฑ๋ก")
+ void addSection() throws Exception {
+ // Given
+ final var params = getAddSectionParams(STATION_ID_2, STATION_ID_3);
+
+ // When
+ final var response = addSection(params);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(OK.value());
+
+ final var lineResponse = getLineById(LINE_ID_1);
+ final var stationIds = lineResponse.jsonPath().getList("stations.id", Long.class);
+ assertThat(stationIds.size()).isEqualTo(3);
+ assertThat(stationIds).containsAnyOf(1L, 2L, 3L);
+ }
+
+ private static HashMap<Object, Object> getAddSectionParams(final Long upStationId, final Long downStationId) {
+ final var params = new HashMap<>();
+ params.put("upStationId", upStationId);
+ params.put("downStationId", downStationId);
+ params.put("distance", "10");
+ return params;
+ }
+
+ private static ExtractableResponse<Response> addSection(final HashMap<Object, Object> params) {
+ return given().log().all()
+ .when()
+ .contentType(APPLICATION_JSON_VALUE)
+ .body(params)
+ .post(BASE_SECTION_PATH)
+ .then().log().all()
+ .extract();
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ํ๋์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ๊ตฌ๊ฐ์ ์ถ๊ฐ ๋ฑ๋กํ ๋,
+ * Then: ์ํ์ญ์ด ๋
ธ์ ์ ๋ฑ๋ก๋์ด ์๋ ํํ ์ข
์ ์ญ์ด ์๋๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ๋ฑ๋ก - ์ํ์ญ์ ๋
ธ์ ์ ๋ฑ๋ก๋์ด ์๋ ํํ ์ข
์ ์ญ์ด ์๋๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ void addSectionThrow1() throws Exception {
+ // Given
+ final var params = getAddSectionParams(STATION_ID_1, STATION_ID_3);
+
+ // When
+ final var response = addSection(params);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ๋ ๊ฐ์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ๊ตฌ๊ฐ์ ์ถ๊ฐ ๋ฑ๋กํ ๋,
+ * Then: ์๋ก์ด ๊ตฌ๊ฐ์ ํํ์ญ์ด ํด๋น ๋
ธ์ ์ ๋ฑ๋ก๋์ด ์๋ ์ญ์ด๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ๋ฑ๋ก - ์๋ก์ด ๊ตฌ๊ฐ์ ํํ์ญ์ ํด๋น ๋
ธ์ ์ ๋ฑ๋ก๋์ด์๋ ์ญ์ผ ์ ์๋ค.")
+ void addSectionThrow2() throws Exception {
+ // Given
+ final var params = getAddSectionParams(STATION_ID_2, STATION_ID_1);
+
+ // When
+ final var response = addSection(params);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ํํ ์ข
์ ์ญ์ ์ญ์ ํ๋ฉด
+ * Then: ๋ชฉ๋ก ์กฐํ ์ ์ญ์ ๋ ๊ตฌ๊ฐ์ ๋์ค์ง ์๋๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ์ญ์ ")
+ void removeSection() throws Exception {
+ // Given
+ addSection(getAddSectionParams(STATION_ID_2, STATION_ID_3));
+
+ // When
+ final var response = removeSection(STATION_ID_3);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(NO_CONTENT.value());
+
+ final var lineResponse = getLineById(LINE_ID_1);
+ final var stationIds = lineResponse.jsonPath().getList("stations.id", Long.class);
+ assertThat(stationIds.size()).isEqualTo(2);
+ assertThat(stationIds).containsAnyOf(1L, 2L);
+ }
+
+ private static ExtractableResponse<Response> removeSection(final Long stationId) {
+ return given().log().all()
+ .when()
+ .delete(BASE_SECTION_PATH + "?stationId=" + stationId)
+ .then().log().all()
+ .extract();
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ๋ ๊ฐ์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ๊ตฌ๊ฐ์ ์ญ์ ํ ๋,
+ * Then: ๋ง์ง๋ง ๊ตฌ๊ฐ์ด ์๋๋ฉด ์ญ์ ๋์ง ์๋๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ์ญ์ - ๋ง์ง๋ง ๊ตฌ๊ฐ์ด ์๋๋จ ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ void removeSectionThrow1() throws Exception {
+ // Given
+ addSection(getAddSectionParams(STATION_ID_2, STATION_ID_3));
+
+ // When
+ final var response = removeSection(STATION_ID_2);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ํ๋์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์์ ๋
+ * When: ๊ตฌ๊ฐ์ ์ญ์ ํ๋ฉด
+ * Then: ๊ตฌ๊ฐ์ ์ญ์ ํ ์ ์๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ์ญ์ - ๊ตฌ๊ฐ์ด ํ๋์ผ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํ๋ค")
+ void removeSectionThrow2() throws Exception {
+ // When
+ final var response = removeSection(STATION_ID_2);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+} | Java | `@DirtiesContext` ๋ฅผ ํ์ฉํด ํ
์คํธ ๊ฒฉ๋ฆฌ๋ฅผ ํด ์ฃผ์
จ๊ตฐ์! ๐
`@DirtiesContext` ๋ ์ปจํ
์คํธ๋ฅผ ๋ค์ ๋ก๋ํ๊ธฐ ๋๋ฌธ์ ํ
์คํธ ์๋๊ฐ ์ค๋ ๊ฑธ๋ฆฐ๋ค๋ ๋จ์ ์ด ์์ต๋๋ค!
์ด ๋ถ๋ถ์ ํ๋ฒ ๊ณ ๋ฏผํด ๋ณด์๋ฉด ์ข์ ๊ฑฐ ๊ฐ์ต๋๋ค ๐ |
@@ -0,0 +1,171 @@
+package subway.line.section;
+
+import io.restassured.response.*;
+import org.junit.jupiter.api.*;
+import org.springframework.boot.test.context.*;
+import org.springframework.test.annotation.*;
+
+import java.util.*;
+
+import static io.restassured.RestAssured.*;
+import static org.assertj.core.api.Assertions.*;
+import static org.springframework.http.HttpStatus.*;
+import static org.springframework.http.MediaType.*;
+import static subway.given.GivenLineApi.*;
+import static subway.given.GivenStationApi.*;
+
+@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+public class SectionAcceptanceTest {
+
+ public static final String BASE_SECTION_PATH = "/lines/1/sections";
+
+ @BeforeEach
+ void setUp() {
+ createStationApi(STATION_1);
+ createStationApi(STATION_2);
+ createStationApi(STATION_3);
+ createLine(LINE_1, STATION_ID_1, STATION_ID_2);
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ํ๋์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์์ ๋,
+ * When: ๊ตฌ๊ฐ์ ์ถ๊ฐ ๋ฑ๋กํ๋ฉด
+ * Then: ๋ชฉ๋ก ์กฐํ ์ ์ถ๊ฐ๋ ๊ตฌ๊ฐ์ ํ์ธํ ์ ์๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ๋ฑ๋ก")
+ void addSection() throws Exception {
+ // Given
+ final var params = getAddSectionParams(STATION_ID_2, STATION_ID_3);
+
+ // When
+ final var response = addSection(params);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(OK.value());
+
+ final var lineResponse = getLineById(LINE_ID_1);
+ final var stationIds = lineResponse.jsonPath().getList("stations.id", Long.class);
+ assertThat(stationIds.size()).isEqualTo(3);
+ assertThat(stationIds).containsAnyOf(1L, 2L, 3L);
+ }
+
+ private static HashMap<Object, Object> getAddSectionParams(final Long upStationId, final Long downStationId) {
+ final var params = new HashMap<>();
+ params.put("upStationId", upStationId);
+ params.put("downStationId", downStationId);
+ params.put("distance", "10");
+ return params;
+ }
+
+ private static ExtractableResponse<Response> addSection(final HashMap<Object, Object> params) {
+ return given().log().all()
+ .when()
+ .contentType(APPLICATION_JSON_VALUE)
+ .body(params)
+ .post(BASE_SECTION_PATH)
+ .then().log().all()
+ .extract();
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ํ๋์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ๊ตฌ๊ฐ์ ์ถ๊ฐ ๋ฑ๋กํ ๋,
+ * Then: ์ํ์ญ์ด ๋
ธ์ ์ ๋ฑ๋ก๋์ด ์๋ ํํ ์ข
์ ์ญ์ด ์๋๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ๋ฑ๋ก - ์ํ์ญ์ ๋
ธ์ ์ ๋ฑ๋ก๋์ด ์๋ ํํ ์ข
์ ์ญ์ด ์๋๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ void addSectionThrow1() throws Exception {
+ // Given
+ final var params = getAddSectionParams(STATION_ID_1, STATION_ID_3);
+
+ // When
+ final var response = addSection(params);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ๋ ๊ฐ์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ๊ตฌ๊ฐ์ ์ถ๊ฐ ๋ฑ๋กํ ๋,
+ * Then: ์๋ก์ด ๊ตฌ๊ฐ์ ํํ์ญ์ด ํด๋น ๋
ธ์ ์ ๋ฑ๋ก๋์ด ์๋ ์ญ์ด๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ๋ฑ๋ก - ์๋ก์ด ๊ตฌ๊ฐ์ ํํ์ญ์ ํด๋น ๋
ธ์ ์ ๋ฑ๋ก๋์ด์๋ ์ญ์ผ ์ ์๋ค.")
+ void addSectionThrow2() throws Exception {
+ // Given
+ final var params = getAddSectionParams(STATION_ID_2, STATION_ID_1);
+
+ // When
+ final var response = addSection(params);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ํํ ์ข
์ ์ญ์ ์ญ์ ํ๋ฉด
+ * Then: ๋ชฉ๋ก ์กฐํ ์ ์ญ์ ๋ ๊ตฌ๊ฐ์ ๋์ค์ง ์๋๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ์ญ์ ")
+ void removeSection() throws Exception {
+ // Given
+ addSection(getAddSectionParams(STATION_ID_2, STATION_ID_3));
+
+ // When
+ final var response = removeSection(STATION_ID_3);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(NO_CONTENT.value());
+
+ final var lineResponse = getLineById(LINE_ID_1);
+ final var stationIds = lineResponse.jsonPath().getList("stations.id", Long.class);
+ assertThat(stationIds.size()).isEqualTo(2);
+ assertThat(stationIds).containsAnyOf(1L, 2L);
+ }
+
+ private static ExtractableResponse<Response> removeSection(final Long stationId) {
+ return given().log().all()
+ .when()
+ .delete(BASE_SECTION_PATH + "?stationId=" + stationId)
+ .then().log().all()
+ .extract();
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ๋ ๊ฐ์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ๊ตฌ๊ฐ์ ์ญ์ ํ ๋,
+ * Then: ๋ง์ง๋ง ๊ตฌ๊ฐ์ด ์๋๋ฉด ์ญ์ ๋์ง ์๋๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ์ญ์ - ๋ง์ง๋ง ๊ตฌ๊ฐ์ด ์๋๋จ ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ void removeSectionThrow1() throws Exception {
+ // Given
+ addSection(getAddSectionParams(STATION_ID_2, STATION_ID_3));
+
+ // When
+ final var response = removeSection(STATION_ID_2);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ํ๋์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์์ ๋
+ * When: ๊ตฌ๊ฐ์ ์ญ์ ํ๋ฉด
+ * Then: ๊ตฌ๊ฐ์ ์ญ์ ํ ์ ์๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ์ญ์ - ๊ตฌ๊ฐ์ด ํ๋์ผ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํ๋ค")
+ void removeSectionThrow2() throws Exception {
+ // When
+ final var response = removeSection(STATION_ID_2);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+} | Java | ์์ธ ์๋๋ฆฌ์ค์ ๋ํด ํ
์คํธ๋ฅผ ์ํด์ฃผ์
จ๋ค์! ๐ |
@@ -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,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 | ์ต์
๋ ์ฒ๋ฆฌ์ ๋ํด ๊ณต๋ถํ๋๊ฑด ๋ถ๋ช
๋์ค์ ์ข์ ์์ฐ์ด ๋ ๊ฑฐ์์ฌ! |
@@ -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 | ๋ฒํผ ํ์ฑํ์ ์ ๊ท์์ ๋ง๋์ง ํ์ธํ๋ ๋ถ๋ถ์ ๋๋ ์ฃผ๋ฉด ๋ ์ข์๊ฑฐ ๊ฐ์์
๋ฒํผ ํ์ฑํ๋ -> textFeild์ ๊ธ์ด ์ฐจ ์์ ๊ฒฝ์ฐ -> textFeildDidChange๋ฅผ ์ฌ์ฉํ๋ฉด ์ข์๊ฑฐ ๊ฐ๊ณ
์ ๊ท์ ํ์ธ -> ๋ฒํผ์ ๋๋ ์ ๋ -> ๋ฒํผ์ addTarget์ ํด์ ํ์ธํด์ฃผ๋ toastMessage๋ print๋ฌธ์ ์ฐ์ด์ฃผ๋๊ฒ ์ข์๊ฑฐ ๊ฐ์ต๋๋ค~ |
@@ -0,0 +1,119 @@
+//
+// AddNickNameBottomSheetUIView.swift
+// GO_SOPT_Seminar_Assingment
+//
+// Created by ๊น๋ค์ on 2023/04/15.
+//
+
+import UIKit
+
+import SnapKit
+import Then
+
+final class AddNickNameBottomSheetUIView: UIView {
+
+ let bottomSheetHeight = UIScreen.main.bounds.height / 2
+
+ let dimmendView = UIView().then {
+ $0.backgroundColor = .black.withAlphaComponent(0.5)
+ }
+
+ private lazy var dragIndicatior = UIView().then {
+ $0.backgroundColor = .tvingGray1
+ $0.layer.cornerRadius = 3
+ }
+
+ let bottomSheetView = UIView().then {
+ $0.backgroundColor = .white
+ $0.layer.cornerRadius = 12
+ $0.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner] // ์ข์ฐ์ธก ํ๋จ์ ๊ทธ๋๋ก
+ }
+
+ private let nickNameMainLabel = UILabel().then {
+ $0.text = "๋๋ค์์ ์
๋ ฅํด์ฃผ์ธ์"
+ $0.font = .tvingMedium(ofSize: 23)
+ }
+
+ let nickNameTextField = CustomTextField().then {
+ $0.placeholder = "๋๋ค์"
+ $0.setPlaceholderColor(.tvingGray1)
+ $0.textColor = .black
+ $0.backgroundColor = .tvingGray2
+ $0.font = .tvingMedium(ofSize: 14)
+ }
+
+ lazy var saveNickNameBtn = UIButton().then {
+ $0.setTitle("์ ์ฅํ๊ธฐ", for: .normal)
+ $0.titleLabel?.font = .tvingMedium(ofSize: 16)
+ $0.titleLabel?.textAlignment = .center
+ $0.titleLabel?.textColor = .tvingGray2
+ $0.backgroundColor = .black
+ $0.layer.cornerRadius = 12
+ $0.isEnabled = false
+ }
+
+ override init(frame: CGRect) {
+ super.init(frame: frame)
+
+ style()
+ hierarchy()
+ setLayout()
+ }
+
+ required init?(coder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+}
+
+private extension AddNickNameBottomSheetUIView {
+
+ func style() {
+
+ }
+
+ func hierarchy() {
+ self.addSubviews(dimmendView,
+ dragIndicatior,
+ bottomSheetView)
+ bottomSheetView.addSubviews(nickNameMainLabel,
+ nickNameTextField,
+ saveNickNameBtn)
+ }
+
+ func setLayout() {
+
+ dimmendView.snp.makeConstraints {
+ $0.edges.equalToSuperview()
+ }
+
+ bottomSheetView.snp.makeConstraints {
+ $0.height.equalTo(bottomSheetHeight)
+ $0.bottom.left.right.equalToSuperview()
+ $0.top.equalToSuperview().inset(UIScreen.main.bounds.height - bottomSheetHeight)
+ }
+
+ dragIndicatior.snp.makeConstraints {
+ $0.height.equalTo(5)
+ $0.leading.trailing.equalToSuperview().inset(120)
+ $0.bottom.equalTo(bottomSheetView.snp.top).inset(-10)
+ }
+
+ nickNameMainLabel.snp.makeConstraints {
+ $0.top.equalToSuperview().inset(45)
+ $0.leading.equalToSuperview().inset(20)
+ }
+
+ nickNameTextField.snp.makeConstraints {
+ $0.height.equalTo(52)
+ $0.top.equalTo(nickNameMainLabel.snp.bottom).offset(21)
+ $0.leading.trailing.equalToSuperview().inset(20)
+ }
+
+ saveNickNameBtn.snp.makeConstraints {
+ $0.height.equalTo(52)
+ $0.bottom.equalToSuperview().inset(20)
+ $0.leading.trailing.equalToSuperview().inset(20)
+ }
+ }
+
+} | Swift | ์ ๊ทผ ์ ์ด์๋ฅผ ํ์ฉํ ๋๋ ๋ด๊ฐ ํด๋น ๋ด์ฉ์(? ๋ช
์นญ์ด ์ ๋งคํจ) ์ฌ์ฉํ ์ต์ํ์ ๋ฒ์๋ก ์ฌ์ฉํ๋๊ฒ ์ข์์! ๋ง์ฝ ํด๋น ํ์ผ์์๋ง ์ฌ์ฉํ component๋ผ๋ฉด private์ผ๋ก ๋ฐ๊พธ๋๊ฒ๋ ์ข๊ฒ ์ฃ ? |
@@ -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 | ์ด์ฉ์ง ๋ ์ด์์ ์ก์ผ๋ฉด์๋ ์ด๊ฒ ๋ง๋.. ์ถ์์ด๋ฏธ๋ค
์คํ๋ทฐ๋ก ๋ค์ ์ง๋ดค์ด์!!!!!! |
@@ -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 | bottomSheet ๋๋ฌธ์ ์ด์ฉ๋ค๋ณด๋..
์ฅ๋จ์ ์ด ์๋ ๊ฒ ๊ฐ์์!!! ์ฝ๋๋ ์ง์ง ๊ฐ๊ฒฐํด์ก์ฃต |
@@ -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 | bottomSheet๋ฅผ ์ฌ๋ฆฌ๋ ค๊ณ ์ฌ์ฉํ๋๋ฐ ์ด๊ฒ ๋ง๋์ง๋ ๋ฉ๊ฒ ใ
๋ค์..ใ
ใ
|
@@ -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,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,36 @@
+package rentcar.domain;
+
+public class Avante extends Car {
+
+ private static final String NAME = "Avante";
+ private static final double DISTANCE_PER_LITER = 15;
+ private static final String VALIDATE_TRIP_DISTANCE_MESSAGE = "[ERROR] ์ฌํ๊ฑฐ๋ฆฌ๋ 0 ์ด์์
๋๋ค.";
+
+ private double tripDistance;
+
+ public Avante(double tripDistance) {
+ validateTripDistance(tripDistance);
+ this.tripDistance = tripDistance;
+ }
+
+ private void validateTripDistance(double tripDistance) {
+ if (tripDistance < 0) {
+ throw new IllegalArgumentException(VALIDATE_TRIP_DISTANCE_MESSAGE);
+ }
+ }
+
+ @Override
+ double getDistancePerLiter() {
+ return DISTANCE_PER_LITER;
+ }
+
+ @Override
+ double getTripDistance() {
+ return tripDistance;
+ }
+
+ @Override
+ String getName() {
+ return NAME;
+ }
+} | Java | Car (์ถ์) ํด๋์ค์ ํ์ ๊ตฌํ์ฒด๋ค์ ๋ชจ๋ ์ด ๋ก์ง์ด ๋ฐ๋ณต๋๊ณ ์์ด์. ๐
๋ฐ๋ณต๋๋ ์ฝ๋๋ฅผ Car ํด๋์ค์ ๊ตฌํํ๋ฉด ๋ฐ๋ณต๋๋ ์ฝ๋๋ฅผ ์ค์ผ ์ ์์ ๊ฒ ๊ฐ์์. ๐ค |
@@ -0,0 +1,36 @@
+package rentcar.domain;
+
+public class Avante extends Car {
+
+ private static final String NAME = "Avante";
+ private static final double DISTANCE_PER_LITER = 15;
+ private static final String VALIDATE_TRIP_DISTANCE_MESSAGE = "[ERROR] ์ฌํ๊ฑฐ๋ฆฌ๋ 0 ์ด์์
๋๋ค.";
+
+ private double tripDistance;
+
+ public Avante(double tripDistance) {
+ validateTripDistance(tripDistance);
+ this.tripDistance = tripDistance;
+ }
+
+ private void validateTripDistance(double tripDistance) {
+ if (tripDistance < 0) {
+ throw new IllegalArgumentException(VALIDATE_TRIP_DISTANCE_MESSAGE);
+ }
+ }
+
+ @Override
+ double getDistancePerLiter() {
+ return DISTANCE_PER_LITER;
+ }
+
+ @Override
+ double getTripDistance() {
+ return tripDistance;
+ }
+
+ @Override
+ String getName() {
+ return NAME;
+ }
+} | Java | `0`์ด ์ด๋ค ์ซ์์ธ์ง ์์๋ก ์ถ์ถํ์ฌ ์๋ฏธ๋ฅผ ๋ช
ํํ๊ฒ ํด์ฃผ๋ฉด ์ข์ ๊ฒ ๊ฐ์์. ๐ค |
@@ -0,0 +1,7 @@
+package rentcar.domain;
+
+public interface Reportable {
+
+ String generateReport();
+
+} | Java | ์ธํฐํ์ด์ค ํ์ฉ ๐๐ |
@@ -0,0 +1,92 @@
+package blackjack.controller;
+
+import blackjack.domain.card.CardFactory;
+import blackjack.domain.card.Deck;
+import blackjack.domain.report.GameReports;
+import blackjack.domain.request.DrawRequest;
+import blackjack.domain.request.UserNamesRequest;
+import blackjack.domain.user.Dealer;
+import blackjack.domain.user.Player;
+import blackjack.domain.user.Players;
+import blackjack.view.InputView;
+import blackjack.view.OutputView;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class BlackJack {
+
+ private final Players players;
+ private final Deck deck;
+
+ private BlackJack(Players players, Deck deck) {
+ this.players = players;
+ this.deck = deck;
+ }
+
+ public static BlackJack init(UserNamesRequest playerNames) {
+ Dealer dealer = new Dealer();
+ Players candidates = playerNames.userNames()
+ .stream()
+ .map(Player::new)
+ .collect(Collectors.collectingAndThen(Collectors.toList(),
+ players -> new Players(dealer, players)));
+ CardFactory cardFactory = CardFactory.getInstance();
+ Deck deck = new Deck(cardFactory.createCards());
+ return new BlackJack(candidates, deck);
+ }
+
+ public void runGame() {
+ spreadStartCards();
+ if (!players.hasBlackJack()) {
+ drawPlayers();
+ drawDealer();
+ }
+ GameReports reports = getResult();
+ showResult(reports);
+ }
+
+ private void spreadStartCards() {
+ players.drawStartCards(deck);
+ OutputView.printAllPlayersCard(players);
+ }
+
+ private void drawPlayers() {
+ for (Player player : players.findOnlyPlayers()) {
+ drawEachPlayer(player);
+ }
+ }
+
+ private void drawEachPlayer(Player player) {
+ while (player.isDrawable() && getPlayerRequest(player)) {
+ player.drawCard(deck.spreadCard());
+ OutputView.printEachCardInfo(player);
+ }
+ }
+
+ private boolean getPlayerRequest(Player player) {
+ String drawRequest = InputView.getDrawRequest(player);
+ return DrawRequest.valueOf(drawRequest)
+ .isDrawable();
+ }
+
+ private void drawDealer() {
+ Dealer dealer = players.findDealer();
+ while (dealer.isDrawable()) {
+ dealer.drawCard(deck.spreadCard());
+ OutputView.printDealerGetCard();
+ }
+ }
+
+ private GameReports getResult() {
+ Dealer dealer = players.findDealer();
+ List<Player> candidates = players.findOnlyPlayers();
+ return candidates.stream()
+ .map(dealer::createReport)
+ .collect(Collectors.collectingAndThen(Collectors.toList(), GameReports::new));
+ }
+
+ private void showResult(GameReports reports) {
+ OutputView.printResultStatus(players.all());
+ OutputView.printReports(reports);
+ }
+} | Java | `collectingAndThen` ํจ์๋ ์ ๋ ๋ชฐ๋๋๋ฐ, ์ ์ฉํ ๊ฒ ๊ฐ์์! ๐คญ๐ |
@@ -0,0 +1,92 @@
+package blackjack.controller;
+
+import blackjack.domain.card.CardFactory;
+import blackjack.domain.card.Deck;
+import blackjack.domain.report.GameReports;
+import blackjack.domain.request.DrawRequest;
+import blackjack.domain.request.UserNamesRequest;
+import blackjack.domain.user.Dealer;
+import blackjack.domain.user.Player;
+import blackjack.domain.user.Players;
+import blackjack.view.InputView;
+import blackjack.view.OutputView;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class BlackJack {
+
+ private final Players players;
+ private final Deck deck;
+
+ private BlackJack(Players players, Deck deck) {
+ this.players = players;
+ this.deck = deck;
+ }
+
+ public static BlackJack init(UserNamesRequest playerNames) {
+ Dealer dealer = new Dealer();
+ Players candidates = playerNames.userNames()
+ .stream()
+ .map(Player::new)
+ .collect(Collectors.collectingAndThen(Collectors.toList(),
+ players -> new Players(dealer, players)));
+ CardFactory cardFactory = CardFactory.getInstance();
+ Deck deck = new Deck(cardFactory.createCards());
+ return new BlackJack(candidates, deck);
+ }
+
+ public void runGame() {
+ spreadStartCards();
+ if (!players.hasBlackJack()) {
+ drawPlayers();
+ drawDealer();
+ }
+ GameReports reports = getResult();
+ showResult(reports);
+ }
+
+ private void spreadStartCards() {
+ players.drawStartCards(deck);
+ OutputView.printAllPlayersCard(players);
+ }
+
+ private void drawPlayers() {
+ for (Player player : players.findOnlyPlayers()) {
+ drawEachPlayer(player);
+ }
+ }
+
+ private void drawEachPlayer(Player player) {
+ while (player.isDrawable() && getPlayerRequest(player)) {
+ player.drawCard(deck.spreadCard());
+ OutputView.printEachCardInfo(player);
+ }
+ }
+
+ private boolean getPlayerRequest(Player player) {
+ String drawRequest = InputView.getDrawRequest(player);
+ return DrawRequest.valueOf(drawRequest)
+ .isDrawable();
+ }
+
+ private void drawDealer() {
+ Dealer dealer = players.findDealer();
+ while (dealer.isDrawable()) {
+ dealer.drawCard(deck.spreadCard());
+ OutputView.printDealerGetCard();
+ }
+ }
+
+ private GameReports getResult() {
+ Dealer dealer = players.findDealer();
+ List<Player> candidates = players.findOnlyPlayers();
+ return candidates.stream()
+ .map(dealer::createReport)
+ .collect(Collectors.collectingAndThen(Collectors.toList(), GameReports::new));
+ }
+
+ private void showResult(GameReports reports) {
+ OutputView.printResultStatus(players.all());
+ OutputView.printReports(reports);
+ }
+} | Java | `BlackJack` ํด๋์ค๋ Controller์ ์ฉ๋๋ก ์ฌ์ฉํ๋ ค๋ ๊ฒ ๊ฐ์ผ๋ ๋น์ฆ๋์ค ๋ก์ง์ด ์๋น์ ์กด์ฌํ๋ ๊ฒ ๊ฐ์์. ๐ค
Controller๋ ์ํ ๊ฐ์ ๊ฐ์ง์ง ์์์ผํด์. ๐
`BlackJackController` ํด๋์ค์ ๋น์ฆ๋์ค ๋ชจ๋ธ์ธ `BlackJack` ํด๋์ค๋ก ๋ถ๋ฆฌํด๋ณผ ์ ์์ ๊ฒ ๊ฐ์์. ๐ค |
@@ -0,0 +1,34 @@
+package blackjack.domain.card;
+
+public enum Number {
+
+ ACE(1, "A"),
+ TWO(2, "2"),
+ THREE(3, "3"),
+ FOUR(4, "4"),
+ FIVE(5, "5"),
+ SIX(6, "6"),
+ SEVEN(7, "7"),
+ EIGHT(8, "8"),
+ NINE(9, "9"),
+ TEN(10, "10"),
+ JACK(10, "J"),
+ QUEEN(10, "Q"),
+ KING(10, "K");
+
+ private final int score;
+ private final String message;
+
+ Number(int score, String message) {
+ this.score = score;
+ this.message = message;
+ }
+
+ public int score() {
+ return score;
+ }
+
+ public String message() {
+ return message;
+ }
+} | Java | enum ํด๋์ค๋ช
์ด `ACE, JACK, QUEEN, KING`์ ํฌํจํ๋ ์๋ฏธ๋ผ๊ณ ๋ณผ ์ ์์๊น์? ๐ค
`Type` or `CardType`๊ณผ ๊ฐ์ ๋ค์ด๋ฐ์ ์ด๋จ๊น์? ๐ |
@@ -0,0 +1,34 @@
+package blackjack.domain.card;
+
+public enum Number {
+
+ ACE(1, "A"),
+ TWO(2, "2"),
+ THREE(3, "3"),
+ FOUR(4, "4"),
+ FIVE(5, "5"),
+ SIX(6, "6"),
+ SEVEN(7, "7"),
+ EIGHT(8, "8"),
+ NINE(9, "9"),
+ TEN(10, "10"),
+ JACK(10, "J"),
+ QUEEN(10, "Q"),
+ KING(10, "K");
+
+ private final int score;
+ private final String message;
+
+ Number(int score, String message) {
+ this.score = score;
+ this.message = message;
+ }
+
+ public int score() {
+ return score;
+ }
+
+ public String message() {
+ return message;
+ }
+} | Java | ๊ฐ์ฒด์ ์ํ ๊ฐ์ ์ธ๋ถ๋ก ํธ์ถํ๋ ๋ฉ์๋๋ `getter` ๋ฉ์๋๋ฅผ ์ ์ํด์ฃผ์ธ์. ๐
getter, setter์ ๊ฐ์ ๊ด์ต์ ์ธ ๋ฉ์๋ ์์ฑ์ด ๋ฏ์ค๊ฑฐ๋ ์ด๋ ต๋ค๋ฉด `โ + N` ๋จ์ถํค๋ฅผ ํตํด์ ์ด๋ฐ ๋ฉ์๋๋ค์ ์ฝ๊ฒ ์์ฑํ ์ ์์ด์. ๐ค |
@@ -0,0 +1,35 @@
+package blackjack.domain.card;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class CardFactory {
+
+ public static CardFactory INSTANCE;
+
+ private CardFactory() {
+ }
+
+ public static CardFactory getInstance() {
+ if (INSTANCE == null) {
+ INSTANCE = new CardFactory();
+ }
+ return INSTANCE;
+ }
+
+ public List<Card> createCards() {
+ List<Card> cards = new ArrayList<>();
+ for (Suit suit : Suit.values()) {
+ createBySuit(cards, suit);
+ }
+ Collections.shuffle(cards);
+ return cards;
+ }
+
+ private void createBySuit(List<Card> cards, Suit suit) {
+ for (Number number : Number.values()) {
+ cards.add(new Card(suit, number));
+ }
+ }
+} | Java | Deck์ผ๋ก ์ฐ์ด๋ ์นด๋๋ค์ ์นด๋์ ํํ์ ๊ฐฏ์๋ค์ด ์ ํด์ ธ์๊ณ ์ฌ์ฌ์ฉํ ํ๋ฅ ์ด ๋๋ค๊ณ ์๊ฐํด์. ๐
๋ฏธ๋ฆฌ ๋ง๋ค์ด๋๋ค๊ฐ ํ์ํ ์์ ์ ์ฌ์ฌ์ฉํด๋ณด๋ฉด ์ด๋จ๊น์? ๐ค
[์ฐธ๊ณ ์๋ฃ](https://tecoble.techcourse.co.kr/post/2020-06-24-caching-instance/) |
@@ -0,0 +1,22 @@
+package blackjack.domain.card;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+
+public class Deck {
+
+ private final Queue<Card> deck;
+
+ public Deck(List<Card> cards) {
+ this.deck = new LinkedList<>(cards);
+ }
+
+ public Card spreadCard() {
+ return deck.poll();
+ }
+
+ public int remainCardSize() {
+ return deck.size();
+ }
+} | Java | ์ ๋ Stack์ด ์กฐ๊ธ ๋ ์นด๋ ๊ฒ์์ ์ด์ธ๋ฆฐ๋ค๊ณ ์๊ฐํ๋๋ฐ, Queue๋ ์ข์ ์ ๊ทผ์ธ ๊ฒ ๊ฐ์์. ๐ค
`spreadCard` ๋ฉ์๋์์๋ deck์ด ๋น์ด์๋ ๊ฒฝ์ฐ์ ๋ํ ์์ธ ์ฒ๋ฆฌ๋ ํ ์ ์์ ๊ฒ ๊ฐ์์. ๐ |
@@ -0,0 +1,42 @@
+package blackjack.domain.card;
+
+import blackjack.domain.score.ScoreCalculator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class CardBundle {
+
+ private static final int BLACK_JACK_SCORE = 21;
+
+ private final List<Card> cards;
+
+ private CardBundle() {
+ this.cards = new ArrayList<>();
+ }
+
+ public static CardBundle emptyBundle() {
+ return new CardBundle();
+ }
+
+ public void addCard(Card card) {
+ cards.add(card);
+ }
+
+ public int calculateScore() {
+ return ScoreCalculator.findByCards(cards)
+ .calculateScore(cards);
+ }
+
+ public List<Card> getCards() {
+ return Collections.unmodifiableList(cards);
+ }
+
+ public boolean isBurst() {
+ return calculateScore() > BLACK_JACK_SCORE;
+ }
+
+ public boolean isBlackJack() {
+ return calculateScore() == BLACK_JACK_SCORE;
+ }
+} | Java | CardBundle.`empty()` ๋ก๋ ์ถฉ๋ถํ ์๋ฏธ๊ฐ ์ ๋ฌ๋๋ ๊ฒ ๊ฐ์์. ๐ |
@@ -0,0 +1,42 @@
+package blackjack.domain.card;
+
+import blackjack.domain.score.ScoreCalculator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class CardBundle {
+
+ private static final int BLACK_JACK_SCORE = 21;
+
+ private final List<Card> cards;
+
+ private CardBundle() {
+ this.cards = new ArrayList<>();
+ }
+
+ public static CardBundle emptyBundle() {
+ return new CardBundle();
+ }
+
+ public void addCard(Card card) {
+ cards.add(card);
+ }
+
+ public int calculateScore() {
+ return ScoreCalculator.findByCards(cards)
+ .calculateScore(cards);
+ }
+
+ public List<Card> getCards() {
+ return Collections.unmodifiableList(cards);
+ }
+
+ public boolean isBurst() {
+ return calculateScore() > BLACK_JACK_SCORE;
+ }
+
+ public boolean isBlackJack() {
+ return calculateScore() == BLACK_JACK_SCORE;
+ }
+} | Java | `CardBundle` ๊ฐ์ฒด๋ **์นด๋์ ์ ์๋ฅผ ํฉ์ฐํ๋ ์ญํ **์ ์ํํ๋ค๊ณ ์๊ฐํด์. ๐ค
`ScoreCalculator` enum class ๋ด๋ถ ์ฝ๋๋ ๋งค์ฐ ํฅ๋ฏธ๋กญ๊ฒ ๋ดค์ด์. ๐ ๐
ํ์ง๋ง `AceScoreStrategy`, `DefaultScoreStrategy`์ ๋ด๋ถ ์ฝ๋๋ฅผ ๋ณด์์ ๋, ์ด๋ฐ ์์ผ๋ก (์นด๋ ์ ์ ํฉ์ฐ) ์ ๋ต์ ๊ตฌ๋ถํ์ฌ ๊ตฌํํ๋ ๊ฒ๋ณด๋ค ์นด๋ ์ ์ ํฉ์ฐ ๋ก์ง์ด ํ์ํ `CardBundle ๊ฐ์ฒด ๋ด๋ถ`์ ์ง์ ๊ตฌํํ๋ ๊ฒ์ด ๋ ์์ง์ฑ์ด ๋๋ค๊ณ ์๊ฐํด์. ๐
์ง๊ธ์ ์ฝ๋์์ `์ ์๋ฅผ ํฉ์ฐ`ํ๋ ๊ธฐ๋ฅ์ ํ์
ํ๊ธฐ๊ฐ ์ด๋ ค์ด ๊ฒ ๊ฐ์์. ๐ค (์๋์ ๊ฐ์ด ์ฝ๋๋ฅผ ํ์ํด์ผ ํด์. ๐ฑ)
`calculateScore()` -> `ScoreCalculator#findByCards(cards)` -> `ScoreCalculator#isSupportable(cards)` -> `ScoreCalculator#calculateScore(cards)` -> (AceScoreStrategy & DefaultScoreStrategy)`scoreStrategy.calculateScore(cards)`
๋ํ `ScoreCalculator`์ ํจ์๋ฅผ ํธ์ถํ ๋๋ง๋ค, ๊ณ์ํด์ ๋ฉ์๋ ํ๋ผ๋ฏธํฐ(= ์ธ๋ถ)๋ก cards๋ฅผ ์ ๋ฌํ๊ณ ์์ด์. ๐
์ด๋ฐ ๋ถ๋ถ์์ `์นด๋ ์ ์๋ฅผ ํฉ์ฐ`ํ๋ ๊ธฐ๋ฅ์ ๊ฐ์ฒด์ ์ญํ ์ด ์๋๋ผ CardBundle์ ์ญํ ์ด๋ผ๊ณ ์๊ฐ๋ผ์. ๐ค |
@@ -0,0 +1,51 @@
+package blackjack.domain.report;
+
+import java.util.Objects;
+
+public class GameReport {
+
+ private final String name;
+ private final GameResult result;
+
+ public GameReport(String name, GameResult result) {
+ this.name = name;
+ this.result = result;
+ }
+
+ public String name() {
+ return name;
+ }
+
+ public String message() {
+ return result.message();
+ }
+
+ public boolean isWin() {
+ return result == GameResult.WIN;
+ }
+
+ public boolean isDraw() {
+ return result == GameResult.DRAW;
+ }
+
+ public boolean isLose() {
+ return result == GameResult.LOSE;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ GameReport report = (GameReport) o;
+ return Objects.equals(name, report.name) && result == report.result;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, result);
+ }
+} | Java | GameReport ๊ฐ์ฒด์ `๋๋ฑ์ฑ`์ ์ ์ํ ํ์๊ฐ ์๋์? ๐ค
ํน์ ํ์ํ ์์น๊ฐ ์์๊น์? ๐ (์ ๊ฐ ๋ชป ์ฐพ๋ ๊ฑธ๊น์? ๐) |
@@ -0,0 +1,52 @@
+package blackjack.domain.report;
+
+import blackjack.domain.card.CardBundle;
+import java.util.Arrays;
+
+public enum GameResult {
+
+ WIN(1, "์น"),
+ DRAW(0, "๋ฌด"),
+ LOSE(-1, "ํจ");
+
+ private final int result;
+ private final String message;
+
+ GameResult(int result, String message) {
+ this.result = result;
+ this.message = message;
+ }
+
+ public static GameResult comparing(CardBundle playerCardBundle, CardBundle dealerCardBundle) {
+ isComparable(playerCardBundle, dealerCardBundle);
+ if (playerCardBundle.isBurst()) {
+ return GameResult.LOSE;
+ }
+ if (dealerCardBundle.isBurst()) {
+ return GameResult.WIN;
+ }
+ int result = Integer.compare(playerCardBundle.calculateScore(),
+ dealerCardBundle.calculateScore());
+ return findResult(result);
+ }
+
+ public String message() {
+ return message;
+ }
+
+ private static void isComparable(CardBundle dealerCardBundle, CardBundle playerCardBundle) {
+ if (dealerCardBundle == null) {
+ throw new IllegalArgumentException("[ERROR] ๋๋ฌ์ ์นด๋๊ฐ ๋น์์ต๋๋ค");
+ }
+ if (playerCardBundle == null) {
+ throw new IllegalArgumentException("[ERROR] ํ๋ ์ด์ด์ ์นด๋๊ฐ ๋น์์ต๋๋ค.");
+ }
+ }
+
+ private static GameResult findResult(int result) {
+ return Arrays.stream(values())
+ .filter(gameResult -> gameResult.result == result)
+ .findFirst()
+ .orElseThrow(() -> new IllegalArgumentException("[ERROR] ์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ ์
๋๋ค"));
+ }
+} | Java | getter (getter ์ญํ ์ ํ๋ ๋ฉ์๋), setter, compareTo, toString ๋ฑ์ ๋ฉ์๋๋ ํด๋์ค์ ์ตํ๋จ์ ์์น์์ผ์ฃผ์ธ์! |
@@ -0,0 +1,52 @@
+package blackjack.domain.report;
+
+import blackjack.domain.card.CardBundle;
+import java.util.Arrays;
+
+public enum GameResult {
+
+ WIN(1, "์น"),
+ DRAW(0, "๋ฌด"),
+ LOSE(-1, "ํจ");
+
+ private final int result;
+ private final String message;
+
+ GameResult(int result, String message) {
+ this.result = result;
+ this.message = message;
+ }
+
+ public static GameResult comparing(CardBundle playerCardBundle, CardBundle dealerCardBundle) {
+ isComparable(playerCardBundle, dealerCardBundle);
+ if (playerCardBundle.isBurst()) {
+ return GameResult.LOSE;
+ }
+ if (dealerCardBundle.isBurst()) {
+ return GameResult.WIN;
+ }
+ int result = Integer.compare(playerCardBundle.calculateScore(),
+ dealerCardBundle.calculateScore());
+ return findResult(result);
+ }
+
+ public String message() {
+ return message;
+ }
+
+ private static void isComparable(CardBundle dealerCardBundle, CardBundle playerCardBundle) {
+ if (dealerCardBundle == null) {
+ throw new IllegalArgumentException("[ERROR] ๋๋ฌ์ ์นด๋๊ฐ ๋น์์ต๋๋ค");
+ }
+ if (playerCardBundle == null) {
+ throw new IllegalArgumentException("[ERROR] ํ๋ ์ด์ด์ ์นด๋๊ฐ ๋น์์ต๋๋ค.");
+ }
+ }
+
+ private static GameResult findResult(int result) {
+ return Arrays.stream(values())
+ .filter(gameResult -> gameResult.result == result)
+ .findFirst()
+ .orElseThrow(() -> new IllegalArgumentException("[ERROR] ์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ ์
๋๋ค"));
+ }
+} | Java | ๋ CardBundle (์ฌ์ค์ ๋ ๋ฒ์งธ, ํ๋ผ๋ฏธํฐ๋ก ๋ฐ๋ CardBundle์ Dealer์ CardBundle๋ก ๊ณ ์ ๋๋ ๊ฒ ๊ฐ์์. ๐)์ ๋ฐ์์ `๊ฒ์ ๊ฒฐ๊ณผ`๋ฅผ ๋ฐํํ๋ ์ญํ ์ `Dealer`์ ์ญํ ์ด๋ผ๊ณ ๋ณผ ์ ์์ง ์์๊น์? ๐ค (๊ทธ๋ฌ๋ฉด ์ฒซ ๋ฒ์งธ ํ๋ผ๋ฏธํฐ์ ๋ ๋ฒ์งธ ํ๋ผ๋ฏธํฐ์ ์์๋ฅผ ์๋ชป ๋์
ํ๋ค๊ฑฐ๋ ํ๋ ์ค์๋ฅผ ๋ง์ ์๋ ์์ ๊ฒ ๊ฐ์์. ๐) |
@@ -0,0 +1,45 @@
+package blackjack.domain.request;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class UserNamesRequest {
+
+ private static final String USER_NAME_DELIMITER = ",";
+
+ private final List<String> userNames;
+
+ private UserNamesRequest(List<String> userNames) {
+ this.userNames = userNames;
+ }
+
+ public static UserNamesRequest from(String userNames) {
+ validateUserNames(userNames);
+ List<String> splitUserNames = Arrays.stream(userNames.split(USER_NAME_DELIMITER))
+ .map(String::trim)
+ .collect(Collectors.toList());
+ validateDuplicate(splitUserNames);
+ return new UserNamesRequest(splitUserNames);
+ }
+
+ public List<String> userNames() {
+ return Collections.unmodifiableList(userNames);
+ }
+
+ private static void validateUserNames(String userNames) {
+ if (userNames == null || userNames.trim().isEmpty()) {
+ throw new IllegalArgumentException("[ERROR] ์ด๋ฆ์ ์
๋ ฅํด ์ฃผ์ธ์");
+ }
+ }
+
+ private static void validateDuplicate(List<String> splitUserNames) {
+ Set<String> removeDuplicate = new HashSet<>(splitUserNames);
+ if (removeDuplicate.size() != splitUserNames.size()) {
+ throw new IllegalArgumentException("[ERROR] ํ๋ ์ด์ด ์ด๋ฆ์ ์ค๋ณต๋ ์ ์์ต๋๋ค");
+ }
+ }
+} | Java | ์ด ์ ํจ์ฑ ๊ฒ์ฆ ๋ก์ง์ ๋ธ๋์ญ ๋๋ฉ์ธ ๋ชจ๋ธ์ ๊ผญ ํ์ํ ์ ํจ์ฑ ๊ฒ์ฆ์ธ ๊ฒ ๊ฐ์์. ๐
๋จผ์ Player์ ์ํ ๊ฐ์ธ ์์ ๊ฐ name์ ํฌ์ฅํด๋ณด๋ฉด ์ด๋จ๊น์? ๐ค |
@@ -0,0 +1,55 @@
+package blackjack.domain.user;
+
+import blackjack.domain.card.Card;
+import blackjack.domain.card.CardBundle;
+import java.util.List;
+
+public class Player {
+
+ protected final CardBundle cardBundle;
+ private final String name;
+
+ public Player(String name) {
+ validateName(name);
+ this.name = name;
+ this.cardBundle = CardBundle.emptyBundle();
+ }
+
+ private void validateName(String name) {
+ if (name == null || name.trim().length() == 0) {
+ throw new IllegalArgumentException("[ERROR] ์ฌ๋ฐ๋ฅด์ง ์์ ์ด๋ฆ์ ์
๋ ฅ ๊ฐ์
๋๋ค.");
+ }
+ }
+
+ public void drawCard(Card card) {
+ this.cardBundle.addCard(card);
+ }
+
+ public String name() {
+ return name;
+ }
+
+ public boolean isPlayer() {
+ return true;
+ }
+
+ public boolean isDealer() {
+ return false;
+ }
+
+ public int score() {
+ return cardBundle.calculateScore();
+ }
+
+ public boolean isDrawable() {
+ return !cardBundle.isBlackJack() && !cardBundle.isBurst();
+ }
+
+ public List<Card> getCardBundle() {
+ return cardBundle.getCards();
+ }
+
+ public boolean isBlackJack() {
+ return cardBundle.isBlackJack();
+ }
+} | Java | String์ `isEmpty` ํจ์๋ฅผ ๋์ ์ฌ์ฉํด๋ณด๋ฉด ์ด๋จ๊น์? ๐
```suggestion
if (name == null || name.trim().isEmpty()) {
``` |
@@ -0,0 +1,33 @@
+package blackjack.domain.user;
+
+import blackjack.domain.report.GameResult;
+import blackjack.domain.report.GameReport;
+
+public class Dealer extends Player {
+
+ private static final int DEALER_MUST_DRAW_SCORE = 16;
+
+ public Dealer() {
+ super("๋๋ฌ");
+ }
+
+ public GameReport createReport(Player player) {
+ GameResult gameResult = GameResult.comparing(player.cardBundle, this.cardBundle);
+ return new GameReport(player.name(), gameResult);
+ }
+
+ @Override
+ public boolean isPlayer() {
+ return false;
+ }
+
+ @Override
+ public boolean isDealer() {
+ return true;
+ }
+
+ @Override
+ public boolean isDrawable() {
+ return score() <= DEALER_MUST_DRAW_SCORE;
+ }
+} | Java | Dealer๊ฐ ์จ์ ํ Player ํด๋์ค๋ฅผ ๋ฐ๋ก ์์๋ฐ์๊ธฐ ๋๋ฌธ์ ์ด๋ค ๋ฉ์๋๋ฅผ ์ฌ์ ์ํด์ผ ํ๋์ง ํ์
ํ๊ธฐ ์ด๋ ค์ด ๊ฒ ๊ฐ์์. ๐ค
๊ณตํต์ผ๋ก ์ฌ์ฉํ๋ ๋ฉ์๋๋ ๊ทธ๋๋ก ์ฌ์ฉํ ์ ์๊ฒ ํ๋, ํ์ ๊ตฌํ์ฒด์ ๋ฐ๋ผ ๋ฌ๋ผ์ง๋ ๊ธฐ๋ฅ๋ค์ `์ถ์ ๋ฉ์๋`๋ก ์ ์ํด์ ํ์ ๊ตฌํ์ฒด์์๋ ์ฌ์ ์๋ฅผ ๊ฐ์ ํ๋๋ก ํ๋ฉด ์ข์ง ์์๊น์? ๐ |
@@ -0,0 +1,33 @@
+package blackjack.domain.user;
+
+import blackjack.domain.report.GameResult;
+import blackjack.domain.report.GameReport;
+
+public class Dealer extends Player {
+
+ private static final int DEALER_MUST_DRAW_SCORE = 16;
+
+ public Dealer() {
+ super("๋๋ฌ");
+ }
+
+ public GameReport createReport(Player player) {
+ GameResult gameResult = GameResult.comparing(player.cardBundle, this.cardBundle);
+ return new GameReport(player.name(), gameResult);
+ }
+
+ @Override
+ public boolean isPlayer() {
+ return false;
+ }
+
+ @Override
+ public boolean isDealer() {
+ return true;
+ }
+
+ @Override
+ public boolean isDrawable() {
+ return score() <= DEALER_MUST_DRAW_SCORE;
+ }
+} | Java | GameReport ๊ฐ์ฒด์ ์ํ ๊ฐ์ผ๋ก Player์ ์ด๋ฆ์ ๋ฐ๋๊ฒ ์๋๋ผ `Player`๋ฅผ ๊ฐ์ง๋ฉด ์ด๋จ๊น์? ๐ค |
@@ -0,0 +1,82 @@
+package blackjack.view;
+
+import static blackjack.domain.user.Players.START_CARD_INIT_SIZE;
+
+import blackjack.domain.report.GameReports;
+import blackjack.domain.card.Card;
+import blackjack.domain.user.Player;
+import blackjack.domain.user.Players;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class OutputView {
+
+ private OutputView() {
+ }
+
+ public static void printAllPlayersCard(Players players) {
+ List<Player> candiates = players.findOnlyPlayers();
+ Player dealer = players.findDealer();
+ System.out.printf("\n๋๋ฌ์ %s์๊ฒ %d์ฅ ๋๋์์ต๋๋ค.\n", collectPlayerNames(candiates),
+ START_CARD_INIT_SIZE);
+ System.out.printf("%s : %s\n", dealer.name(), collectDealerCard(dealer));
+ candiates.forEach(OutputView::printEachCardInfo);
+ System.out.println();
+ }
+
+ public static void printEachCardInfo(Player player) {
+ System.out.printf("%s : %s\n", player.name(), collectPlayerCard(player));
+ }
+
+ public static void printDealerGetCard() {
+ System.out.println("\n๋๋ฌ๋ 16์ดํ๋ผ ํ์ฅ์ ์นด๋๋ฅผ ๋ ๋ฐ์์ต๋๋ค.");
+ }
+
+ public static void printResultStatus(List<Player> players) {
+ System.out.println();
+ players.forEach(OutputView::showEachResult);
+ }
+
+ public static void printReports(GameReports reports) {
+ System.out.println("\n## ์ต์ข
์นํจ");
+ showDealerReports(reports);
+ reports.reports()
+ .stream()
+ .map(report -> String.format("%s: %s", report.name(), report.message()))
+ .forEach(System.out::println);
+ }
+
+ private static void showDealerReports(GameReports reports) {
+ int dealerWinCount = reports.getPlayerLoseCount();
+ int drawCount = reports.getPlayerDrawCount();
+ int dealerLoseCount = reports.getPlayerWinCount();
+ System.out.printf("๋๋ฌ: %d์น %d๋ฌด %dํจ\n", dealerWinCount, drawCount, dealerLoseCount);
+ }
+
+ private static String collectPlayerNames(List<Player> candiates) {
+ return candiates.stream()
+ .map(Player::name)
+ .collect(Collectors.joining(","));
+ }
+
+ private static String collectDealerCard(Player dealer) {
+ List<Card> cards = dealer.getCardBundle();
+ return makeCardInfo(cards.get(0));
+ }
+
+ private static String makeCardInfo(Card card) {
+ return String.join("", card.message(), card.suit());
+ }
+
+ private static String collectPlayerCard(Player player) {
+ List<Card> cards = player.getCardBundle();
+ return cards.stream()
+ .map(OutputView::makeCardInfo)
+ .collect(Collectors.joining(", "));
+ }
+
+ private static void showEachResult(Player player) {
+ System.out.printf("%s์นด๋: %s - ๊ฒฐ๊ณผ : %d\n", player.name(), collectPlayerCard(player),
+ player.score());
+ }
+} | Java | `findOnlyPlayers`์ `findDealer`๋ ๋น์ฆ๋์ค ๋ก์ง์ด๊ธฐ ๋๋ฌธ์ Model์ ์์ญ์ด๋ผ๊ณ ๋ณผ ์ ์์ด์. ๐
Controller์์ ๋ ๋ฉ์๋๋ฅผ ํธ์ถํ ๋ค, ๋ฉ์๋ ํ๋ผ๋ฏธํฐ๋ก ๊ทธ ๊ฒฐ๊ณผ ๊ฐ๋ค์ ์ ๋ฌ๋ฐ๋๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์! ๐ |
@@ -0,0 +1,34 @@
+package blackjack.domain.card;
+
+public enum Number {
+
+ ACE(1, "A"),
+ TWO(2, "2"),
+ THREE(3, "3"),
+ FOUR(4, "4"),
+ FIVE(5, "5"),
+ SIX(6, "6"),
+ SEVEN(7, "7"),
+ EIGHT(8, "8"),
+ NINE(9, "9"),
+ TEN(10, "10"),
+ JACK(10, "J"),
+ QUEEN(10, "Q"),
+ KING(10, "K");
+
+ private final int score;
+ private final String message;
+
+ Number(int score, String message) {
+ this.score = score;
+ this.message = message;
+ }
+
+ public int score() {
+ return score;
+ }
+
+ public String message() {
+ return message;
+ }
+} | Java | ์ ๋ `getXXX`๊ณผ ๊ฐ์ ๋ค์ด๋ฐ์ด ์คํ๋ ค ๋ด๋ถ ์์ฑ์ ๋
ธ์ถํ๋ค๊ณ ์๊ฐํด์
`์๋ฏธ์๋ ๋ค์ด๋ฐ์ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋๊ฒ ๋ ๋ซ์ง ์์๊น?` ๋ผ๋ ์๊ฐ์ผ๋ก ๋ฉ์๋์ ๋ค์ด๋ฐ์ ์์ฑํด๋ณด์๋๋ฐ
ํด๋น์ ๋ํด์๋ `getXXX`์ผ๋ก ํต์ผํ๋๊ฒ ๋ ์ข์๊น์? |
@@ -0,0 +1,42 @@
+package blackjack.domain.card;
+
+import blackjack.domain.score.ScoreCalculator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class CardBundle {
+
+ private static final int BLACK_JACK_SCORE = 21;
+
+ private final List<Card> cards;
+
+ private CardBundle() {
+ this.cards = new ArrayList<>();
+ }
+
+ public static CardBundle emptyBundle() {
+ return new CardBundle();
+ }
+
+ public void addCard(Card card) {
+ cards.add(card);
+ }
+
+ public int calculateScore() {
+ return ScoreCalculator.findByCards(cards)
+ .calculateScore(cards);
+ }
+
+ public List<Card> getCards() {
+ return Collections.unmodifiableList(cards);
+ }
+
+ public boolean isBurst() {
+ return calculateScore() > BLACK_JACK_SCORE;
+ }
+
+ public boolean isBlackJack() {
+ return calculateScore() == BLACK_JACK_SCORE;
+ }
+} | Java | `empty()`๋ ๊ด์ฐฎ์ ๋ค์ด๋ฐ์ด๋ผ๊ณ ์๊ฐํ์ง๋ง,
ํด๋น ๋ฒ๋ค์ด ๋น์ด์๋ค๋ ์๋ฏธ(`isEmpty()`)์ ์ ์ฌํ๊ฒ ํด์๋ ์๋ ์๋ค๊ณ ์๊ฐํ์ต๋๋ค. |
@@ -0,0 +1,51 @@
+package blackjack.domain.report;
+
+import java.util.Objects;
+
+public class GameReport {
+
+ private final String name;
+ private final GameResult result;
+
+ public GameReport(String name, GameResult result) {
+ this.name = name;
+ this.result = result;
+ }
+
+ public String name() {
+ return name;
+ }
+
+ public String message() {
+ return result.message();
+ }
+
+ public boolean isWin() {
+ return result == GameResult.WIN;
+ }
+
+ public boolean isDraw() {
+ return result == GameResult.DRAW;
+ }
+
+ public boolean isLose() {
+ return result == GameResult.LOSE;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ GameReport report = (GameReport) o;
+ return Objects.equals(name, report.name) && result == report.result;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, result);
+ }
+} | Java | ์ ์ฒ์์ GameReports์ `Set`์ ์๋ํ๊ณ ๊ตฌํํ๋๋ฐ ์ง๊ธ์ ๋ถํ์ํ ๋ฉ์๋๋ผ๊ณ ์๊ฐ๋์ด ์ญ์ ํ๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,21 @@
+package lotto.constants;
+
+public enum ErrorMessage {
+ DUPLICATION("[ERROR] ๊ฐ์ด ์ค๋ณต๋์์ต๋๋ค"),
+ ISNOTINTEGER("[ERROR] ์ซ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์"),
+ SIXNUMBER("[ERROR] ๋ฒํธ 6๊ฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์"),
+ OUTFRANGE("[ERROR] ๋ก๋ ๋ฒํธ๋ 1๋ถํฐ 45 ์ฌ์ด์ ์ซ์์ฌ์ผ ํฉ๋๋ค."),
+ ONENUMBER("[ERROR] ์ซ์ ๋ฒํธ 1๊ฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์"),
+ NOTTHOUSAND("[ERROR] 1000์ ๋จ์๋ก ์
๋ ฅํด ์ฃผ์ธ์");
+
+
+ private final String message;
+
+ ErrorMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+} | Java | ์ค๋ณต๋๋ ๋ถ๋ถ์ ๋ํด์ ์์์ฒ๋ฆฌ ํด์ค๋ ์ข์๊ฑฐ๊ฐ์์ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.