    refresh();
  }
  
  void MapSettings::refresh() {
    bool has_home = false, has_work = false;
    auto destinations = std::vector<std::unique_ptr<NavDestination>>();
  
    auto destinations_str = cur_destinations.trimmed();
    if (!destinations_str.isEmpty()) {
      QJsonDocument doc = QJsonDocument::fromJson(destinations_str.toUtf8());
      if (doc.isNull()) {
        qWarning() << "JSON Parse failed on navigation locations" << cur_destinations;
        return;
      }
  
      for (auto el : doc.array()) {
        auto destination = std::make_unique<NavDestination>(el.toObject());
  
        // add home and work later if they are missing
        if (destination->isFavorite()) {
          if (destination->label() == NAV_FAVORITE_LABEL_HOME) has_home = true;
          else if (destination->label() == NAV_FAVORITE_LABEL_WORK) has_work = true;
        }
  
        // skip current destination
        if (current_destination && *destination == *current_destination) continue;
        destinations.push_back(std::move(destination));
      }
    }
  
    // TODO: should we build a new layout and swap it in?
    clearLayout(destinations_layout);
  
    // Sort: HOME, WORK, alphabetical FAVORITES, and then most recent (as returned by API)
    std::stable_sort(destinations.begin(), destinations.end(), [](const auto &a, const auto &b) {
 
</s> remove   // Sort: HOME, WORK, alphabetical FAVORITES, and then most recent (as returned by API)
  std::stable_sort(destinations.begin(), destinations.end(), [](const auto &a, const auto &b) {
    if (a->isFavorite() && b->isFavorite()) {
      if (a->label() == NAV_FAVORITE_LABEL_HOME) return true;
      else if (b->label() == NAV_FAVORITE_LABEL_HOME) return false;
      else if (a->label() == NAV_FAVORITE_LABEL_WORK) return true;
      else if (b->label() == NAV_FAVORITE_LABEL_WORK) return false;
      else return a->name() < b->name();
 </s> add   bool has_home = false, has_work = false;
  for (auto location : current_locations) {
    auto dest = location.toObject();
    if (dest["save_type"].toString() == NAV_TYPE_FAVORITE) {
      has_home = has_home || dest["label"].toString() == NAV_FAVORITE_LABEL_HOME;
      has_work = has_work || dest["label"].toString() == NAV_FAVORITE_LABEL_WORK; </s> remove     auto destination = std::make_unique<NavDestination>(doc.object());
    if (current_destination && *destination == *current_destination) return;
    current_destination = std::move(destination);
    current_widget->set(current_destination.get(), true);
 </s> add     current_destination = doc.object();
    current_widget->set(current_destination, true); </s> remove void MapSettings::parseResponse(const QString &response, bool success) {
  if (!success || response == cur_destinations) return;
  cur_destinations = response;
 </s> add void MapSettings::updateLocations(const QJsonArray &locations) {
  current_locations = locations; </s> remove   if (destination->isFavorite()) {
    if (destination->label() == NAV_FAVORITE_LABEL_HOME) {
 </s> add   if (destination["save_type"] == NAV_TYPE_FAVORITE) {
    if (destination["label"] == NAV_FAVORITE_LABEL_HOME) { </s> remove     else if (a->isFavorite()) return true;
    else if (b->isFavorite()) return false;
    return false;
  });
 </s> add     if (dest == current_destination) continue;
  setUpdatesEnabled(false);
    refresh();
  }
  
  void MapSettings::refresh() {
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
  setUpdatesEnabled(false);
    // TODO: should we build a new layout and swap it in?
    clearLayout(destinations_layout);
  
    // Sort: HOME, WORK, alphabetical FAVORITES, and then most recent (as returned by API)
    std::stable_sort(destinations.begin(), destinations.end(), [](const auto &a, const auto &b) {
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 ui/MapSettings: sort location JsonArray inplace (#28886) 
selfdrive/ui/qt/maps/map_settings.cc