Some good suggestions above, but here is a reality check.
Yosemite is one of the most difficult places to visit, especially with last-minute planning like this. You absolutely must have reservations, and if your lodging is not inside the park you also need a day-use permit to enter the park. Most of those permits for June were released for booking in late March and were all taken. They will release a limited number of additional permits each day, one week in advance of the entry date, so you would need to be ready to grab one for your visit the moment they are released. Here is more information:
https://www.recreation.gov/timed-entry/10086745?tab=info
So it is much better to have lodging reserved inside the park ( so you don’t need a separate entry permit), but those lodges and cabins went on sale a year ago and were almost fully booked up at that time. Usually there are some tent cabins at Curry Village left, but for June those may have been booked more recently. Then, some people cancel their reservation made long ago, and the room or cabin appears back on the official website. So you may find something for one night here or there if you keep looking ( several times a day), but it is very difficult to find a 2-night or longer stay at this point.
If you want to look, use ONLY the official website for Yosemite lodging, which is https://www.travelyosemite.com/
There are websites like one called “national park reservations” that will say they can book you a room at a park lodge, then switch you to a room in a motel outside the park—-and then you cannot enter the park unless you have that day use permit.
So I would suggest you skip Yosemite altogether.
Grand Canyon National Park is well worth a visit, and lodging can be hard to find there as well, but it is not as crucial to stay inside the park there. It is preferable, but not essential like it is at Yosemite.
The official websites for booking at the park lodges at Grand Canyon NP are:
South Rim: https://www.grandcanyonlodges.com/ and https://www.visitgrandcanyon.com/yavapai-lodge
North Rim: https://www.grandcanyonforever.com/
If there is nothing available inside the park, there are motels and hotels in the village of Tusayan, right at the park entrance.
I am not a fan of Grand Canyon West and the Skywalk suggested above. It is highly promoted to Las Vegas tourists, but it is expensive, and you are not at the best part of the Grand Canyon.
There are other national parks near to your route which are well worth seeing, and I will suggest a basic route. Start in San Francisco, spend 3-4 days in the city without a car. Then rent a car for 5 days and drive up the coast and back, for the redwoods and coast views.
If rental car prices at San Francisco look too high, I have found decent prices on car rentals in the past month by looking at Santa Rosa. You can get there by ferry plus commuter train from San Francisco. We had fun doing this.
If you want to spend more time in California with the car, you can visit Big Sur and Monterey south of San Francisco, or maybe Lake Tahoe to the east.
Then return the car at Santa Rosa (or maybe SFO—-it did not cost extra for us) and fly to Los Angeles. Alaska Airlines has direct flights. Spend the time you want in Las Angeles without a car, then fly to Las Vegas and rent another car there to drive to the Grand Canyon. Consider adding Bryce and Zion National parks, which makes for a nice loop back to Las Vegas.
Return the car at Las Vegas and fly back to San Francisco for your flight home.