Skip to content

Commit

Permalink
Merge pull request CSID-DGU#83 from study2895:main
Browse files Browse the repository at this point in the history
[Fix] ํŒŒ์ผ ์‚ญ์ œ ํ›„ auth.js ๋ชจ๋“ˆ ์˜ค๋ฅ˜ ์ˆ˜์ •
  • Loading branch information
study2895 authored Dec 5, 2024
2 parents 6c5afb1 + c31eb49 commit d94bbea
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,61 @@
import { createStore } from 'vuex';
import auth from '../views/test/auth.js'; // auth ๋ชจ๋“ˆ import
import login from './modules/login.js'; // ๋กœ๊ทธ์ธ ๋ชจ๋“ˆ import
import { v4 as uuidv4 } from 'uuid'; // UUID๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ณ ์œ  ID ์ƒ์„ฑ
import { createStore } from 'vuex'
import login from './modules/login.js' // ๋กœ๊ทธ์ธ ๋ชจ๋“ˆ import
import { v4 as uuidv4 } from 'uuid' // UUID๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ณ ์œ  ID ์ƒ์„ฑ

// ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€์—์„œ ํฌํŠธํด๋ฆฌ์˜ค ๊ฐ€์ ธ์˜ค๊ธฐ
const getStoredPortfolios = () => {
const storedPortfolios = localStorage.getItem('portfolios');
return storedPortfolios ? JSON.parse(storedPortfolios) : [];
};
const storedPortfolios = localStorage.getItem('portfolios')
return storedPortfolios ? JSON.parse(storedPortfolios) : []
}

const store = createStore({
state: {
portfolios: getStoredPortfolios(), // ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€์—์„œ ํฌํŠธํด๋ฆฌ์˜ค ์ดˆ๊ธฐํ™”
portfolios: getStoredPortfolios() // ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€์—์„œ ํฌํŠธํด๋ฆฌ์˜ค ์ดˆ๊ธฐํ™”
},
mutations: {
ADD_PORTFOLIO(state, portfolio) {
const newPortfolio = { ...portfolio, id: uuidv4() }; // ๊ณ ์œ  ID ์ถ”๊ฐ€
state.portfolios.push(newPortfolio); // ํฌํŠธํด๋ฆฌ์˜ค ์ถ”๊ฐ€
localStorage.setItem('portfolios', JSON.stringify(state.portfolios)); // ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€์— ์ €์žฅ
const newPortfolio = { ...portfolio, id: uuidv4() } // ๊ณ ์œ  ID ์ถ”๊ฐ€
state.portfolios.push(newPortfolio) // ํฌํŠธํด๋ฆฌ์˜ค ์ถ”๊ฐ€
localStorage.setItem('portfolios', JSON.stringify(state.portfolios)) // ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€์— ์ €์žฅ
},
DELETE_PORTFOLIO(state, portfolioId) {
state.portfolios = state.portfolios.filter(portfolio => portfolio.id !== portfolioId);
localStorage.setItem('portfolios', JSON.stringify(state.portfolios)); // ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€์— ์‚ญ์ œ ํ›„ ์ €์žฅ
state.portfolios = state.portfolios.filter(
(portfolio) => portfolio.id !== portfolioId
)
localStorage.setItem('portfolios', JSON.stringify(state.portfolios)) // ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€์— ์‚ญ์ œ ํ›„ ์ €์žฅ
},
// ์ˆ˜์ • ๊ธฐ๋Šฅ์„ ์œ„ํ•œ UPDATE_PORTFOLIO ๋ฎคํ…Œ์ด์…˜ ์ถ”๊ฐ€
UPDATE_PORTFOLIO(state, updatedPortfolio) {
const index = state.portfolios.findIndex(portfolio => portfolio.id === updatedPortfolio.id);
// ์ˆ˜์ • ๊ธฐ๋Šฅ์„ ์œ„ํ•œ UPDATE_PORTFOLIO ๋ฎคํ…Œ์ด์…˜ ์ถ”๊ฐ€
UPDATE_PORTFOLIO(state, updatedPortfolio) {
const index = state.portfolios.findIndex(
(portfolio) => portfolio.id === updatedPortfolio.id
)
if (index !== -1) {
state.portfolios.splice(index, 1, updatedPortfolio); // ๊ธฐ์กด ํ•ญ๋ชฉ์„ ์—…๋ฐ์ดํŠธ๋œ ํ•ญ๋ชฉ์œผ๋กœ ๊ต์ฒด
localStorage.setItem('portfolios', JSON.stringify(state.portfolios)); // ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€์— ์—…๋ฐ์ดํŠธ ํ›„ ์ €์žฅ
state.portfolios.splice(index, 1, updatedPortfolio) // ๊ธฐ์กด ํ•ญ๋ชฉ์„ ์—…๋ฐ์ดํŠธ๋œ ํ•ญ๋ชฉ์œผ๋กœ ๊ต์ฒด
localStorage.setItem('portfolios', JSON.stringify(state.portfolios)) // ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€์— ์—…๋ฐ์ดํŠธ ํ›„ ์ €์žฅ
}
},
}
},
actions: {
addPortfolio({ commit }, portfolio) {
commit('ADD_PORTFOLIO', portfolio); // mutation ํ˜ธ์ถœ
commit('ADD_PORTFOLIO', portfolio) // mutation ํ˜ธ์ถœ
},
deletePortfolio({ commit }, portfolioId) {
commit('DELETE_PORTFOLIO', portfolioId);
},
// ์ˆ˜์ • ๊ธฐ๋Šฅ์„ ์œ„ํ•œ updatePortfolio ์•ก์…˜ ์ถ”๊ฐ€
updatePortfolio({ commit }, updatedPortfolio) {
commit('UPDATE_PORTFOLIO', updatedPortfolio); // UPDATE_PORTFOLIO ๋ฎคํ…Œ์ด์…˜ ํ˜ธ์ถœ
commit('DELETE_PORTFOLIO', portfolioId)
},
// ์ˆ˜์ • ๊ธฐ๋Šฅ์„ ์œ„ํ•œ updatePortfolio ์•ก์…˜ ์ถ”๊ฐ€
updatePortfolio({ commit }, updatedPortfolio) {
commit('UPDATE_PORTFOLIO', updatedPortfolio) // UPDATE_PORTFOLIO ๋ฎคํ…Œ์ด์…˜ ํ˜ธ์ถœ
}
},
getters: {
getPortfolios(state) {
return state.portfolios; // ํฌํŠธํด๋ฆฌ์˜ค ๋ชฉ๋ก ๋ฐ˜ํ™˜
},
return state.portfolios // ํฌํŠธํด๋ฆฌ์˜ค ๋ชฉ๋ก ๋ฐ˜ํ™˜
}
},
modules: {
login, // ๋กœ๊ทธ์ธ ๋ชจ๋“ˆ
auth, // auth ๋ชจ๋“ˆ
},
});

export default store;

login // ๋กœ๊ทธ์ธ ๋ชจ๋“ˆ
// auth ๋ชจ๋“ˆ
}
})

export default store

0 comments on commit d94bbea

Please sign in to comment.