Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Digital course file
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SE-PROJECT-TEAM
Digital course file
Commits
c493655a
Commit
c493655a
authored
4 years ago
by
Ganapathi Subramanyam Jayam
Browse files
Options
Downloads
Patches
Plain Diff
delete file
parent
2f035b18
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
digital-course-file/src/user/File.js
+143
-85
143 additions, 85 deletions
digital-course-file/src/user/File.js
with
143 additions
and
85 deletions
digital-course-file/src/user/File.js
+
143
−
85
View file @
c493655a
import
{
faFile
}
from
"
@fortawesome/free-solid-svg-icons
"
import
{
FontAwesomeIcon
}
from
"
@fortawesome/react-fontawesome
"
import
{
React
,
useState
}
from
"
react
"
import
{
storage
}
from
'
../fire.js
'
import
Axios
from
'
axios
'
;
import
fileDownload
from
'
js-file-download
'
;
import
{
Button
,
Modal
,
Form
}
from
'
react-bootstrap
'
;
import
{
useContextMenu
,
Menu
,
Item
}
from
"
react-contexify
"
;
import
"
react-contexify/dist/ReactContexify.css
"
;
import
{
faFile
}
from
'
@fortawesome/free-solid-svg-icons
'
import
{
FontAwesomeIcon
}
from
'
@fortawesome/react-fontawesome
'
import
{
React
,
useState
}
from
'
react
'
import
{
storage
,
storageRef
,
firestore1
,
database
}
from
'
../fire.js
'
import
Axios
from
'
axios
'
import
fileDownload
from
'
js-file-download
'
import
{
Button
,
Modal
,
Form
}
from
'
react-bootstrap
'
import
{
useContextMenu
,
Menu
,
Item
}
from
'
react-contexify
'
import
'
react-contexify/dist/ReactContexify.css
'
import
firebase
from
'
firebase
'
export
default
function
File
({
file
})
{
const
[
showit
,
setShowit
]
=
useState
(
false
);
const
MENU_ID
=
"
#asvdsdv/asqrca662
"
;
const
[
fname
,
setFname
]
=
useState
(
file
.
name
);
const
[
uploaddetail
,
setuploadDetail
]
=
useState
(
""
);
const
[
showit
,
setShowit
]
=
useState
(
false
)
const
MENU_ID
=
'
#asvdsdv/asqrca662
'
const
[
fname
,
setFname
]
=
useState
(
file
.
name
)
const
[
show1
,
setshow1
]
=
useState
(
false
)
const
[
show2
,
setshow2
]
=
useState
(
false
)
const
[
fileurl
,
setfileURL
]
=
useState
(
''
)
const
[
fileid
,
setfileid
]
=
useState
(
''
)
const
[
uploaddetail
,
setuploadDetail
]
=
useState
(
''
)
const
db
=
firebase
.
firestore
()
const
[
uniqueid1
,
setuniqueid1
]
=
useState
(
''
)
const
{
show
}
=
useContextMenu
({
id
:
MENU_ID
,
})
const
{
show
}
=
useContextMenu
({
id
:
MENU_ID
,
});
function
closeModal
()
{
setShowit
(
false
)
setshow1
(
false
)
setshow2
(
false
)
}
function
displayMenu
(
e
)
{
show
(
e
,
{
props
:
{
id
:
Number
(
e
.
currentTarget
.
id
),
fileURL
:
file
.
url
,
fileName
:
file
.
name
,
showit
:
showit
,
details
:
file
.
createdAt
,
fileuniqueID
:
file
.
uniqueid
,
fileID
:
file
.
id
,
},
})
}
function
closeModal
(){
setShowit
(
false
);
function
handleItemClick
({
event
,
props
,
file
})
{
switch
(
event
.
currentTarget
.
id
)
{
case
'
download
'
:
// Getting download url of the file and converting it as data to blob using axios and then downloading it
var
httpsReference
=
storage
.
refFromURL
(
props
.
fileURL
)
httpsReference
.
getDownloadURL
()
.
then
((
url
)
=>
{
Axios
.
get
(
url
,
{
responseType
:
'
blob
'
,
}).
then
((
res
)
=>
{
fileDownload
(
res
.
data
,
props
.
fileName
)
})
})
.
catch
((
error
)
=>
{
console
.
log
(
'
ERROR
'
)
})
break
case
'
details
'
:
setShowit
(
true
)
setFname
(
props
.
fileName
)
setuploadDetail
(
Date
(
props
.
details
.
toMillis
()))
break
case
'
delete
'
:
setshow1
(
true
)
setuniqueid1
(
props
.
fileuniqueID
)
setfileid
(
props
.
fileid
)
break
}
function
displayMenu
(
e
)
{
show
(
e
,
{
props
:
{
id
:
Number
(
e
.
currentTarget
.
id
),
fileURL
:
file
.
url
,
fileName
:
file
.
name
,
showit
:
showit
,
details
:
file
.
createdAt
}
});
}
function
handleItemClick
({
event
,
props
,
file
})
{
}
switch
(
event
.
currentTarget
.
id
)
{
function
handleDelete
({
props
})
{
const
storageRef
=
firebase
.
storage
().
ref
()
case
"
download
"
:
// Getting download url of the file and converting it as data to blob using axios and then downloading it
var
httpsReference
=
storage
.
refFromURL
(
props
.
fileURL
);
httpsReference
.
getDownloadURL
()
.
then
((
url
)
=>
{
Axios
.
get
(
url
,
{
responseType
:
'
blob
'
,
}).
then
(
res
=>
{
fileDownload
(
res
.
data
,
props
.
fileName
);
});
})
.
catch
((
error
)
=>
{
console
.
log
(
"
ERROR
"
);
});
break
;
var
path
=
'
files/
'
+
firebase
.
auth
().
currentUser
.
uid
+
'
/
'
+
uniqueid1
console
.
log
(
path
)
var
desertRef1
=
storageRef
.
child
(
path
)
desertRef1
.
delete
()
case
"
details
"
:
setShowit
(
true
);
setFname
(
props
.
fileName
);
setuploadDetail
(
Date
((
props
.
details
).
toMillis
()));
break
;
database
.
files
.
doc
(
file
.
id
)
.
delete
()
.
then
(()
=>
{
console
.
log
(
'
Folder deleted
'
)
})
.
catch
((
error
)
=>
{
console
.
error
(
'
Error :
'
,
error
)
})
case
"
delete
"
:
break
;
}
}
closeModal
()
}
return
(
<
div
id
=
'
root
'
>
<
a
onContextMenu
=
{
displayMenu
}
href
=
{
file
.
url
}
target
=
"
_blank
"
className
=
"
btn btn-outline-dark text-truncate w-100
"
>
<
FontAwesomeIcon
icon
=
{
faFile
}
className
=
"
mr-2
"
/>
{
file
.
name
}
<
/a
>
{
/* CONTEXT MENU FOR FILE */
}
<
Menu
id
=
{
MENU_ID
}
>
<
Item
id
=
"
download
"
onClick
=
{
handleItemClick
}
>
Download
<
/Item
>
<
Item
id
=
"
details
"
onClick
=
{
handleItemClick
}
>
Details
<
/Item
>
<
Item
id
=
"
delete
"
onClick
=
{
handleItemClick
}
>
Delete
<
/Item
>
<
/Menu
>
{
/* FOR SHOWING DETAILS OF THE FILE */
}
<
Modal
show
=
{
showit
}
onHide
=
{
closeModal
}
>
<
Modal
.
Body
>
<
p
>
File
:
{
fname
}
<
/p
>
<
p
>
Uploaded
On
:
{(
""
+
uploaddetail
).
substring
(
0
,
34
)
+
"
(IST)
"
}
<
/p
>
<
/Modal.Body
>
<
Modal
.
Footer
>
<
Button
variant
=
"
danger
"
onClick
=
{
closeModal
}
>
Close
<
/Button
>
<
/Modal.Footer
>
<
/Modal
>
<
a
onContextMenu
=
{
displayMenu
}
href
=
{
file
.
url
}
target
=
'
_blank
'
className
=
'
btn btn-outline-dark text-truncate w-100
'
>
<
FontAwesomeIcon
icon
=
{
faFile
}
className
=
'
mr-2
'
/>
{
file
.
name
}
<
/a
>
{
/* CONTEXT MENU FOR FILE */
}
<
Menu
id
=
{
MENU_ID
}
>
<
Item
id
=
'
download
'
onClick
=
{
handleItemClick
}
>
Download
<
/Item
>
<
Item
id
=
'
details
'
onClick
=
{
handleItemClick
}
>
Details
<
/Item
>
<
Item
id
=
'
delete
'
onClick
=
{
handleItemClick
}
>
Delete
<
/Item
>
<
/Menu
>
{
/* FOR SHOWING DETAILS OF THE FILE */
}
<
Modal
show
=
{
showit
}
onHide
=
{
closeModal
}
>
<
Modal
.
Body
>
<
p
>
File
:
{
fname
}
<
/p
>
<
p
>
Uploaded
On
:
{(
''
+
uploaddetail
).
substring
(
0
,
34
)
+
'
(IST)
'
}
<
/p
>
<
/Modal.Body
>
<
Modal
.
Footer
>
<
Button
variant
=
'
danger
'
onClick
=
{
closeModal
}
>
Close
<
/Button
>
<
/Modal.Footer
>
<
/Modal
>
<
Modal
show
=
{
show1
}
onHide
=
{
closeModal
}
>
<
Form
>
<
Modal
.
Body
>
<
div
>
Do
you
want
to
delete
the
current
file
?
<
/div
>
<
/Modal.Body
>
<
Modal
.
Footer
>
<
Button
name
=
'
del_confirm
'
style
=
{{
float
:
'
left
'
}}
className
=
'
mr-2
'
variant
=
'
danger
'
onClick
=
{
handleDelete
}
>
DELETE
<
/Button
>
<
Button
variant
=
'
primary
'
onClick
=
{
closeModal
}
>
Cancel
<
/Button
>
<
/Modal.Footer
>
<
/Form
>
<
/Modal
>
<
/div
>
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment