From 3029d255ead3928df52ecbb5cb6ed5fc2f3f98c2 Mon Sep 17 00:00:00 2001 From: mrfry Date: Wed, 24 Aug 2022 18:48:48 +0200 Subject: [PATCH] user files improvements --- src/components/searchBar.module.css | 6 ++ src/pages/chat.js | 2 +- src/pages/userfiles.js | 136 +++++++++++++++++++++------- src/pages/userfiles.module.css | 4 +- 4 files changed, 111 insertions(+), 37 deletions(-) diff --git a/src/components/searchBar.module.css b/src/components/searchBar.module.css index 7d8ab97..f3a8069 100644 --- a/src/components/searchBar.module.css +++ b/src/components/searchBar.module.css @@ -7,6 +7,12 @@ padding-bottom: 2px; } +.searchContainer input { + border: 1px solid var(--text-color); + border-radius: 5px; + padding: 10px; +} + .clearButton { width: 50px; background-color: var(--background-color); diff --git a/src/pages/chat.js b/src/pages/chat.js index c433086..8526da5 100644 --- a/src/pages/chat.js +++ b/src/pages/chat.js @@ -425,7 +425,7 @@ export default class Chat extends React.Component { ref={this.chatInputRef} className={styles.msgInput} autoFocus - placeholder={'Message ...'} + placeholder={'Üzenet ...'} type={'text'} value={currMsg} tabIndex={0} diff --git a/src/pages/userfiles.js b/src/pages/userfiles.js index 0e7edc1..4eec907 100644 --- a/src/pages/userfiles.js +++ b/src/pages/userfiles.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react' +import React, { useState, useEffect, useCallback } from 'react' import Link from 'next/link' import LoadingIndicator from '../components/LoadingIndicator' @@ -203,6 +203,52 @@ export default function UserFiles({ const currDir = router.query.dir ? decodeURIComponent(router.query.dir) : '' + const goBack = useCallback(() => { + router.back() + // FIXME: consistend going back with browser back button + // + // back button works like broser back button, unless it would result in site leave + // history: nothing > opened site/usrFiles?dir=... + // history: site > site/userFiles > site/usrFiles?dir=... + router.push(`${router.pathname}`, undefined, { + shallow: true, + }) + }, [router]) + + const deleteDirectory = useCallback( + (dirName) => { + fetch(constants.apiUrl + 'deleteDir', { + method: 'POST', + credentials: 'include', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + name: dirName, + }), + }) + .then((res) => { + return res.json() + }) + .then((res) => { + console.info(res) + if (res.succes) { + getRootDir(true) + alert(`a(z) '${dirName}' mappa törölve!`) + } else { + alert('Hiba törlés közben!') + console.log(res) + } + }) + .catch((e) => { + alert('Hálózati hiba!') + console.log(e) + }) + }, + [router] + ) + useEffect(() => { router.replace(`${router.asPath.replace('.html', '')}`, undefined, { shallow: true, @@ -281,37 +327,37 @@ export default function UserFiles({ }) } + const renderNewButton = () => ( +
+
{ + setAddingNew(currDir ? 'file' : 'dir') + }} + > + {currDir ? 'Új fájl feltöltése...' : '➕ Új tárgy hozzáadása...'} +
+
+ ) + const renderDirList = (dirs) => { return (
{currDir && (
-
-
{ - router.back() - // FIXME: consistend going back with browser back button - // back button works like broser back button, unless it would result in site leave - // history: nothing > opened site/usrFiles?dir=... - // history: site > site/userFiles > site/usrFiles?dir=... - router.push(`${router.pathname}`, undefined, { - shallow: true, - }) - }} - > - Vissza -
-
{currDir &&
{currDir}
} -
)} - { - setSearchTerm(e) - }} - /> +
+
+ { + setSearchTerm(e) + }} + /> +
+ {renderNewButton()} +
{ @@ -336,14 +382,17 @@ export default function UserFiles({
{dirs ? (
-
{ - setAddingNew(currDir ? 'file' : 'dir') - }} - > -
{currDir ? 'Új fájl feltöltése...' : 'Új tárgy...'}
-
- {dirs.length !== 0 && ( + {currDir && ( +
{ + goBack() + }} + > + {'Vissza'} +
+ )} + {dirs.length !== 0 ? ( <> {dirs.sort(dirSorter).map((dir) => { const { @@ -444,6 +493,22 @@ export default function UserFiles({ ) })} + ) : ( +
{ + if ( + window.confirm( + `Biztosan törlöd a(z) '${currDir}' üres mappát?` + ) + ) { + deleteDirectory(currDir) + goBack() + } + }} + > + {'Mappa törlése'} +
)}
) : ( @@ -524,11 +589,14 @@ export default function UserFiles({ newSubj(newSubjName).then(() => { setUploading(false) setAddingNew(null) - getRootDir() + getRootDir(true) + alert(`'${newSubjName}' létrehozva!`) }) }} > -
OK
+
+ {addingNew === 'file' ? 'OK' : 'Új mappa létrehozása'} +
)} diff --git a/src/pages/userfiles.module.css b/src/pages/userfiles.module.css index 071fb04..3e891f5 100644 --- a/src/pages/userfiles.module.css +++ b/src/pages/userfiles.module.css @@ -88,8 +88,8 @@ background-color: var(--dark-color); } -.backButton { - width: 15%; +.newButton { + width: 35%; } .description {