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
์ค‘๋ณต๋˜๋Š” ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ ์ƒ์ˆ˜์ฒ˜๋ฆฌ ํ•ด์ค˜๋„ ์ข‹์„๊ฑฐ๊ฐ™์•„์š”