add support change title on share page
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import { useParams } from "react-router";
|
import { useParams } from "react-router";
|
||||||
import FilesTable from "./FilesTable";
|
import FilesTable from "./FilesTable";
|
||||||
import { Tr } from "../translate";
|
import { Tr, tr, langCodeContext } from "../translate";
|
||||||
|
|
||||||
function Share(props) {
|
function Share(props) {
|
||||||
let params = useParams();
|
let params = useParams();
|
||||||
const [file, setFile] = useState([]);
|
const { langCode } = useContext(langCodeContext);
|
||||||
|
|
||||||
|
const [file, setFile] = useState({});
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch("/api/v1/get_file_info", {
|
fetch("/api/v1/get_file_info", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -16,12 +18,27 @@ function Share(props) {
|
|||||||
})
|
})
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setFile([data]);
|
setFile(data);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
alert("get_file_info error: " + error);
|
alert("get_file_info error: " + error);
|
||||||
});
|
});
|
||||||
}, [params]);
|
}, [params]);
|
||||||
|
|
||||||
|
// change title
|
||||||
|
useEffect(() => {
|
||||||
|
const oldTitle = document.title;
|
||||||
|
|
||||||
|
document.title = `${tr("Share", langCode)}🎵: ${
|
||||||
|
file.filename
|
||||||
|
} - MSW Open Music`;
|
||||||
|
|
||||||
|
// set title back
|
||||||
|
return () => {
|
||||||
|
document.title = oldTitle;
|
||||||
|
};
|
||||||
|
}, [file]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="page">
|
<div className="page">
|
||||||
<h3>{Tr("Share with others!")}</h3>
|
<h3>{Tr("Share with others!")}</h3>
|
||||||
@@ -33,7 +50,7 @@ function Share(props) {
|
|||||||
👇 {Tr("Click the filename below to enjoy music!")}
|
👇 {Tr("Click the filename below to enjoy music!")}
|
||||||
<br />
|
<br />
|
||||||
</p>
|
</p>
|
||||||
<FilesTable setPlayingFile={props.setPlayingFile} files={file} />
|
<FilesTable setPlayingFile={props.setPlayingFile} files={[file]} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user