forked from CSID-DGU/2024-2-OSSProj-Osori-FE-01
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request CSID-DGU#83 from study2895:main
[Fix] ํ์ผ ์ญ์ ํ auth.js ๋ชจ๋ ์ค๋ฅ ์์
- Loading branch information
Showing
1 changed file
with
35 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |