Skip to content

Commit

Permalink
use inertia
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin committed Jul 13, 2023
1 parent f834776 commit 69ae998
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Str;

class ContactVCardController extends Controller
Expand All @@ -18,9 +19,10 @@ public function download(Request $request, Vault $vault, Contact $contact)
$cardData = $this->exportVCard($vault->id, $contact->id);
$name = Str::of($contact->name)->slug(language: App::getLocale());

return response()->streamDownload(function () use ($cardData) {
echo $cardData;
}, "$name.vcf", ['Content-Type' => 'text/vcard'], 'inline');
return Redirect::back()->with('flash', [
'data' => $cardData,
'filename' => "$name.vcf",
]);
}

/**
Expand Down
26 changes: 17 additions & 9 deletions resources/js/Pages/Vault/Contact/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,23 @@ const destroyAvatar = () => {
};
const download = () => {
return axios.post(props.data.url.download_vcard).then((response) => {
const filename = response.headers['content-disposition'].split('filename=')[1];
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', filename);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
router.post(props.data.url.download_vcard, null, {
preserveScroll: true,
onSuccess: (response) => {
const filename = response.props.jetstream.flash.filename;
if (filename !== undefined) {
const url = window.URL.createObjectURL(new Blob([response.props.jetstream.flash.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', filename);
try {
document.body.appendChild(link);
link.click();
} catch (e) {
document.body.removeChild(link);
}
}
},
});
};
</script>
Expand Down

0 comments on commit 69ae998

Please sign in to comment.