CHOIYEJUN / TodoList

TodoList ๋งŒ๋“ค๊ธฐ.
0 stars 0 forks source link

๐Ÿ‘‰๐Ÿป ReactNetive ๊ณต๋ถ€์˜ ํ”์  ๋ณด๋Ÿฌ๊ฐ€๊ธฐ

๊ฒฐ๊ณผ๋ฌผ

๊ฒฐ๊ณผ๋ฌผ

๊ตฌํ˜„ํ•œ ๊ธฐ๋Šฅ

  1. TodoList ์˜ ์ถ”๊ฐ€ ์‚ญ์ œ
  2. TodoList ์˜ ์ฒดํฌ๋ฐ•์Šค๋ฅผ ํด๋ฆญํ–ˆ์„๋•Œ ์ฒดํฌ๊ธฐ๋Šฅ ๋ฐ TodoList Progress Bar ์—ฐ๋™
  3. Week Select ๋ฐ ์Šคํฌ๋กค ์—๋‹ˆ๋ฉ”์ด์…˜ ๊ธฐ๋Šฅ

๋Š๋‚€์ 

  1. ๋น„์Šทํ•˜๋ฉด์„œ๋„ ๋‹ค๋ฅธ react ์™€ reactNetive

    • react ๋Š” html ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜์ง€๋งŒ reactNetive ๋Š” View, Text, TextInput ๋“ฑ์˜ ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ์˜Œ ์›น ๋ฌธ์„œ๊ฐ€ ์•„๋‹ˆ๋‹ˆ๊นŒ... ใ…Žใ…Ž)
    • ์ƒํƒœ๊ด€๋ฆฌ ๋ฐฉ์‹์ด ๋น„์Šทํ•˜๋‹ค. (useState, useEffect, useRef ๋“ฑ๋“ฑ)
    • ์ด๊ณณ์€ ๋ชจ๋ฐ”์ผ ํ™˜๊ฒฝ์ด๋‹ค. ui ์™€ ๊ธฐ๋Šฅ๋“ค์ด ์›น๊ณผ๋Š” ํ™•์—ฐํžˆ๋‹ค๋ฅด๋‹ค.
    • React Native๋Š” ๊ฑฐ์˜ ๋ชจ๋“  CSS ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๋ ค๊ณ  ๋…ธ๋ ฅํ–ˆ์ง€๋งŒ, CSS ์• ๋‹ˆ๋ฉ”์ด์…˜ ๊ตฌํ˜„ ํˆด์ธ keyframes ๋Š” ์˜ฎ๊ฒจ์˜ค์ง€ ๋ชปํ–ˆ๋‹ค. ๊ทธ๋ž˜์„œ ๋ณต์žกํ•œ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๊ตฌํ˜„ํ•˜๋ ค๋ฉด ๋ณต์žกํ•œ ๊ณผ์ •์ด ์š”๊ตฌ๋œ๋‹ค.
    • ๋””๋ฒ„๊น…์ด ์‰ฝ์ง€ ์•Š๋‹ค.. (์ฃ„๋‹ค console.log ์ฐ์–ด๋ด์•ผ ํ•œ๋‹ค. )
  2. ์ด์ œ ๋ฌด์—‡์„ ํ•ด๋ณผ๊นŒ

    • ์ผ์ฃผ์ผ ๋™์•ˆ ์ž‘์„ฑํ•˜๊ณ  ๊ณต๋ถ€ํ–ˆ๋˜ ๋‚ด์šฉ๋“ค์„ ๊ธฐ์ˆ ๋ธ”๋กœ๊ทธ์— ์ •๋ฆฌํ•ด๋ณผ๊ฒƒ์ด๋‹ค.
    • reactNetive ๋ฅผ ์ด์šฉํ•ด์„œ ๊ธฐ์กด์— ๋งŒ๋“ค์—ˆ๋˜ ๋ฐฐ๋“œ๋ฏผํ„ด ๊ฒŒ์ŠคํŠธ ์˜ˆ์•ฝ ์‹œ์Šคํ…œ์„ ๋ชจ๋ฐ”์ผ ํ™˜๊ฒฝ์œผ๋กœ ๋งŒ๋“ค์–ด๋ณผ๊ฒƒ์ด๋‹ค. (๋ฐฑ์—”๋“œ API ์™€ ํ†ต์‹ ํ•˜๋Š” ๊ณผ์ •๋„ ๊ถ๊ธˆํ•˜๋‹ค.)

