Skip to content

Commit

Permalink
Merge pull request #487 from Heaven-Tonight/snippet-copies-bugFix
Browse files Browse the repository at this point in the history
[#483] fixed duplicate snippet bug
  • Loading branch information
HelenOne authored May 30, 2024
2 parents d98f4d3 + 50fc86a commit db1f4da
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions frontend/src/components/Modals/DuplicateSnippetModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ const initialFormState = { state: 'initial', message: '' };

// duplicateSnippet
function DuplicateSnippetModal({ handleClose, isOpen }) {
const { currSnippetName, code, ownerUsername } = useSelector(
const { currSnippetName, currSnippetLng, code, ownerUsername } = useSelector(
({ modal }) => modal.item,
);
const navigate = useNavigate();
const duplicateSnippet = useDuplicateSnippet();
const { genViewSnippetLink } = useSnippets();
const { t } = useTranslation();
const username = useSelector((state) => state.user.userInfo.username);
const language = useSelector((state) => state.languages.currentLanguage);

const nameRef = useRef(null);
const [formState, setFormState] = useState({ state: 'initial', message: '' });

Expand All @@ -49,7 +49,7 @@ function DuplicateSnippetModal({ handleClose, isOpen }) {
const { slug } = await duplicateSnippet({
code,
snippetName: preparedValues.snippetName,
language,
language: currSnippetLng,
});

const url = new URL(genViewSnippetLink(username, slug));
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/profile/SnippetCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function CardFooter({ handleDelete, handleShare, handleDuplicate }) {
}

function SnippetCard({ data }) {
const { id, name, slug, code } = data;
const { id, name, slug, code, language } = data;
const ownerUsername = data.user.username;
const dispatch = useDispatch();
const [mode, setMode] = useState('viewing');
Expand All @@ -277,6 +277,7 @@ function SnippetCard({ data }) {
type: 'duplicateSnippet',
item: {
currSnippetName: name,
currSnippetLng: language,
ownerUsername,
code,
},
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/pages/snippet/ActionsToolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function ActionsToolbar({ snippet }) {
const dispatch = useDispatch();
const { snippetData, code, isAllSaved } = snippet;
const { name: snippetName, ownerUsername } = snippetData;
const { language } = snippetData;
const { isLoggedIn } = useAuth();
const { direction } = useSelector((state) => state.editor);
const handleShare = () => {
Expand All @@ -35,6 +36,7 @@ function ActionsToolbar({ snippet }) {
type: 'duplicateSnippet',
item: {
currSnippetName: snippetName,
currSnippetLng: language,
ownerUsername,
code,
},
Expand All @@ -46,6 +48,7 @@ function ActionsToolbar({ snippet }) {
type: 'attemptDuplicateSnippet',
item: {
currSnippetName: snippetName,
currSnippetLng: language,
code,
},
}),
Expand Down

0 comments on commit db1f4da

Please sign in to comment.