-
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.
- Loading branch information
Showing
31 changed files
with
184 additions
and
58 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
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React, { useState, useEffect, useCallback, useContext } from 'react'; | ||
import { useLocation } from 'react-router-dom'; | ||
import { TargetsContext } from './context/targets'; | ||
import Nav from 'parts/Nav'; | ||
import { isDir, pageTitle } from 'funcs/paths'; | ||
import { setFavicon, blinkFavicon } from 'funcs/favicon'; | ||
import { isActiveTarget } from 'funcs/targets'; | ||
import { dirPath } from 'funcs/paths'; | ||
import useView, { viewObject } from 'state'; | ||
import View from 'views/View'; | ||
|
||
export default function Loader() { | ||
const { targets } = useContext(TargetsContext); | ||
const path = useLocation().pathname; | ||
|
||
const { view, setView } = useView() | ||
|
||
const [status, setStatus] = useState(""); | ||
|
||
async function loadView(path: string) { | ||
const resp = await fetch("/api/view" + path); | ||
if (!resp.ok) { | ||
setStatus(resp.status + " - " + resp.statusText) | ||
} | ||
const newView = await resp.json(); | ||
setView(newView); | ||
}; | ||
|
||
// only load when a new *dir* is requested | ||
useEffect(() => { | ||
document.title = pageTitle(path); | ||
setFavicon(path); | ||
|
||
if (shouldLoad(path, view)) { | ||
loadView(path); | ||
} | ||
}, [path, view]); | ||
|
||
function shouldLoad(path: string, view: viewObject): boolean { | ||
// load if is new dir | ||
if (isDir(path) && dirPath(path) !== view.path) { | ||
return true | ||
} | ||
// load if is file but no dir loaded | ||
if (!isDir(path) && view.path === "") { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// listen if another tab sends files to this tab. | ||
const listenForWrite = useCallback(() => { | ||
if (isActiveTarget(targets, path)) { | ||
loadView(path); | ||
blinkFavicon(path); | ||
} | ||
}, [targets, path]); | ||
|
||
useEffect(() => { | ||
window.addEventListener('storage', listenForWrite); | ||
|
||
return () => { | ||
window.removeEventListener('storage', listenForWrite); | ||
}; | ||
}, [listenForWrite]); | ||
|
||
if (status !== "") { | ||
return ( | ||
<> | ||
<Nav path={path} /> | ||
<br /> | ||
<code>{status}</code> | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<Nav path={path} /> | ||
<View path={path} files={view.dir.files} sorted={view.dir.sorted} /> | ||
</> | ||
); | ||
} |
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
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
File renamed without changes.
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
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
File renamed without changes.
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
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
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
File renamed without changes.
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
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
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
src/views/folder/views/dir.tsx → src/views/folder/DirView.tsx
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
6 changes: 3 additions & 3 deletions
6
src/views/folder/views/media.tsx → src/views/folder/MediaView.tsx
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
4 changes: 2 additions & 2 deletions
4
src/views/folder/views/text.tsx → src/views/folder/TextView.tsx
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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
import File from 'funcs/files'; | ||
import Info from './Info'; | ||
import AddInfo from './extra/AddInfo'; | ||
|
||
export default function Image({file, isSingle}: { file: File; isSingle?: boolean }) { | ||
if (isSingle) { | ||
return <img alt="" src={"/file" + file.path} /> | ||
} else { | ||
return ( | ||
<div className="list-media"> | ||
<img alt="" src={"/file" + file.path} /> | ||
<AddInfo mainFilePath={file.path}></AddInfo> | ||
<Info mainFilePath={file.path} /> | ||
</div> | ||
) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
|
||
import TextField from './TextView'; | ||
import { newInfoFile } from 'funcs/files'; | ||
|
||
export default function Info({ mainFilePath }: { mainFilePath: string }) { | ||
const info = newInfoFile(mainFilePath); | ||
return ( | ||
<TextField file={info} isSingle={false} /> | ||
) | ||
} |
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
import File from 'funcs/files'; | ||
import AddInfo from 'views/folder/files/extra/AddInfo' | ||
|
||
type VideoProps = { | ||
file: File; | ||
isSingle?: boolean; | ||
} | ||
|
||
export default function Video({file, isSingle}: VideoProps) { | ||
if (isSingle) { | ||
return ( | ||
<video controls src={"/file" + file.path}></video> | ||
) | ||
} else { | ||
return ( | ||
<div className="list-media"> | ||
<video controls src={"/file" + file.path}></video> | ||
<AddInfo mainFilePath={file.path}></AddInfo> | ||
</div> | ||
) | ||
} | ||
} | ||
|
File renamed without changes.
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
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
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
File renamed without changes.
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
8 changes: 4 additions & 4 deletions
8
src/views/folder/switch.tsx → src/views/folder/parts/switch.tsx
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
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
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