๋ฌธ์ œ์˜ ๋ฐœ์ƒ๊ณผ ํ•ด๊ฒฐ

2023 11 30 ๋ฌธ์ œ๋ด‰์ฐฉ...

๋ฌธ์ œ์˜์ƒ

๊ฐœ๋งํ•จ

TodoList ์˜ ์ฒดํฌ๋ฐ•์Šค๋ฅผ ํด๋ฆญํ–ˆ์„๋•Œ ์ฒดํฌ๊ฐ€ ๋˜๊ณ , ํ•ด๋‹น TodoItem ์˜ ํ…์ŠคํŠธ๊ฐ€ ์ทจ์†Œ์„ ์ด ๊ทธ์–ด์ง€๋Š” ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. ํ•˜์ง€๋งŒ ์ทจ์†Œ์„ ์€ Week 1 ์—์„œ๋งŒ ์ƒ๊ธฐ๊ณ , ์ฒซ๋ฒˆ์งธ todoList ๋ฅผ ํด๋ฆญํ•˜๋ฉด ๋ชจ๋“  Week ์˜ ์ฒซ๋ฒˆ์งธ TodoList ๊ฐ€ ์ฒดํฌ๋œ๋‹ค.. (์ทจ์†Œ์„  ์•ˆ๋˜๋Š”๊ฑด ๋ค)

Data ์ž์ฒด๋Š” ์ž˜ get ํ•˜๊ณ  set ํ•˜๋Š”๊ฒƒ ๊ฐ™์€๋ฐ, ํ•ด๋‹น ์ฒดํฌ๋ฐ•์Šค๋ฅผ ๊ทธ๋ ค์ค„๋•Œ ์ž˜๋ชป ๊ทธ๋ ค์ฃผ๊ณ  ์žˆ๋‚˜.... ํ•˜๋Š” ์ƒ๊ฐ์ด ๋“ ๋‹ค. 2์‹œ๊ฐ„์งธ ์ฐพ๋Š”์ค‘์ด๋‹ค... ์†Œ์Šค๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

// ํ•ด๋‹น Week ์˜ TodoList ๋ฅผ ๊ทธ๋ ค์ฃผ๋Š” ํ•จ์ˆ˜ 
{todos.map((todo, index) => (
        <View key={index} style={styles.todoItem}>
           <BouncyCheckbox
                   isChecked={todo.completed}
                   onPress={() => handleToggleTodo(index)}
           />
           <Text style={[styles.todoText , {textDecorationLine : todo.completed ? 'line-through' : 'none' } ]}>{todo.content}</Text>
        </View>
))}

// TodoList ์ฒดํฌ ๋ฐ•์Šค ์ฒดํฌํ•˜๋ฉด ์ฒดํฌ๋œ ๋ฐ์ดํ„ฐ ํ™•์ธํ•ด์„œ 
// completed ๊ฐ’ ๋ฐ”๊ฟ”์ฃผ๋Š” ํ•จ์ˆ˜
  const handleToggleTodo = (weekNumber: number, index: number) => {
    setTodoData(
      (prevData) =>
      prevData.map((todo, i) =>
         todo.weekNumber === weekNumber && i === index
          ? { ...todo, completed: !todo.completed }
          : todo
      )
    );
  };

์ด์ค‘์— ๋ฒ”์ธ์ด ์žˆ์ง€ ์•Š์„๊นŒ...

