Toggle navigation
Toggle navigation
This project
Loading...
Sign in
최원석
/
2021-1-database-project
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
1seok2
2021-06-05 01:18:36 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
58d689776314bc5965dd5240d04657f5a149c5e5
58d68977
1 parent
f73d0213
refactor: change for fetch data type
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
35 deletions
app/src/App.ts
app/src/store/state.ts
app/src/views/body/contents/main/Main.ts
app/src/views/header/Header.ts
app/src/App.ts
View file @
58d6897
...
...
@@ -15,7 +15,7 @@ import { getElement } from "./shared/functions";
function
App
(
pathname
:
string
):
string
{
/* id 없을 시 id 입력으로 redirect */
if
(
!
getState
().
insta_id
)
pathname
=
""
;
if
(
getState
().
user
[
0
]
===
""
)
pathname
=
""
;
history
.
pushState
(
""
,
""
,
pathname
);
return
`
...
...
app/src/store/state.ts
View file @
58d6897
...
...
@@ -5,28 +5,20 @@
* 주로 instaId, followers, following 관리
**/
export
interface
StateType
{
insta_id
?
:
string
,
followers
?
:
Array
<
string
>
,
following
?
:
Array
<
string
>
,
src
?
:
string
}
const
initialState
=
{
insta_id
:
''
,
followers
:
[
''
],
following
:
[
''
],
src
:
''
,
}
let
state
:
StateType
=
initialState
;
user
:
[
""
,
""
,
""
],
follower
:
[[
""
,
""
,
""
]],
};
export
const
setState
=
(
newState
:
StateType
):
void
=>
{
let
state
=
initialState
;
export
const
setState
=
(
newState
):
void
=>
{
state
=
{
...
state
,
...
newState
}
...
newState
,
};
};
export
const
getState
=
()
=>
{
return
state
}
\ No newline at end of file
return
state
;
};
...
...
app/src/views/body/contents/main/Main.ts
View file @
58d6897
...
...
@@ -13,33 +13,23 @@ import { getState } from "@src/store/state";
const
Main
=
()
=>
{
const
state
=
getState
();
let
followers
:
string
=
""
;
let
following
:
string
=
""
;
state
.
follower
s
?.
sort
().
forEach
((
id
,
idx
)
=>
{
followers
+=
`<div class="item item-
${
idx
%
2
}
">
${
id
}
</div>`
;
state
.
follower
?.
forEach
((
follower
,
idx
)
=>
{
followers
+=
`<div class="item item-
${
idx
%
2
}
">
${
follower
[
0
]
}
</div>`
;
});
state
.
following
?.
sort
().
forEach
((
id
,
idx
)
=>
{
following
+=
`<div class="item item-
${
idx
%
2
}
">
${
id
}
</div>`
;
});
const
followers_num
=
formatNumber
(
state
.
followers
?.
length
||
0
);
const
followings_num
=
formatNumber
(
state
.
following
?.
length
||
0
);
const
followers_num
=
formatNumber
(
state
.
follower
?.
length
||
0
);
return
`
<div class="main">
<div class="profile">
<img src="
${
state
.
src
}
" alt="
${
state
.
insta_id
}
-image"/>
<img src="
${
state
}
" alt="
${
state
.
user
[
0
]
}
-image"/>
</div>
<div class="list">
<div class="followers">
<h2 class="title">FOLLOWERS (
${
followers_num
}
)</h2>
<div>
${
followers
}
</div>
</div>
<div class="following">
<h2 class="title">FOLLOWINGS (
${
followings_num
}
)</h2>
<div>
${
following
}
</div>
</div>
</div>
</div>
`
;
...
...
app/src/views/header/Header.ts
View file @
58d6897
...
...
@@ -12,7 +12,7 @@ import { getState } from "@src/store/state";
import
{
addEventWithElementByType
,
handleFetchById
}
from
"@src/shared/event"
;
const
Header
=
():
string
=>
{
const
{
insta_id
}
=
getState
();
const
{
user
}
=
getState
();
addEventWithElementByType
(
document
.
body
,
"click"
,
function
(
e
:
Event
)
{
if
((
e
.
target
as
HTMLButtonElement
).
id
===
"update-button"
)
{
...
...
@@ -25,7 +25,7 @@ const Header = (): string => {
return
`
<div class="header">
<div class="form-container">
<input type="text" name="insta_id" id="id-input" placeholder="
${
insta_id
}
" value="
${
insta_id
}
" />
<input type="text" name="insta_id" id="id-input" placeholder="
${
user
[
0
]}
" value="
${
user
[
0
]
}
" />
<button id="update-button">UPDATE</button>
</div>
</div>
...
...
Please
register
or
login
to post a comment