Skip to content

Commit

Permalink
finalize kurang example
Browse files Browse the repository at this point in the history
  • Loading branch information
zonblade committed Mar 25, 2024
1 parent 34c113a commit 77a66ee
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 34 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions docs/assets/render.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function recrusiveMenu(data, num) {
}
template += `
<div style="width: 100%;" id="par-${fleId}" data-z="${num}">
<div class="pile" page="${item.file}.md" id="${fleId}" data-sub="${hasSub}" onClick="window.openMenu(this);">
<div class="pile" page="${item.file}.md" id="${fleId}" data-path="${item.file}" data-sub="${hasSub}" onClick="window.openMenu(this);">
${item.title}
</div>
${subtemps}
Expand Down Expand Up @@ -113,6 +113,9 @@ window.openMenu = (e) => {
const id = e.id;
// get data-sub
const sub = e.getAttribute('data-sub');
const path = encodeURIComponent(e.getAttribute('data-path'))
window.history.pushState({}, '', `?p=${path}`)

if (sub === "true") {
updateMenuState(id)
// scroll to top
Expand All @@ -136,8 +139,14 @@ async function CST_ContentConstructor(page = "pages/index.md") {
}

(async () => {
const urlParams = new URLSearchParams(window.location.search);
const page = urlParams.get('p');
let initRender = "pages/index.md"
if(page!==null){
initRender = `${decodeURIComponent(page)}.md`
}
await CST_MenuConstructor()
await CST_ContentConstructor()
await CST_ContentConstructor(initRender)
})()

document.addEventListener('click', (e) => {
Expand Down
23 changes: 22 additions & 1 deletion docs/assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ h, h1, h2, h3, h4, h5, h6, th, tr, td, p, ul {
}

pre {
font-size: 16px;
font-size: 14px;
}

a {
color: #00a8ff;
text-decoration: none;
}

a:hover {
color: #00a8ff;
text-decoration: underline;
}

/* make table border white 0.5 */
Expand All @@ -13,6 +23,17 @@ table {
width: 100%;
}

p img {
max-width: 400px;
}

blockquote {
background-color: #1b1b1b;
border-left: 5px solid #404040;
padding: 10px;
margin: 10px;
}

th,
td {
border: 0.5px solid rgb(156, 156, 156);
Expand Down
15 changes: 5 additions & 10 deletions docs/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
{
"mode":"menu",
"title": "Folder Structures",
"title": "Folders & Files Structures",
"file": "pages/folder/index",
"menu": [
{
Expand Down Expand Up @@ -226,7 +226,7 @@
},
{
"mode":"menu",
"title": "Workflow",
"title": "Data Workflow",
"file": "pages/workflow/index",
"menu": [
{
Expand All @@ -235,8 +235,8 @@
{
"id": "folder/intro",
"mode":"menu",
"title": "Element Grouping",
"file": "pages/workflow/index"
"title": "Element Lifecycle",
"file": "pages/workflow/case-study/component"
},
{
"id": "folder/intro",
Expand All @@ -253,15 +253,10 @@
{
"id": "folder/intro",
"mode":"menu",
"title": "Using Next Action",
"title": "Submit/Req Data (client)",
"file": "pages/workflow/posting.client"
}
]
},
{
"mode": "menu",
"title": "TEST",
"file": "pages/test/index"
}
]
}
6 changes: 5 additions & 1 deletion docs/pages/naming/folder/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ The app folder should contain list of feature or page :
├── login
└── user/
└── management
```
```

##### selengkapnya :
- [NextJs App Routing](https://nextjs.org/docs/app/building-your-application/routing)
- [NextJs File Convention](https://nextjs.org/docs/app/api-reference/file-conventions)
133 changes: 133 additions & 0 deletions docs/pages/workflow/case-study/component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
## Studi-Kasus Element Lifecycle.

untuk menghindari `Element Drilling` maupun `Redux` yang menyampah/tidak tertata dengan rapi
maupun bentuk data yang acak, disarankan untuk menggunakan Emitter jika `client component` tersebut
terpisah oleh server component

- Workflow
- Contoh Kode
___
### workflow

![api call](assets/images/case-study/nextjs.workflow-a.png)
![api call](assets/images/case-study/nextjs.workflow-b.png)
___
### Contoh Kode

#### Page File
```tsx
# app/feature/page.tsx