๋””๋ฒ„๊ทธ๋ฅผ ์ฐ๋Š” ๋ฐฉ๋ฒ•์„ ์ž˜ ๋ชจ๋ฅด๊ฒ ์–ด์„œ ํ•ด๋งค๊ณ  ์žˆ๋‹ค... ๋””๋ฒ„๊ทธ ์ฐ๋Š” ๋ฐฉ๋ฒ•๋ถ€ํ„ฐ ์ฐพ์•„๋ด์•ผ๊ฒ ๋‹คใ… ใ… ใ… 

2023 12 01 0์‹œ 45๋ถ„ ๋ฌธ์ œํ•ด๊ฒฐ

ํ•ด๊ฒฐํ•ด๋”ฐ

๋ฉ์ฒญํ–ˆ๋‹ค...

// TodoList ์ฒดํฌ ๋ฐ•์Šค ์ฒดํฌํ•˜๋ฉด ์ฒดํฌ๋œ ๋ฐ์ดํ„ฐ ํ™•์ธํ•ด์„œ 
// completed ๊ฐ’ ๋ฐ”๊ฟ”์ฃผ๋Š” ํ•จ์ˆ˜
  const handleToggleTodo = (weekNumber: number, index: number) => {
    setTodoData(
      (prevData) =>
      prevData.map((todo, i) =>

        // ์ด๋ถ€๋ถ„์ด ๋ฌธ์ œ์˜€๋‹ค. ( i === index)
         todo.weekNumber === weekNumber && i === index
          ? { ...todo, completed: !todo.completed }
          : todo
      )
    );
  };

weekNumber 1์— 3๊ฐœ์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๊ณ  weekNumber 2์— 3๊ฐœ์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ์„๋•Œ weekNumber 2 ์˜ ์ฒซ๋ฒˆ์งธ todoList ๋ฅผ ํด๋ฆญํ•˜๋ฉด weekNumber : 1 index : 0 ์ด ๋‚˜์˜ค์ง€๋งŒ, i ์—๋Š” 3์ด ๋“ค์–ด๊ฐ€ ๋ฒ„๋ฆฐ ๊ฒƒ์ด์˜€๋‹ค.... ์™œ๋ƒ๋ฉด prevData ๋Š” 0,1,2, "3" ๋ฒˆ์งธ๋ฅผ ๋Œ๊ณ ์žˆ์œผ๋‹ˆ...

๊ทธ๋ž˜์„œ ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •ํ•˜์˜€๋‹ค.

  const handleToggleTodo = (weekNumber: number, index: number) => {
  setTodoData((prevData) => {
    console.log('Previous Data:', prevData);

    // ์ฃผ์–ด์ง„ ์ฃผ์ฐจ์— ํ•ด๋‹นํ•˜๋Š” todo๋งŒ ํ•„ํ„ฐ๋ง
    const filteredData = prevData.filter((todo) => todo.weekNumber === weekNumber);

    // ํ•„ํ„ฐ๋ง๋œ todo๋ฅผ map์„ ์‚ฌ์šฉํ•˜์—ฌ ์—…๋ฐ์ดํŠธ
    const updatedData = filteredData.map((todo, todoIndex) => {
      console.log(todoIndex + ' Todo:', todo);
      if (todoIndex === index) {
        // ์ฃผ์–ด์ง„ index์— ํ•ด๋‹นํ•˜๋Š” todo์˜ completed๋ฅผ ํ† ๊ธ€
        const updatedTodo = {
          ...todo,
          completed: !todo.completed,
        };
        console.log('Updated Todo:', updatedTodo);
        return updatedTodo;
      }
      return todo;
    });
    // ๊ธฐ์กด ๋ฐ์ดํ„ฐ ์ค‘์—์„œ ํ•ด๋‹น ์ฃผ์ฐจ์˜ ๋ฐ์ดํ„ฐ๋งŒ ์—…๋ฐ์ดํŠธ๋œ ๋ฐ์ดํ„ฐ๋กœ ๊ต์ฒด
    return prevData.map((todo) =>
      todo.weekNumber === weekNumber ? updatedData.shift() || todo : todo
    );
  });
};

๋ฐ›์•„์˜จ weekNumber ์— ํ•ด๋‹นํ•˜๋Š” ๋ฐ์ดํ„ฐ๋งŒ ํ•„ํ„ฐ๋ง์„ ํ•ด์ฃผ๊ณ , ํ•„ํ„ฐ๋ง๋œ ๋ฐ์ดํ„ฐ์—์„œ๋งŒ ๋น„๊ตํ•˜์˜€๋‹ค. ๋‚˜๋จธ์ง€๋Š” ๋”ฐ๋กœ ๋„ฃ์–ด์ฃผ๋Š” ํ˜•ํƒœ๋กœ ๊ธฐ๋Šฅ์„ ์ˆ˜์ •ํ–ˆ๋‹ค!!

๋””๋ฒ„๊ทธ๋ฅผ console.log ๋กœ๋งŒ ์ฐ๋‹ค๋ณด๋‹ˆ ๋ฌธ์ œ ํŒŒ์•…์ด ์‰ฝ์ง€ ์•Š์•˜๋˜๊ฒƒ ๊ฐ™๋‹ค.. (web ๋””๋ฒ„๊ทธ ์ฐ๊ธฐ๋Š” ์‰ฌ์› ๋Š”๋ฐ ใ… ใ… ใ… )

2023 12 01 ๊ณ ๋ฏผ์ค‘..

ADD ๋ฒ„ํŠผ๋งŒ ๋ˆŒ๋ €๋Š”๋ฐ ์–ด๋–ป๊ฒŒ ๋ฐ”๋กœ ์žํŒ์ด ์˜ฌ๋ผ์˜ค์ง€?...

๊ทธ๋™์•ˆ์€ TextInput ์— ๊ธ€์ž๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ADD ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์„œ ์ถ”๊ฐ€์‹œ์ผฐ๋Š”๋ฐ... ์ด๋ฒˆ์—๋Š” ADD ๋ฒ„ํŠผ๋งŒ ๋ˆŒ๋ €์„๋•Œ ์žํŒ์ด ์˜ฌ๋ผ์˜ค๊ฒŒ ํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ•˜๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ๋‹ค..

2023 12 02

keyboard ๋ฅผ ๋„์›Œ์ฃผ๋Š” ๊ธฐ๋Šฅ์€ ์—†๋‹ค๊ณ  ํ•œ๋‹ค..

์„ค๋งˆ TextInput ์„ ์–ด๋”˜๊ฐ€์— ์ˆจ๊ฒจ๋†“๊ณ  ADD ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์ˆจ๊ฒจ๋†“์€ textInput ์— ํฌ์ปค์‹ฑ์„ ํ•˜๋Š” ์ด์ƒํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ํ•˜๋ฉด ์•ˆ๋˜๊ฒ ์ง€? ๋ผ๊ณ  ์ƒ๊ฐํ–ˆ์—ˆ์ง€๋งŒ

๋ฐ”๋กœ ๊ทธ๊ฒŒ ์ •๋‹ต..ใ…Žใ…Ž

<View 
      style={{ flexDirection: 'row', justifyContent: 'space-between', paddingHorizontal: 20, alignItems: 'center' }}
    >
  // ์–ด๋”˜๊ฐ€๋กœ ์ˆจ๊ฒจ๋ฒ„๋ฆฐ textInput
      <TextInput
        style={{ position: 'absolute', left: -1000 }}
        ref={textInputRef}
        value={newTodo}
        onChangeText={(text) => setNewTodo(text)}
        onSubmitEditing={handleTextInputSubmit}
      />
      <Button title="Add" onPress={handleButtonPress} color={'#FF7484'} />
    </View>