export default function Page(){

return (
<>
<SE_Header />
<SE_List />
</>
)
}
```

#### Server Files

jika kita melakukan render beberapa client element pada server element,
CE_ tersebut tidak akan dapat berkomunikasi melalui direct-line maupun props drilling tanpa
melakukan refresh maupun mengupdate cookie (*jika menggunakan cookie*)
rekomendasi fetch data ditaruh pada `CE_List`, akan dijelaskan pada bagian Client Files

```tsx
# app/feature/$element/server.header.tsx

export function SE_Header(){
return (
<div>
<CE_SearchBar/>
<div>
<CE_SaveButton/>
</div>
</div>
)
}
```

```tsx
# app/feature/$element/server.datalist.tsx

export function SE_List(){

const data = await APIS_Data();

return (
<div>
{data?(
<CE_List data={data} />
):(<></>)}
</div>
)
}
```

#### Client Files

jadi cara untuk mengupdate data jika komponen search
mengirim data seperti dibawah ini.
```sh
<CE_SearchBar/> ::<--update-->:: <CE_List/>
```
dengan menggunakan `useEffect` atau `useMemo`. contoh dibawah ini
pada file `client.header.search.tsx` melakukan emit/mengirim data
dan pada file `client.datalist.tsx` melakukan listen data.
```tsx
# app/feature/$element/client.header.search.tsx

export function CE_SearchBar(){
const [searchText, setSearchText] = useState('');

const updateSearch = (search:string)=>{
setSearchText(search);
GlobalEmitter.emit(E_Somethn.SEARCH, search);
}

return (
<></>
)
}

```
```tsx
# app/feature/$element/client.datalist.tsx

export function CE_List(prop:{data:I_Lists[]}){

const [searchText, setSearchText] = useState('');
const [data, setData] = useState<I_Lists[]>(data);

useEffect(()=>{
GlobalEmitter.addListener(E_Somethn.SEARCH, (text:string)=>{
setSearchText(text)
})
return ()=>{
GlobalEmitter.removeAllListener(E_Somethn.SEARCH)
}
},[])

useEffect(()=>{
CFN_DataFetch({
search:searchText,
whileDone:(data:I_Lists[])=>{
setData(data)
},
whileError:()=>{
// do something
}
})

return ()=>{}
},[searchText])

return(
<></>
)
}
```
4 changes: 4 additions & 0 deletions docs/pages/workflow/fetching.client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Next Action Workflow


![api call](assets/images/api-call-client.png)
4 changes: 4 additions & 0 deletions docs/pages/workflow/fetching.server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Next Action Workflow


![api call](assets/images/api-call-server.png)
26 changes: 6 additions & 20 deletions docs/pages/workflow/index.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
## Data Workflow

## test ini judul folder
beberapa data workflow yang harus dipatuhi untuk
pemanfaatan penuh feature yang diberikan

```html
<h1>hello<span></span></h1>
```

| Name | Age |
|------|-----|
| John | 20 |

```tsx
const hello = () => {
const ok = "yaaa";

return (
<h1>hello<span></span></h1>
)
}
```

hello `test`
- **Fetching Data (Server/Client)** : penting untuk memahami flow pemanggilan dan flow pengembalian data.
- **Submit/Req Data** : penting untuk memahami flow pengiriman data.
- **Element Lifecycle** : point paling krusial untuk manajemen data teratur.

0 comments on commit 77a66ee

Please sign in to comment.